JAL-3141 Taken the backing up code out of FileChooser into its own class for more...
[jalview.git] / src / jalview / io / JalviewFileChooser.java
index 052cf68..90a3cc0 100755 (executable)
@@ -33,7 +33,6 @@ import java.awt.HeadlessException;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.File;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -352,114 +351,7 @@ public class JalviewFileChooser extends JFileChooser
         ret = JalviewFileChooser.CANCEL_OPTION;
       }
 
-      rollBackupFiles(ourselectedFile);
-    }
-
-    return ret;
-  }
-
-  // attempts to roll backup files for this file (before overwriting). Returns
-  // 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);
-  }
-
-  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", defaultSuffix);
-    int backupMax = jalview.bin.Cache.getDefault("BACKUP_ROLL_MAX",
-            defaultMax);
-    String dir = "";
-    try
-    {
-      File dirFile = file.getParentFile();
-      dir = dirFile.getCanonicalPath();
-    } catch (Exception e)
-    {
-      System.out.println(
-              "Could not get canonical path for file '" + file + "'");
-      return false;
-    }
-    String filename = file.getName();
-    String basename = filename;
-    String extension = "";
-    int dotchar = filename.lastIndexOf('.');
-    // don't split of filenames with the last '.' at the very beginning or
-    // very end of the filename
-    if ((dotchar > 0) && (dotchar < filename.length() - 1))
-    {
-      basename = filename.substring(0, dotchar);
-      extension = filename.substring(dotchar); // NOTE this includes the '.'
-    }
-
-    boolean ret = true;
-    if (backupMax >= 1)
-    {
-      // Create/move backups up one
-      String numString = null;
-      File lastfile = null;
-      for (int n = backupMax; n > 0; n--)
-      {
-        numString = String.format("%02d", n);
-        String backupSuffix = backupSuffixTemplate.replaceAll("%n",
-                numString);
-        String backupfilename = dir + File.separatorChar + basename
-                + backupSuffix + extension;
-        File backupfile_n = new File(backupfilename);
-
-        if (! backupfile_n.exists()) {
-          lastfile = backupfile_n;
-          continue;
-        }
-        
-        if (n == backupMax)
-        { // 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
-        {
-          // Just In Case
-          if (lastfile != null)
-          {
-            ret = ret && backupfile_n.renameTo(lastfile);
-          }
-        }
-
-        lastfile = backupfile_n;
-      }
-      
-      // now actually backup the important file!
-      ret = ret && file.renameTo(lastfile);
+      // not happening here now rollBackupFiles(ourselectedFile);
     }
 
     return ret;