From 5f4dc95ca521261b830ecb9c263c13535df51609 Mon Sep 17 00:00:00 2001 From: cyan Date: Mon, 14 Apr 2025 18:46:45 +0200 Subject: [PATCH] fix: do not overwrite monero backup files if they exist. (#2202) --- cw_core/lib/monero_wallet_utils.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cw_core/lib/monero_wallet_utils.dart b/cw_core/lib/monero_wallet_utils.dart index 8a4990f78..9682784f9 100644 --- a/cw_core/lib/monero_wallet_utils.dart +++ b/cw_core/lib/monero_wallet_utils.dart @@ -19,15 +19,15 @@ Future backupWalletFiles(String name) async { final newKeysFilePath = backupFileName(keysFile.path); final newAddressListFilePath = backupFileName(addressListFile.path); - if (cacheFile.existsSync()) { + if (cacheFile.existsSync() && !File(newCacheFilePath).existsSync()) { await cacheFile.copy(newCacheFilePath); } - if (keysFile.existsSync()) { + if (keysFile.existsSync() && !File(newKeysFilePath).existsSync()) { await keysFile.copy(newKeysFilePath); } - if (addressListFile.existsSync()) { + if (addressListFile.existsSync() && !File(newAddressListFilePath).existsSync()) { await addressListFile.copy(newAddressListFilePath); } } @@ -83,10 +83,13 @@ Future backupWalletFilesExists(String name) async { Future removeCache(String name) async { final path = await pathForWallet(name: name, type: WalletType.monero); final cacheFile = File(path); - + final backgroundCacheFile = File(path + ".background"); if (cacheFile.existsSync()) { cacheFile.deleteSync(); } + if (backgroundCacheFile.existsSync()) { + backgroundCacheFile.deleteSync(); + } } Future restoreOrResetWalletFiles(String name) async { @@ -94,7 +97,8 @@ Future restoreOrResetWalletFiles(String name) async { if (backupsExists) { await removeCache(name); - + // TODO(mrcyjanek): is this needed? + // If we remove cache then wallet should be restored from .keys file. await restoreWalletFiles(name); } }