diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index 4d9d043f..a98ca266 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -173,6 +173,20 @@ public class Storage { } public void deleteTempBackups() { + File[] backups = getBackups(Storage.TEMP_BACKUP_PREFIX); + if(backups.length > 0) { + try { + Date date = BACKUP_DATE_FORMAT.parse(getBackupDate(backups[0].getName())); + ProcessHandle.Info processInfo = ProcessHandle.current().info(); + if(processInfo.startInstant().isPresent() && processInfo.startInstant().get().isAfter(date.toInstant())) { + File permanent = new File(backups[0].getParent(), backups[0].getName().substring(Storage.TEMP_BACKUP_PREFIX.length() + 1)); + backups[0].renameTo(permanent); + } + } catch(Exception e) { + log.error("Error copying temporary to permanent backup", e); + } + } + deleteBackups(Storage.TEMP_BACKUP_PREFIX); } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java index 7811088f..1dfea6af 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java @@ -88,6 +88,7 @@ public class DbPersistence implements Persistence { Persistence backupPersistence = PersistenceType.DB.getInstance(); backupPersistence.setKeyDeriver(keyDeriver); backupWallet = backupPersistence.loadWallet(new Storage(backupPersistence, backupFile), password, encryptionKey).getWallet(); + backupPersistence.close(); } Map childWallets = loadChildWallets(storage, masterWallet, backupWallet, encryptionKey);