}
rollBackupFiles(ourselectedFile);
-
}
return ret;
}
// attempts to roll backup files for this file (before overwriting). Returns
- // true if it rolled all the files, false otherwise.
- private static boolean rollBackupFiles(File file)
+ // true if it rolled all the files it was supposed to, false otherwise.
+ public static boolean rollBackupFiles(String filename)
{
+ File file = new File(filename);
+ return rollBackupFiles(file);
+ }
+
+ public static boolean rollBackupFiles(File file)
+ {
+ return rollBackupFiles(file, true, "-bak-%n", 4);
+ }
- if (!file.exists())
+ public static boolean rollBackupFiles(File file, boolean defaultDo,
+ String defaultSuffix, int defaultMax)
+ {
+
+ if (!(file.exists()
+ && jalview.bin.Cache.getDefault("BACKUP_FILES",
+ defaultDo)))
{
// nothing to do
return true;
// split filename up to insert suffix template in the right place. template
// and backupMax can be set in .jalview_properties
String backupSuffixTemplate = jalview.bin.Cache
- .getDefault("BACKUP_SUFFIX", "-bak-%n");
- int backupMax = jalview.bin.Cache.getDefault("BACKUP_MAX", 10);
+ .getDefault("BACKUP_SUFFIX", defaultSuffix);
+ int backupMax = jalview.bin.Cache.getDefault("BACKUP_ROLL_MAX",
+ defaultMax);
String dir = "";
try
{
continue;
}
- if (n == backupMax-1)
+ if (n == backupMax)
{ // Move the max backup to /tmp instead of deleting (Just In
// Case)
- String tmpfile = "tmp-" + backupfilename;
+ String tmpfile = "tmp-" + backupfile_n.getName();
try
{
File tmpFile = File.createTempFile(tmpfile, ".tmp");
}
else
{
- ret = ret && backupfile_n.renameTo(lastfile);
+ // Just In Case
+ if (lastfile != null)
+ {
+ ret = ret && backupfile_n.renameTo(lastfile);
+ }
}
lastfile = backupfile_n;