JAL-3210 JAL-3141 JAL-3056 disable backups in JalviewJS
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Mar 2019 10:51:01 +0000 (10:51 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Mar 2019 10:51:01 +0000 (10:51 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/io/BackupFiles.java
src/jalview/project/Jalview2XML.java

index a9d5b86..4bf424b 100644 (file)
@@ -1289,10 +1289,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         else
         {
           // create backupfiles object and get new temp filename destination
-          BackupFiles backupfiles = new BackupFiles(file);
+          boolean doBackup = BackupFiles.getEnabled();
+          BackupFiles backupfiles = doBackup ? new BackupFiles(file) : null;
           try
           {
-            String tempFilePath = backupfiles.getTempFilePath();
+            String tempFilePath = doBackup ? backupfiles.getTempFilePath() : file;
                        PrintWriter out = new PrintWriter(
                     new FileWriter(tempFilePath));
 
@@ -1302,15 +1303,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             statusBar.setText(MessageManager.formatMessage(
                   "label.successfully_saved_to_file_in_format", new Object[]
                   { fileName, format.getName() }));
+            lastSaveSuccessful = true;
           } catch (Exception ex)
           {
             lastSaveSuccessful = false;
             ex.printStackTrace();
           }
 
-          backupfiles.setWriteSuccess(lastSaveSuccessful);
-          // do the backup file roll and rename the temp file to actual file
-          lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
+          if (doBackup)
+          {
+            backupfiles.setWriteSuccess(lastSaveSuccessful);
+            // do the backup file roll and rename the temp file to actual file
+            lastSaveSuccessful = backupfiles.rollBackupsAndRenameTempFile();
+          }
         }
       }
     };
index 89499c1..1e5904c 100644 (file)
@@ -1705,12 +1705,16 @@ public class Desktop extends jalview.jbgui.GDesktop
           // TODO prevent user from messing with the Desktop whilst we're saving
           try
           {
-            BackupFiles backupfiles = new BackupFiles(chosenFile);
+               boolean doBackup = BackupFiles.getEnabled();
+            BackupFiles backupfiles = doBackup ? new BackupFiles(chosenFile) : null;
 
-            new Jalview2XML().saveState(backupfiles.getTempFile());
+            new Jalview2XML().saveState(doBackup ? backupfiles.getTempFile() : chosenFile);
 
-            backupfiles.setWriteSuccess(true);
-            backupfiles.rollBackupsAndRenameTempFile();
+            if (doBackup)
+            {
+              backupfiles.setWriteSuccess(true);
+              backupfiles.rollBackupsAndRenameTempFile();
+            }
           } catch (OutOfMemoryError oom)
           {
             new OOMWarning("Whilst saving current state to "
index dbda022..dae1c02 100644 (file)
@@ -4,6 +4,7 @@ import jalview.bin.Cache;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 
 import java.io.File;
 import java.io.IOException;
@@ -144,7 +145,7 @@ public class BackupFiles
 
   public static void classInit()
   {
-    setEnabled(Cache.getDefault(ENABLED, true));
+    setEnabled(Cache.getDefault(ENABLED, !Platform.isJS()));
     setConfirmDelete(Cache.getDefault(CONFIRM_DELETE_OLD, true));
   }
 
index 09f1675..5049443 100644 (file)
@@ -768,9 +768,10 @@ public class Jalview2XML
     try
     {
       // create backupfiles object and get new temp filename destination
-      BackupFiles backupfiles = new BackupFiles(jarFile);
-      FileOutputStream fos = new FileOutputStream(
-              backupfiles.getTempFilePath());
+      boolean doBackup = BackupFiles.getEnabled();
+      BackupFiles backupfiles = doBackup ? new BackupFiles(jarFile) : null;
+      FileOutputStream fos = new FileOutputStream(doBackup ? 
+              backupfiles.getTempFilePath() : jarFile);
 
       JarOutputStream jout = new JarOutputStream(fos);
       List<AlignFrame> frames = new ArrayList<>();
@@ -795,8 +796,11 @@ public class Jalview2XML
       jout.close();
       boolean success = true;
 
-      backupfiles.setWriteSuccess(success);
-      success = backupfiles.rollBackupsAndRenameTempFile();
+      if (doBackup)
+      {
+        backupfiles.setWriteSuccess(success);
+        success = backupfiles.rollBackupsAndRenameTempFile();
+      }
 
       return success;
     } catch (Exception ex)