From: gmungoc Date: Thu, 14 Mar 2019 10:51:01 +0000 (+0000) Subject: JAL-3210 JAL-3141 JAL-3056 disable backups in JalviewJS X-Git-Tag: Release_2_11_4_0~45^2~18^2~229 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2ce814f1ea0fd000c4a1be2680248d82e3ef40ff;p=jalview.git JAL-3210 JAL-3141 JAL-3056 disable backups in JalviewJS --- diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index a9d5b86..4bf424b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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(); + } } } }; diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 89499c1..1e5904c 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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 " diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index dbda022..dae1c02 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -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)); } diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 09f1675..5049443 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -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 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)