|
@ -20,6 +20,7 @@ import java.nio.file.attribute.PosixFilePermissions; |
|
|
import java.security.cert.Certificate; |
|
|
import java.security.cert.Certificate; |
|
|
import java.security.cert.CertificateEncodingException; |
|
|
import java.security.cert.CertificateEncodingException; |
|
|
import java.text.DateFormat; |
|
|
import java.text.DateFormat; |
|
|
|
|
|
import java.text.ParseException; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.text.SimpleDateFormat; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.regex.Matcher; |
|
|
import java.util.regex.Matcher; |
|
@ -173,24 +174,27 @@ public class Storage { |
|
|
deleteBackups(null); |
|
|
deleteBackups(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void deleteTempBackups() { |
|
|
public void deleteTempBackups(boolean forceSave) { |
|
|
File[] backups = getBackups(Storage.TEMP_BACKUP_PREFIX); |
|
|
File[] backups = getBackups(Storage.TEMP_BACKUP_PREFIX); |
|
|
if(backups.length > 0) { |
|
|
if(backups.length > 0 && (forceSave || hasStartedSince(backups[0]))) { |
|
|
try { |
|
|
File permanent = new File(backups[0].getParent(), backups[0].getName().substring(Storage.TEMP_BACKUP_PREFIX.length() + 1)); |
|
|
Date date = BACKUP_DATE_FORMAT.parse(getBackupDate(backups[0].getName())); |
|
|
backups[0].renameTo(permanent); |
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean hasStartedSince(File lastBackup) { |
|
|
|
|
|
try { |
|
|
|
|
|
Date date = BACKUP_DATE_FORMAT.parse(getBackupDate(lastBackup.getName())); |
|
|
|
|
|
ProcessHandle.Info processInfo = ProcessHandle.current().info(); |
|
|
|
|
|
return (processInfo.startInstant().isPresent() && processInfo.startInstant().get().isAfter(date.toInstant())); |
|
|
|
|
|
} catch(Exception e) { |
|
|
|
|
|
log.error("Error parsing date for backup file " + lastBackup.getName(), e); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void deleteBackups(String prefix) { |
|
|
private void deleteBackups(String prefix) { |
|
|
File[] backups = getBackups(prefix); |
|
|
File[] backups = getBackups(prefix); |
|
|
for(File backup : backups) { |
|
|
for(File backup : backups) { |
|
|