make temp backup permanent when created in a previous process

This commit is contained in:
Craig Raw 2021-10-04 13:49:41 +02:00
parent 54baee57e1
commit 9dd6068e69
2 changed files with 15 additions and 0 deletions

View file

@ -173,6 +173,20 @@ public class Storage {
} }
public void deleteTempBackups() { 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); deleteBackups(Storage.TEMP_BACKUP_PREFIX);
} }

View file

@ -88,6 +88,7 @@ public class DbPersistence implements Persistence {
Persistence backupPersistence = PersistenceType.DB.getInstance(); Persistence backupPersistence = PersistenceType.DB.getInstance();
backupPersistence.setKeyDeriver(keyDeriver); backupPersistence.setKeyDeriver(keyDeriver);
backupWallet = backupPersistence.loadWallet(new Storage(backupPersistence, backupFile), password, encryptionKey).getWallet(); backupWallet = backupPersistence.loadWallet(new Storage(backupPersistence, backupFile), password, encryptionKey).getWallet();
backupPersistence.close();
} }
Map<WalletBackupAndKey, Storage> childWallets = loadChildWallets(storage, masterWallet, backupWallet, encryptionKey); Map<WalletBackupAndKey, Storage> childWallets = loadChildWallets(storage, masterWallet, backupWallet, encryptionKey);