mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-10 08:19:23 +00:00
Handle migration flags for sync prompt
This commit is contained in:
@@ -1157,6 +1157,7 @@ class PasswordManager:
|
||||
)
|
||||
|
||||
migrated = False
|
||||
last_migration_performed = False
|
||||
index_exists = (
|
||||
self.vault.index_file.exists()
|
||||
or (
|
||||
@@ -1164,7 +1165,9 @@ class PasswordManager:
|
||||
).exists()
|
||||
)
|
||||
try:
|
||||
_, migrated = self.vault.load_index(return_migration_flag=True)
|
||||
_, migrated, last_migration_performed = self.vault.load_index(
|
||||
return_migration_flags=True
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
print(colored(str(exc), "red"))
|
||||
sys.exit(1)
|
||||
@@ -1232,26 +1235,32 @@ class PasswordManager:
|
||||
print(colored("Local database migration successful.", "green"))
|
||||
if self.encryption_manager is not None:
|
||||
self.encryption_manager.last_migration_performed = False
|
||||
if not self.offline_mode and confirm_action(
|
||||
"Do you want to sync the migrated profile to Nostr now?"
|
||||
):
|
||||
result = self.sync_vault()
|
||||
if result:
|
||||
if last_migration_performed and not self.offline_mode:
|
||||
if confirm_action(
|
||||
"Do you want to sync the migrated profile to Nostr now?"
|
||||
):
|
||||
result = self.sync_vault()
|
||||
if result:
|
||||
print(
|
||||
colored(
|
||||
"Profile synchronized to Nostr successfully.",
|
||||
"green",
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(
|
||||
colored(
|
||||
"Error: Failed to sync profile to Nostr.",
|
||||
"red",
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(
|
||||
colored(
|
||||
"Profile synchronized to Nostr successfully.",
|
||||
"green",
|
||||
"You can sync the migrated profile later from the main menu.",
|
||||
"yellow",
|
||||
)
|
||||
)
|
||||
else:
|
||||
print(colored("Error: Failed to sync profile to Nostr.", "red"))
|
||||
elif not self.offline_mode:
|
||||
print(
|
||||
colored(
|
||||
"You can sync the migrated profile later from the main menu.",
|
||||
"yellow",
|
||||
)
|
||||
)
|
||||
|
||||
logger.debug("Managers re-initialized for the new fingerprint.")
|
||||
|
||||
|
@@ -32,13 +32,19 @@ class Vault:
|
||||
self.encryption_manager = manager
|
||||
|
||||
# ----- Password index helpers -----
|
||||
def load_index(self, *, return_migration_flag: bool = False):
|
||||
def load_index(self, *, return_migration_flags: bool = False):
|
||||
"""Return decrypted password index data, applying migrations.
|
||||
|
||||
If a legacy ``seedpass_passwords_db.json.enc`` file is detected, the
|
||||
user is prompted to migrate it. A backup copy of the legacy file (and
|
||||
its checksum) is saved under ``legacy_backups`` within the fingerprint
|
||||
directory before renaming to the new filename.
|
||||
|
||||
When ``return_migration_flags`` is ``True`` the tuple
|
||||
``(data, migrated, last_migration_performed)`` is returned where
|
||||
``migrated`` indicates whether any migration occurred and
|
||||
``last_migration_performed`` reflects whether the underlying
|
||||
:class:`EncryptionManager` reported a conversion.
|
||||
"""
|
||||
|
||||
legacy_file = self.fingerprint_dir / "seedpass_passwords_db.json.enc"
|
||||
@@ -154,8 +160,8 @@ class Vault:
|
||||
self.migrated_from_legacy = (
|
||||
legacy_detected or migration_performed or schema_migrated
|
||||
)
|
||||
if return_migration_flag:
|
||||
return data, self.migrated_from_legacy
|
||||
if return_migration_flags:
|
||||
return data, self.migrated_from_legacy, migration_performed
|
||||
return data
|
||||
|
||||
def save_index(self, data: dict) -> None:
|
||||
|
Reference in New Issue
Block a user