From: Ben Soares Date: Wed, 9 Jan 2019 00:26:07 +0000 (+0000) Subject: JAL-3141 Made one more suggested change from code review X-Git-Tag: Release_2_11_0~17^2~97^2~38 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cb07cebea472ebc60d7118b3582a78950ce7e0d8;p=jalview.git JAL-3141 Made one more suggested change from code review --- diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index c58a714..9209d72 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -233,7 +233,7 @@ public class BackupFiles String basename = filename; String extension = ""; int dotcharpos = filename.lastIndexOf('.'); - // don't split of filenames with the last '.' at the very beginning or + // don't split filenames with the last '.' at the very beginning or // very end of the filename if ((dotcharpos > 0) && (dotcharpos < filename.length() - 1)) { @@ -261,18 +261,7 @@ public class BackupFiles } else { - - // sort the backup files (based on integer found in the suffix) using a - // precomputed Hashmap for speed - Map bfHashMap = new HashMap<>(); - for (int i = 0; i < backupFiles.length; i++) - { - File f = backupFiles[i]; - BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix, digits, extension); - bfHashMap.put(bfp.indexNum(), f); - } - TreeMap bfTreeMap = new TreeMap<>(); - bfTreeMap.putAll(bfHashMap); + TreeMap bfTreeMap = sortBackupFilesAsTreeMap(backupFiles, basename, extension); if (reverseOrder) { @@ -368,6 +357,19 @@ public class BackupFiles } } + deleteOldFiles(oldFilesToDelete, confirmDeleteExtraInfo); + + // Let's make the new backup file!! yay, got there at last! + String latestBackupFilename = dir + File.separatorChar + + BackupFilenameFilter.getBackupFilename(nextIndexNum, basename, + suffix, digits, extension); + File latestBackupFile = new File(latestBackupFilename); + ret = ret && file.renameTo(latestBackupFile); + + return ret; + } + + private void deleteOldFiles(File[] oldFilesToDelete, String confirmDeleteExtraInfo) { if (oldFilesToDelete != null && oldFilesToDelete.length > 0) { // delete old backup/version files @@ -415,15 +417,21 @@ public class BackupFiles } } + } - // Let's make the new backup file!! yay, got there at last! - String latestBackupFilename = dir + File.separatorChar - + BackupFilenameFilter.getBackupFilename(nextIndexNum, basename, - suffix, digits, extension); - File latestBackupFile = new File(latestBackupFilename); - ret = ret && file.renameTo(latestBackupFile); - - return ret; + private TreeMap sortBackupFilesAsTreeMap(File[] backupFiles, String basename, String extension) { + // sort the backup files (based on integer found in the suffix) using a + // precomputed Hashmap for speed + Map bfHashMap = new HashMap<>(); + for (int i = 0; i < backupFiles.length; i++) + { + File f = backupFiles[i]; + BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix, digits, extension); + bfHashMap.put(bfp.indexNum(), f); + } + TreeMap bfTreeMap = new TreeMap<>(); + bfTreeMap.putAll(bfHashMap); + return bfTreeMap; } public boolean rollBackupsAndRenameTempFile()