// Create/move backups up one
String numString = null;
File lastfile = null;
- for (int m = 0; m < max; m++)
+
+ if (reverseOrder)
{
- int n = reverseOrder ? max - m : m + 1;
- numString = String.format("%0" + digits + "d", n);
- String backupSuffix = suffix.replaceAll("%n", numString);
- String backupfilename = dir + File.separatorChar + basename
- + backupSuffix + extension;
- File backupfile_n = new File(backupfilename);
-
- if (!backupfile_n.exists())
+ // backup style numbering
+ for (int m = 0; m < max; m++)
{
- lastfile = backupfile_n;
- continue;
- }
-
- if (m == 0)
- { // Move the max backup to /tmp instead of deleting (Just In
- // Case)
- String tmpfile = "tmp-" + backupfile_n.getName();
- try
+ int n = max - m;
+ numString = String.format("%0" + digits + "d", n);
+ String backupSuffix = suffix.replaceAll("%n", numString);
+ String backupfilename = dir + File.separatorChar + basename
+ + backupSuffix + extension;
+ File backupfile_n = new File(backupfilename);
+
+ if (!backupfile_n.exists())
{
- File tmpFile = File.createTempFile(tmpfile, ".tmp");
- ret = ret && backupfile_n.renameTo(tmpFile);
- } catch (IOException e)
+ lastfile = backupfile_n;
+ continue;
+ }
+
+ if (m == 0)
+ { // Move the max backup to /tmp instead of deleting (Just In
+ // Case)
+ String tmpfile = "tmp-" + backupfile_n.getName();
+ try
+ {
+ File tmpFile = File.createTempFile(tmpfile, ".tmp");
+ ret = ret && backupfile_n.renameTo(tmpFile);
+ } catch (IOException e)
+ {
+ System.out.println(
+ "Could not create temp file '" + tmpfile + ".tmp'");
+ }
+ }
+ else
{
- System.out.println(
- "Could not create temp file '" + tmpfile + ".tmp'");
+ // Just In Case
+ if (lastfile != null)
+ {
+ ret = ret && backupfile_n.renameTo(lastfile);
+ }
}
+
+ lastfile = backupfile_n;
}
- else
+
+ }
+ else
+ {
+ // version style numbering (with file rolling though)
+
+ // check if all backup files exist
+ int largest = 0;
+ for (int m = 0; m < max; m++)
{
- // Just In Case
- if (lastfile != null)
+ int n = m + 1;
+ numString = String.format("%0" + digits + "d", n);
+ String backupSuffix = suffix.replaceAll("%n", numString);
+ String backupfilename = dir + File.separatorChar + basename
+ + backupSuffix + extension;
+ File backupfile_n = new File(backupfilename);
+ if (backupfile_n.exists())
{
- ret = ret && backupfile_n.renameTo(lastfile);
+ largest = n;
}
}
-
- lastfile = backupfile_n;
+ // MORE CODE HERE BEN!
}
// now actually backup the important file!