fix: do not overwrite monero backup files if they exist. (#2202)

This commit is contained in:
cyan 2025-04-14 18:46:45 +02:00 committed by GitHub
parent 990feb48ec
commit 5f4dc95ca5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,15 +19,15 @@ Future<void> backupWalletFiles(String name) async {
final newKeysFilePath = backupFileName(keysFile.path); final newKeysFilePath = backupFileName(keysFile.path);
final newAddressListFilePath = backupFileName(addressListFile.path); final newAddressListFilePath = backupFileName(addressListFile.path);
if (cacheFile.existsSync()) { if (cacheFile.existsSync() && !File(newCacheFilePath).existsSync()) {
await cacheFile.copy(newCacheFilePath); await cacheFile.copy(newCacheFilePath);
} }
if (keysFile.existsSync()) { if (keysFile.existsSync() && !File(newKeysFilePath).existsSync()) {
await keysFile.copy(newKeysFilePath); await keysFile.copy(newKeysFilePath);
} }
if (addressListFile.existsSync()) { if (addressListFile.existsSync() && !File(newAddressListFilePath).existsSync()) {
await addressListFile.copy(newAddressListFilePath); await addressListFile.copy(newAddressListFilePath);
} }
} }
@ -83,10 +83,13 @@ Future<bool> backupWalletFilesExists(String name) async {
Future<void> removeCache(String name) async { Future<void> removeCache(String name) async {
final path = await pathForWallet(name: name, type: WalletType.monero); final path = await pathForWallet(name: name, type: WalletType.monero);
final cacheFile = File(path); final cacheFile = File(path);
final backgroundCacheFile = File(path + ".background");
if (cacheFile.existsSync()) { if (cacheFile.existsSync()) {
cacheFile.deleteSync(); cacheFile.deleteSync();
} }
if (backgroundCacheFile.existsSync()) {
backgroundCacheFile.deleteSync();
}
} }
Future<void> restoreOrResetWalletFiles(String name) async { Future<void> restoreOrResetWalletFiles(String name) async {
@ -94,7 +97,8 @@ Future<void> restoreOrResetWalletFiles(String name) async {
if (backupsExists) { if (backupsExists) {
await removeCache(name); await removeCache(name);
// TODO(mrcyjanek): is this needed?
// If we remove cache then wallet should be restored from .keys file.
await restoreWalletFiles(name); await restoreWalletFiles(name);
} }
} }