X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FBackupFiles.java;fp=src%2Fjalview%2Fio%2FBackupFiles.java;h=defc47b50f5abfd852545c5b1593b37cdc248bb6;hb=15d1b4064456f85f3ed602440b10184057460a72;hp=2b6147f9c88083d497aee58e969e2dad54faf19b;hpb=a2214909ebf9788ca5c6386f1f1675efe3d02b9b;p=jalview.git diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index 2b6147f..defc47b 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.TreeMap; import jalview.bin.Cache; +import jalview.bin.Console; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; @@ -131,17 +132,17 @@ public class BackupFiles { String tempfilename = file.getName(); File tempdir = file.getParentFile(); - Cache.trace( + Console.trace( "BACKUPFILES [file!=null] attempting to create temp file for " + tempfilename + " in dir " + tempdir); temp = File.createTempFile(tempfilename, TEMP_FILE_EXT + newTempFileSuffix, tempdir); - Cache.debug( + Console.debug( "BACKUPFILES using temp file " + temp.getAbsolutePath()); } else { - Cache.trace( + Console.trace( "BACKUPFILES [file==null] attempting to create default temp file " + DEFAULT_TEMP_FILE + " with extension " + TEMP_FILE_EXT); @@ -149,29 +150,29 @@ public class BackupFiles } } catch (IOException e) { - Cache.error("Could not create temp file to save to (IOException)"); - Cache.error(e.getMessage()); - Cache.debug(Cache.getStackTraceString(e)); + Console.error("Could not create temp file to save to (IOException)"); + Console.error(e.getMessage()); + Console.debug(Cache.getStackTraceString(e)); } catch (Exception e) { - Cache.error("Exception creating temp file for saving"); - Cache.debug(Cache.getStackTraceString(e)); + Console.error("Exception creating temp file for saving"); + Console.debug(Cache.getStackTraceString(e)); } this.setTempFile(temp); } public static void classInit() { - Cache.initLogger(); - Cache.trace("BACKUPFILES classInit"); + Console.initLogger(); + Console.trace("BACKUPFILES classInit"); boolean e = Cache.getDefault(ENABLED, !Platform.isJS()); setEnabled(e); - Cache.trace("BACKUPFILES " + (e ? "enabled" : "disabled")); + Console.trace("BACKUPFILES " + (e ? "enabled" : "disabled")); BackupFilesPresetEntry bfpe = BackupFilesPresetEntry .getSavedBackupEntry(); - Cache.trace("BACKUPFILES preset scheme " + bfpe.toString()); + Console.trace("BACKUPFILES preset scheme " + bfpe.toString()); setConfirmDelete(bfpe.confirmDelete); - Cache.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete); + Console.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete); } public static void setEnabled(boolean flag) @@ -215,9 +216,9 @@ public class BackupFiles path = this.getTempFile().getCanonicalPath(); } catch (IOException e) { - Cache.error("IOException when getting Canonical Path of temp file '" + Console.error("IOException when getting Canonical Path of temp file '" + this.getTempFile().getName() + "'"); - Cache.debug(Cache.getStackTraceString(e)); + Console.debug(Cache.getStackTraceString(e)); } return path; } @@ -253,7 +254,7 @@ public class BackupFiles || suffix.length() == 0) { // nothing to do - Cache.debug("BACKUPFILES rollBackupFiles nothing to do." + ", " + Console.debug("BACKUPFILES rollBackupFiles nothing to do." + ", " + "filename: " + (file != null ? file.getName() : "null") + ", " + "file exists: " + file.exists() + ", " + "enabled: " + enabled + ", " + "max: " + max + ", " + "suffix: '" + suffix @@ -261,7 +262,7 @@ public class BackupFiles return true; } - Cache.trace("BACKUPFILES rollBackupFiles starting"); + Console.trace("BACKUPFILES rollBackupFiles starting"); String dir = ""; File dirFile; @@ -269,18 +270,18 @@ public class BackupFiles { dirFile = file.getParentFile(); dir = dirFile.getCanonicalPath(); - Cache.trace("BACKUPFILES dir: " + dir); + Console.trace("BACKUPFILES dir: " + dir); } catch (Exception e) { - Cache.error("Could not get canonical path for file '" + file + "'"); - Cache.error(e.getMessage()); - Cache.debug(Cache.getStackTraceString(e)); + Console.error("Could not get canonical path for file '" + file + "'"); + Console.error(e.getMessage()); + Console.debug(Cache.getStackTraceString(e)); return false; } String filename = file.getName(); String basename = filename; - Cache.trace("BACKUPFILES filename is " + filename); + Console.trace("BACKUPFILES filename is " + filename); boolean ret = true; // Create/move backups up one @@ -292,11 +293,11 @@ public class BackupFiles File[] backupFiles = dirFile.listFiles(bff); int nextIndexNum = 0; - Cache.trace("BACKUPFILES backupFiles.length: " + backupFiles.length); + Console.trace("BACKUPFILES backupFiles.length: " + backupFiles.length); if (backupFiles.length == 0) { // No other backup files. Just need to move existing file to backupfile_1 - Cache.trace( + Console.trace( "BACKUPFILES no existing backup files, setting index to 1"); nextIndexNum = 1; } @@ -310,7 +311,7 @@ public class BackupFiles if (reverseOrder) { // backup style numbering - Cache.trace("BACKUPFILES rolling files in reverse order"); + Console.trace("BACKUPFILES rolling files in reverse order"); int tempMax = noMax ? -1 : max; // noMax == true means no limits @@ -342,7 +343,7 @@ public class BackupFiles // no "oldest" file to delete previousFile = backupfile_n; fileToBeDeleted = null; - Cache.trace("BACKUPFILES No oldest file to delete"); + Console.trace("BACKUPFILES No oldest file to delete"); continue; } @@ -353,9 +354,9 @@ public class BackupFiles File replacementFile = backupfile_n; long fileToBeDeletedLMT = fileToBeDeleted.lastModified(); long replacementFileLMT = replacementFile.lastModified(); - Cache.trace("BACKUPFILES fileToBeDeleted is " + Console.trace("BACKUPFILES fileToBeDeleted is " + fileToBeDeleted.getAbsolutePath()); - Cache.trace("BACKUPFILES replacementFile is " + Console.trace("BACKUPFILES replacementFile is " + backupfile_n.getAbsolutePath()); try @@ -369,7 +370,7 @@ public class BackupFiles .format(fileToBeDeletedLMT); String replacementFileLMTString = sdf .format(replacementFileLMT); - Cache.warn("WARNING! I am set to delete backupfile " + Console.warn("WARNING! I am set to delete backupfile " + fileToBeDeleted.getName() + " has modification time " + fileToBeDeletedLMTString @@ -380,7 +381,7 @@ public class BackupFiles boolean delete = confirmNewerDeleteFile(fileToBeDeleted, replacementFile, true); - Cache.trace("BACKUPFILES " + (delete ? "confirmed" : "not") + Console.trace("BACKUPFILES " + (delete ? "confirmed" : "not") + " deleting file " + fileToBeDeleted.getAbsolutePath() + " which is newer than " @@ -393,7 +394,7 @@ public class BackupFiles } else { - Cache.debug("BACKUPFILES moving " + Console.debug("BACKUPFILES moving " + fileToBeDeleted.getAbsolutePath() + " to " + oldestTempFile.getAbsolutePath()); moveFileToFile(fileToBeDeleted, oldestTempFile); @@ -401,7 +402,7 @@ public class BackupFiles } else { - Cache.debug("BACKUPFILES going to move " + Console.debug("BACKUPFILES going to move " + fileToBeDeleted.getAbsolutePath() + " to " + oldestTempFile.getAbsolutePath()); moveFileToFile(fileToBeDeleted, oldestTempFile); @@ -410,10 +411,10 @@ public class BackupFiles } catch (Exception e) { - Cache.error( + Console.error( "Error occurred, probably making new temp file for '" + fileToBeDeleted.getName() + "'"); - Cache.error(Cache.getStackTraceString(e)); + Console.error(Cache.getStackTraceString(e)); } // reset @@ -455,12 +456,12 @@ public class BackupFiles } bfsb.append(backupFiles[i].getName()); } - Cache.trace("BACKUPFILES backupFiles: " + bfsb.toString()); + Console.trace("BACKUPFILES backupFiles: " + bfsb.toString()); // noMax == true means keep all backup files if ((!noMax) && bfTreeMap.size() >= max) { - Cache.trace("BACKUPFILES noMax: " + noMax + ", " + "max: " + max + Console.trace("BACKUPFILES noMax: " + noMax + ", " + "max: " + max + ", " + "bfTreeMap.size(): " + bfTreeMap.size()); // need to delete some files to keep number of backups to designated // max. @@ -470,7 +471,7 @@ public class BackupFiles int numToDelete = suffix.indexOf(NUM_PLACEHOLDER) > -1 ? bfTreeMap.size() - max + 1 : 0; - Cache.trace("BACKUPFILES numToDelete: " + numToDelete); + Console.trace("BACKUPFILES numToDelete: " + numToDelete); // the "replacement" file is the latest backup file being kept (it's // not replacing though) File replacementFile = numToDelete < backupFiles.length @@ -483,7 +484,7 @@ public class BackupFiles File fileToBeDeleted = backupFiles[i]; boolean delete = true; - Cache.trace("BACKUPFILES fileToBeDeleted: " + fileToBeDeleted); + Console.trace("BACKUPFILES fileToBeDeleted: " + fileToBeDeleted); boolean newer = false; if (replacementFile != null) @@ -499,7 +500,7 @@ public class BackupFiles String replacementFileLMTString = sdf .format(replacementFileLMT); - Cache.warn("WARNING! I am set to delete backupfile '" + Console.warn("WARNING! I am set to delete backupfile '" + fileToBeDeleted.getName() + "' has modification time " + fileToBeDeletedLMTString @@ -514,14 +515,14 @@ public class BackupFiles { // User has confirmed delete -- no need to add it to the list fileToBeDeleted.delete(); - Cache.debug("BACKUPFILES deleting fileToBeDeleted: " + Console.debug("BACKUPFILES deleting fileToBeDeleted: " + fileToBeDeleted); delete = false; } else { // keeping file, nothing to do! - Cache.debug("BACKUPFILES keeping fileToBeDeleted: " + Console.debug("BACKUPFILES keeping fileToBeDeleted: " + fileToBeDeleted); } } @@ -529,7 +530,7 @@ public class BackupFiles if (delete) { addDeleteFile(fileToBeDeleted); - Cache.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): " + Console.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): " + fileToBeDeleted); } @@ -545,16 +546,16 @@ public class BackupFiles String latestBackupFilename = dir + File.separatorChar + BackupFilenameParts.getBackupFilename(nextIndexNum, basename, suffix, digits); - Cache.trace("BACKUPFILES Moving old file [" + file + Console.trace("BACKUPFILES Moving old file [" + file + "] to latestBackupFilename [" + latestBackupFilename + "]"); // using boolean '&' instead of '&&' as don't want moveFileToFile attempt to // be conditional (short-circuit) ret = ret & moveFileToFile(file, new File(latestBackupFilename)); - Cache.debug("BACKUPFILES moving " + file + " to " + latestBackupFilename + Console.debug("BACKUPFILES moving " + file + " to " + latestBackupFilename + " was " + (ret ? "" : "NOT ") + "successful"); if (tidyUp) { - Cache.debug("BACKUPFILES tidying up files"); + Console.debug("BACKUPFILES tidying up files"); tidyUpFiles(); } @@ -610,7 +611,7 @@ public class BackupFiles saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile()); } catch (Exception e) { - Cache.error( + Console.error( "Error when confirming to keep backup file newer than other backup files."); e.printStackTrace(); } @@ -720,10 +721,10 @@ public class BackupFiles for (int i = 0; i < deleteFiles.size(); i++) { File fileToDelete = deleteFiles.get(i); - Cache.trace("BACKUPFILES about to delete fileToDelete:" + Console.trace("BACKUPFILES about to delete fileToDelete:" + fileToDelete); fileToDelete.delete(); - Cache.warn("deleted '" + fileToDelete.getName() + "'"); + Console.warn("deleted '" + fileToDelete.getName() + "'"); } } @@ -832,7 +833,7 @@ public class BackupFiles dirFile = file.getParentFile(); } catch (Exception e) { - Cache.error("Could not get canonical path for file '" + file + "'"); + Console.error("Could not get canonical path for file '" + file + "'"); return new TreeMap<>(); } @@ -873,14 +874,14 @@ public class BackupFiles int pos = deleteFiles.indexOf(fileToBeDeleted); if (pos > -1) { - Cache.debug("BACKUPFILES not adding file " + Console.debug("BACKUPFILES not adding file " + fileToBeDeleted.getAbsolutePath() + " to the delete list (already at index" + pos + ")"); return true; } else { - Cache.debug("BACKUPFILES adding file " + Console.debug("BACKUPFILES adding file " + fileToBeDeleted.getAbsolutePath() + " to the delete list"); deleteFiles.add(fileToBeDeleted); } @@ -889,31 +890,31 @@ public class BackupFiles public static boolean moveFileToFile(File oldFile, File newFile) { - Cache.initLogger(); + Console.initLogger(); boolean ret = false; Path oldPath = Paths.get(oldFile.getAbsolutePath()); Path newPath = Paths.get(newFile.getAbsolutePath()); try { // delete destination file - not usually necessary but Just In Case... - Cache.trace("BACKUPFILES deleting " + newFile.getAbsolutePath()); + Console.trace("BACKUPFILES deleting " + newFile.getAbsolutePath()); newFile.delete(); - Cache.trace("BACKUPFILES moving " + oldFile.getAbsolutePath() + " to " + Console.trace("BACKUPFILES moving " + oldFile.getAbsolutePath() + " to " + newFile.getAbsolutePath()); Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING); ret = true; - Cache.trace("BACKUPFILES move seems to have succeeded"); + Console.trace("BACKUPFILES move seems to have succeeded"); } catch (IOException e) { - Cache.warn("Could not move file '" + oldPath.toString() + "' to '" + Console.warn("Could not move file '" + oldPath.toString() + "' to '" + newPath.toString() + "'"); - Cache.error(e.getMessage()); - Cache.debug(Cache.getStackTraceString(e)); + Console.error(e.getMessage()); + Console.debug(Cache.getStackTraceString(e)); ret = false; } catch (Exception e) { - Cache.error(e.getMessage()); - Cache.debug(Cache.getStackTraceString(e)); + Console.error(e.getMessage()); + Console.debug(Cache.getStackTraceString(e)); ret = false; } return ret;