Skip to content

Respect merge mode when restoring private keys from backups#1044

Merged
mfat merged 1 commit into
feature/pluggable-secret-storage-backendsfrom
cursor/fix-restore-private-keys-merge-mode-6190
Jun 30, 2026
Merged

Respect merge mode when restoring private keys from backups#1044
mfat merged 1 commit into
feature/pluggable-secret-storage-backendsfrom
cursor/fix-restore-private-keys-merge-mode-6190

Conversation

@mfat

@mfat mfat commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

When restoring a .spbk backup, config categories (SSH config, known_hosts, app settings) honor the user's Merge vs Replace choice. Private keys did not: _restore_private_keys() always overwrote files at the stored paths, so choosing Merge could still clobber an existing ~/.ssh/id_ed25519.

Solution

  • Pass the import mode from apply_imported_manifest() into _restore_private_keys().
  • In merge mode, skip restoring a key when the private key file already exists; likewise skip the .pub file if it already exists.
  • Replace mode behavior is unchanged.
  • Use the exported mode field when setting private key permissions (was hardcoded to 0o600).

Tests

Added two unit tests in tests/test_backup_manager.py:

  • test_spbk_private_key_merge_skips_existing — merge does not overwrite existing key files
  • test_spbk_private_key_merge_restores_missing — merge still writes keys whose paths are absent
Open in Web Open in Cursor 

_restore_private_keys() now accepts the import mode and skips existing
key files in merge mode instead of always overwriting them. Replace mode
behavior is unchanged. Also restores the exported file mode on private keys.

Co-authored-by: Mehdi <mfat@users.noreply.github.com>
@mfat mfat marked this pull request as ready for review June 30, 2026 14:37
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@mfat mfat merged commit f212eeb into feature/pluggable-secret-storage-backends Jun 30, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants