2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.io.IOException;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.nio.file.Paths;
28 import java.nio.file.StandardCopyOption;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.HashMap;
33 import java.util.TreeMap;
35 import jalview.bin.Cache;
36 import jalview.gui.Desktop;
37 import jalview.gui.JvOptionPane;
38 import jalview.util.MessageManager;
39 import jalview.util.Platform;
42 * BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
43 * User configurable options are:
44 * BACKUPFILES_ENABLED - boolean flag as to whether to use this mechanism or act as before, including overwriting files as saved.
45 * The rest of the options are now saved as BACKUPFILES_PRESET, BACKUPFILES_SAVED and BACKUPFILES_CUSTOM
46 * (see BackupFilesPresetEntry)
49 public class BackupFiles
52 // labels for saved params in Cache and .jalview_properties
53 public static final String NS = "BACKUPFILES";
55 public static final String ENABLED = NS + "_ENABLED";
57 public static final String NUM_PLACEHOLDER = "%n";
59 private static final String DEFAULT_TEMP_FILE = "jalview_temp_file_" + NS;
61 private static final String TEMP_FILE_EXT = ".tmp";
63 // file - File object to be backed up and then updated (written over)
66 // enabled - default flag as to whether to do the backup file roll (if not
67 // defined in preferences)
68 private static boolean enabled;
70 // confirmDelete - default flag as to whether to confirm with the user before
71 // deleting old backup/version files
72 private static boolean confirmDelete;
74 // defaultSuffix - default template to use to append to basename of file
75 private String suffix;
77 // noMax - flag to turn off a maximum number of files
78 private boolean noMax;
80 // defaultMax - default max number of backup files
83 // defaultDigits - number of zero-led digits to use in the filename
86 // reverseOrder - set to true to make newest (latest) files lowest number
87 // (like rolled log files)
88 private boolean reverseOrder;
90 // temp saved file to become new saved file
91 private File tempFile;
93 // flag set to see if file save to temp file was successful
94 private boolean tempFileWriteSuccess;
96 // array of files to be deleted, with extra information
97 private ArrayList<File> deleteFiles = new ArrayList<>();
99 // date formatting for modification times
100 private static final SimpleDateFormat sdf = new SimpleDateFormat(
101 "yyyy-MM-dd HH:mm:ss");
103 private static final String newTempFileSuffix = "_newfile";
105 private static final String oldTempFileSuffix = "_oldfile_tobedeleted";
107 public BackupFiles(String filename)
109 this(new File(filename));
112 // first time defaults for SUFFIX, NO_MAX, ROLL_MAX, SUFFIX_DIGITS and
114 public BackupFiles(File file)
118 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
119 .getSavedBackupEntry();
120 this.suffix = bfpe.suffix;
121 this.noMax = bfpe.keepAll;
122 this.max = bfpe.rollMax;
123 this.digits = bfpe.digits;
124 this.reverseOrder = bfpe.reverse;
126 // create a temp file to save new data in
132 String tempfilename = file.getName();
133 File tempdir = file.getParentFile();
135 "BACKUPFILES [file!=null] attempting to create temp file for "
136 + tempfilename + " in dir " + tempdir);
137 temp = File.createTempFile(tempfilename,
138 TEMP_FILE_EXT + newTempFileSuffix, tempdir);
140 "BACKUPFILES using temp file " + temp.getAbsolutePath());
145 "BACKUPFILES [file==null] attempting to create default temp file "
146 + DEFAULT_TEMP_FILE + " with extension "
148 temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
150 } catch (IOException e)
153 .error("Could not create temp file to save to (IOException)");
154 Cache.log.error(e.getMessage());
155 Cache.log.debug(Cache.getStackTraceString(e));
156 } catch (Exception e)
158 Cache.log.error("Exception ctreating temp file for saving");
159 Cache.log.debug(Cache.getStackTraceString(e));
161 this.setTempFile(temp);
164 public static void classInit()
167 Cache.log.trace("BACKUPFILES classInit");
168 boolean e = Cache.getDefault(ENABLED, true);
170 Cache.log.trace("BACKUPFILES " + (e ? "enabled" : "disabled"));
171 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
172 .getSavedBackupEntry();
173 Cache.log.trace("BACKUPFILES preset scheme " + bfpe.toString());
174 setConfirmDelete(bfpe.confirmDelete);
175 Cache.log.trace("BACKUPFILES confirm delete " + bfpe.confirmDelete);
178 public static void setEnabled(boolean flag)
183 public static boolean getEnabled()
189 public static void setConfirmDelete(boolean flag)
191 confirmDelete = flag;
194 public static boolean getConfirmDelete()
197 return confirmDelete;
200 // set, get and rename temp file into place
201 public void setTempFile(File temp)
203 this.tempFile = temp;
206 public File getTempFile()
211 public String getTempFilePath()
216 path = this.getTempFile().getCanonicalPath();
217 } catch (IOException e)
220 "IOException when getting Canonical Path of temp file '"
221 + this.getTempFile().getName() + "'");
222 Cache.log.debug(Cache.getStackTraceString(e));
227 public boolean setWriteSuccess(boolean flag)
229 boolean old = this.tempFileWriteSuccess;
230 this.tempFileWriteSuccess = flag;
234 public boolean getWriteSuccess()
236 return this.tempFileWriteSuccess;
239 public boolean renameTempFile()
241 return moveFileToFile(tempFile, file);
244 // roll the backupfiles
245 public boolean rollBackupFiles()
247 return this.rollBackupFiles(true);
250 public boolean rollBackupFiles(boolean tidyUp)
252 // file doesn't yet exist or backups are not enabled or template is null or
254 if ((!file.exists()) || (!enabled) || max < 0 || suffix == null
255 || suffix.length() == 0)
258 Cache.log.debug("BACKUPFILES rollBackupFiles nothing to do." + ", "
259 + "filename: " + (file != null ? file.getName() : "null")
260 + ", " + "file exists: " + file.exists() + ", " + "enabled: "
261 + enabled + ", " + "max: " + max + ", " + "suffix: '" + suffix
266 Cache.log.trace("BACKUPFILES rollBackupFiles starting");
272 dirFile = file.getParentFile();
273 dir = dirFile.getCanonicalPath();
274 Cache.log.trace("BACKUPFILES dir: " + dir);
275 } catch (Exception e)
278 "Could not get canonical path for file '" + file + "'");
279 Cache.log.error(e.getMessage());
280 Cache.log.debug(Cache.getStackTraceString(e));
283 String filename = file.getName();
284 String basename = filename;
286 Cache.log.trace("BACKUPFILES filename is " + filename);
288 // Create/move backups up one
292 // find existing backup files
293 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
295 File[] backupFiles = dirFile.listFiles(bff);
296 int nextIndexNum = 0;
299 .trace("BACKUPFILES backupFiles.length: " + backupFiles.length);
300 if (backupFiles.length == 0)
302 // No other backup files. Just need to move existing file to backupfile_1
304 "BACKUPFILES no existing backup files, setting index to 1");
309 TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
310 backupFiles, basename);
311 // bfTreeMap now a sorted list of <Integer index>,<File backupfile>
316 // backup style numbering
317 Cache.log.trace("BACKUPFILES rolling files in reverse order");
319 int tempMax = noMax ? -1 : max;
320 // noMax == true means no limits
321 // look for first "gap" in backupFiles
322 // if tempMax is -1 at this stage just keep going until there's a gap,
323 // then hopefully tempMax gets set to the right index (a positive
324 // integer so the loop breaks)...
325 // why do I feel a little uneasy about this loop?..
326 for (int i = 1; tempMax < 0 || i <= max; i++)
328 if (!bfTreeMap.containsKey(i)) // first index without existent
335 File previousFile = null;
336 File fileToBeDeleted = null;
337 for (int n = tempMax; n > 0; n--)
339 String backupfilename = dir + File.separatorChar
340 + BackupFilenameParts.getBackupFilename(n, basename,
342 File backupfile_n = new File(backupfilename);
344 if (!backupfile_n.exists())
346 // no "oldest" file to delete
347 previousFile = backupfile_n;
348 fileToBeDeleted = null;
349 Cache.log.trace("BACKUPFILES No oldest file to delete");
353 // check the modification time of this (backupfile_n) and the previous
354 // file (fileToBeDeleted) if the previous file is going to be deleted
355 if (fileToBeDeleted != null)
357 File replacementFile = backupfile_n;
358 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
359 long replacementFileLMT = replacementFile.lastModified();
360 Cache.log.trace("BACKUPFILES fileToBeDeleted is "
361 + fileToBeDeleted.getAbsolutePath());
362 Cache.log.trace("BACKUPFILES replacementFile is "
363 + backupfile_n.getAbsolutePath());
367 File oldestTempFile = nextTempFile(fileToBeDeleted.getName(),
370 if (fileToBeDeletedLMT > replacementFileLMT)
372 String fileToBeDeletedLMTString = sdf
373 .format(fileToBeDeletedLMT);
374 String replacementFileLMTString = sdf
375 .format(replacementFileLMT);
376 Cache.log.warn("WARNING! I am set to delete backupfile "
377 + fileToBeDeleted.getName()
378 + " has modification time "
379 + fileToBeDeletedLMTString
380 + " which is newer than its replacement "
381 + replacementFile.getName()
382 + " with modification time "
383 + replacementFileLMTString);
385 boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
386 replacementFile, true);
387 Cache.log.trace("BACKUPFILES "
388 + (delete ? "confirmed" : "not") + " deleting file "
389 + fileToBeDeleted.getAbsolutePath()
390 + " which is newer than "
391 + replacementFile.getAbsolutePath());
395 // User has confirmed delete -- no need to add it to the list
396 fileToBeDeleted.delete();
400 Cache.log.debug("BACKUPFILES moving "
401 + fileToBeDeleted.getAbsolutePath() + " to "
402 + oldestTempFile.getAbsolutePath());
403 moveFileToFile(fileToBeDeleted, oldestTempFile);
408 Cache.log.debug("BACKUPFILES going to move "
409 + fileToBeDeleted.getAbsolutePath() + " to "
410 + oldestTempFile.getAbsolutePath());
411 moveFileToFile(fileToBeDeleted, oldestTempFile);
412 addDeleteFile(oldestTempFile);
415 } catch (Exception e)
418 "Error occurred, probably making new temp file for '"
419 + fileToBeDeleted.getName() + "'");
420 Cache.log.error(Cache.getStackTraceString(e));
424 fileToBeDeleted = null;
427 if (!noMax && n == tempMax && backupfile_n.exists())
429 fileToBeDeleted = backupfile_n;
433 if (previousFile != null)
435 // using boolean '&' instead of '&&' as don't want moveFileToFile
436 // attempt to be conditional (short-circuit)
437 ret = ret & moveFileToFile(backupfile_n, previousFile);
441 previousFile = backupfile_n;
444 // index to use for the latest backup
447 else // not reverse numbering
449 // version style numbering (with earliest file deletion if max files
452 bfTreeMap.values().toArray(backupFiles);
453 StringBuilder bfsb = new StringBuilder();
454 for (int i = 0; i < backupFiles.length; i++)
456 if (bfsb.length() > 0)
460 bfsb.append(backupFiles[i].getName());
462 Cache.log.trace("BACKUPFILES backupFiles: " + bfsb.toString());
464 // noMax == true means keep all backup files
465 if ((!noMax) && bfTreeMap.size() >= max)
467 Cache.log.trace("BACKUPFILES noMax: " + noMax + ", " + "max: "
468 + max + ", " + "bfTreeMap.size(): " + bfTreeMap.size());
469 // need to delete some files to keep number of backups to designated
471 // Note that if the suffix is not numbered then do not delete any
472 // backup files later or we'll delete the new backup file (there can
474 int numToDelete = suffix.indexOf(NUM_PLACEHOLDER) > -1
475 ? bfTreeMap.size() - max + 1
477 Cache.log.trace("BACKUPFILES numToDelete: " + numToDelete);
478 // the "replacement" file is the latest backup file being kept (it's
479 // not replacing though)
480 File replacementFile = numToDelete < backupFiles.length
481 ? backupFiles[numToDelete]
483 for (int i = 0; i < numToDelete; i++)
485 // check the deletion files for modification time of the last
486 // backupfile being saved
487 File fileToBeDeleted = backupFiles[i];
488 boolean delete = true;
491 "BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
493 boolean newer = false;
494 if (replacementFile != null)
496 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
497 long replacementFileLMT = replacementFile != null
498 ? replacementFile.lastModified()
500 if (fileToBeDeletedLMT > replacementFileLMT)
502 String fileToBeDeletedLMTString = sdf
503 .format(fileToBeDeletedLMT);
504 String replacementFileLMTString = sdf
505 .format(replacementFileLMT);
507 Cache.log.warn("WARNING! I am set to delete backupfile '"
508 + fileToBeDeleted.getName()
509 + "' has modification time "
510 + fileToBeDeletedLMTString
511 + " which is newer than the oldest backupfile being kept '"
512 + replacementFile.getName()
513 + "' with modification time "
514 + replacementFileLMTString);
516 delete = confirmNewerDeleteFile(fileToBeDeleted,
517 replacementFile, false);
520 // User has confirmed delete -- no need to add it to the list
521 fileToBeDeleted.delete();
522 Cache.log.debug("BACKUPFILES deleting fileToBeDeleted: "
528 // keeping file, nothing to do!
529 Cache.log.debug("BACKUPFILES keeping fileToBeDeleted: "
536 addDeleteFile(fileToBeDeleted);
537 Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
545 nextIndexNum = bfTreeMap.lastKey() + 1;
549 // Let's make the new backup file!! yay, got there at last!
550 String latestBackupFilename = dir + File.separatorChar
551 + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
553 Cache.log.trace("BACKUPFILES Moving old file [" + file
554 + "] to latestBackupFilename [" + latestBackupFilename + "]");
555 // using boolean '&' instead of '&&' as don't want moveFileToFile attempt to
556 // be conditional (short-circuit)
557 ret = ret & moveFileToFile(file, new File(latestBackupFilename));
559 "BACKUPFILES moving " + file + " to " + latestBackupFilename
560 + " was " + (ret ? "" : "NOT ") + "successful");
563 Cache.log.debug("BACKUPFILES tidying up files");
570 private static File nextTempFile(String filename, File dirFile)
574 COUNT: for (int i = 1; i < 1000; i++)
576 File trythis = new File(dirFile,
577 filename + '~' + Integer.toString(i));
578 if (!trythis.exists())
587 temp = File.createTempFile(filename, TEMP_FILE_EXT, dirFile);
592 private void tidyUpFiles()
597 private static boolean confirmNewerDeleteFile(File fileToBeDeleted,
598 File replacementFile, boolean replace)
600 StringBuilder messageSB = new StringBuilder();
602 File ftbd = fileToBeDeleted;
603 String ftbdLMT = sdf.format(ftbd.lastModified());
604 String ftbdSize = Long.toString(ftbd.length());
606 File rf = replacementFile;
607 String rfLMT = sdf.format(rf.lastModified());
608 String rfSize = Long.toString(rf.length());
610 int confirmButton = JvOptionPane.NO_OPTION;
613 File saveFile = null;
616 saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile());
617 } catch (Exception e)
620 "Error when confirming to keep backup file newer than other backup files.");
623 messageSB.append(MessageManager.formatMessage(
624 "label.newerdelete_replacement_line", new String[]
625 { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
627 // "Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted and
628 // replaced by apparently older file \n''{1}''\t(modified {3}, size
630 messageSB.append("\n\n");
631 messageSB.append(MessageManager.formatMessage(
632 "label.confirm_deletion_or_rename", new String[]
633 { ftbd.getName(), saveFile.getName() }));
634 // "Confirm deletion of ''{0}'' or rename to ''{1}''?"
635 String[] options = new String[] {
636 MessageManager.getString("label.delete"),
637 MessageManager.getString("label.rename") };
639 confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
640 : JvOptionPane.showOptionDialog(Desktop.desktop,
641 messageSB.toString(),
642 MessageManager.getString(
643 "label.backupfiles_confirm_delete"),
645 JvOptionPane.YES_NO_OPTION,
646 JvOptionPane.WARNING_MESSAGE, null, options,
651 messageSB.append(MessageManager
652 .formatMessage("label.newerdelete_line", new String[]
653 { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
655 // "Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted but
656 // is newer than the oldest remaining backup file \n''{1}''\t(modified
658 messageSB.append("\n\n");
659 messageSB.append(MessageManager
660 .formatMessage("label.confirm_deletion", new String[]
661 { ftbd.getName() }));
662 // "Confirm deletion of ''{0}''?"
663 String[] options = new String[] {
664 MessageManager.getString("label.delete"),
665 MessageManager.getString("label.keep") };
667 confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
668 : JvOptionPane.showOptionDialog(Desktop.desktop,
669 messageSB.toString(),
670 MessageManager.getString(
671 "label.backupfiles_confirm_delete"),
673 JvOptionPane.YES_NO_OPTION,
674 JvOptionPane.WARNING_MESSAGE, null, options,
678 // return should be TRUE if file is to be deleted
679 return (confirmButton == JvOptionPane.YES_OPTION);
682 private void deleteOldFiles()
684 if (deleteFiles != null && !deleteFiles.isEmpty())
686 boolean doDelete = false;
687 StringBuilder messageSB = null;
688 if (confirmDelete && deleteFiles.size() > 0)
690 messageSB = new StringBuilder();
691 messageSB.append(MessageManager
692 .getString("label.backupfiles_confirm_delete_old_files"));
693 // "Delete the following older backup files? (see the Backups tab in
694 // Preferences for more options)"
695 for (int i = 0; i < deleteFiles.size(); i++)
697 File df = deleteFiles.get(i);
698 messageSB.append("\n");
699 messageSB.append(df.getName());
700 messageSB.append(" ");
701 messageSB.append(MessageManager.formatMessage("label.file_info",
703 { sdf.format(df.lastModified()),
704 Long.toString(df.length()) }));
705 // "(modified {0}, size {1})"
708 int confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
709 : JvOptionPane.showConfirmDialog(Desktop.desktop,
710 messageSB.toString(),
711 MessageManager.getString(
712 "label.backupfiles_confirm_delete"),
714 JvOptionPane.YES_NO_OPTION,
715 JvOptionPane.WARNING_MESSAGE);
717 doDelete = (confirmButton == JvOptionPane.YES_OPTION);
726 for (int i = 0; i < deleteFiles.size(); i++)
728 File fileToDelete = deleteFiles.get(i);
729 Cache.log.trace("BACKUPFILES about to delete fileToDelete:"
731 fileToDelete.delete();
732 Cache.log.warn("deleted '" + fileToDelete.getName() + "'");
741 private TreeMap<Integer, File> sortBackupFilesAsTreeMap(
742 File[] backupFiles, String basename)
744 // sort the backup files (based on integer found in the suffix) using a
745 // precomputed Hashmap for speed
746 Map<Integer, File> bfHashMap = new HashMap<>();
747 for (int i = 0; i < backupFiles.length; i++)
749 File f = backupFiles[i];
750 BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
752 bfHashMap.put(bfp.indexNum(), f);
754 TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
755 bfTreeMap.putAll(bfHashMap);
759 public boolean rollBackupsAndRenameTempFile()
761 boolean write = this.getWriteSuccess();
763 boolean roll = false;
764 boolean rename = false;
767 roll = this.rollBackupFiles(false); // tidyUpFiles at the end
768 rename = this.renameTempFile();
772 * Not sure that this confirmation is desirable. By this stage the new file is
773 * already written successfully, but something (e.g. disk full) has happened while
774 * trying to roll the backup files, and most likely the filename needed will already
775 * be vacant so renaming the temp file is nearly always correct!
777 boolean okay = roll && rename;
780 StringBuilder messageSB = new StringBuilder();
781 messageSB.append(MessageManager.getString(
782 "label.backupfiles_confirm_save_file_backupfiles_roll_wrong"));
783 // "Something possibly went wrong with the backups of this file."
786 if (messageSB.length() > 0)
788 messageSB.append("\n");
790 messageSB.append(MessageManager.getString(
791 "label.backupfiles_confirm_save_new_saved_file_ok"));
792 // "The new saved file seems okay."
796 if (messageSB.length() > 0)
798 messageSB.append("\n");
800 messageSB.append(MessageManager.getString(
801 "label.backupfiles_confirm_save_new_saved_file_not_ok"));
802 // "The new saved file might not be okay."
804 if (messageSB.length() > 0)
806 messageSB.append("\n");
809 .append(MessageManager.getString("label.continue_operation"));
811 int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION
812 : JvOptionPane.showConfirmDialog(Desktop.desktop,
813 messageSB.toString(),
814 MessageManager.getString(
815 "label.backupfiles_confirm_save_file"),
816 // "Confirm save file"
817 JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
818 okay = confirmButton == JvOptionPane.OK_OPTION;
828 public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
829 String fileName, String suffix, int digits)
831 File[] backupFiles = null;
833 File file = new File(fileName);
838 dirFile = file.getParentFile();
839 } catch (Exception e)
842 "Could not get canonical path for file '" + file + "'");
843 return new TreeMap<>();
846 String filename = file.getName();
847 String basename = filename;
849 // find existing backup files
850 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
852 backupFiles = dirFile.listFiles(bff); // is clone needed?
854 // sort the backup files (based on integer found in the suffix) using a
855 // precomputed Hashmap for speed
856 Map<Integer, File> bfHashMap = new HashMap<>();
857 for (int i = 0; i < backupFiles.length; i++)
859 File f = backupFiles[i];
860 BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
862 bfHashMap.put(bfp.indexNum(), f);
864 TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
865 bfTreeMap.putAll(bfHashMap);
871 private boolean addDeleteFile(File fileToBeDeleted, File originalFile,
872 boolean delete, boolean newer)
874 return addDeleteFile(fileToBeDeleted, originalFile, null, delete, newer);
877 private boolean addDeleteFile(File fileToBeDeleted)
880 int pos = deleteFiles.indexOf(fileToBeDeleted);
883 Cache.log.debug("BACKUPFILES not adding file "
884 + fileToBeDeleted.getAbsolutePath()
885 + " to the delete list (already at index" + pos + ")");
890 Cache.log.debug("BACKUPFILES adding file "
891 + fileToBeDeleted.getAbsolutePath() + " to the delete list");
892 deleteFiles.add(fileToBeDeleted);
897 public static boolean moveFileToFile(File oldFile, File newFile)
901 Path oldPath = Paths.get(oldFile.getAbsolutePath());
902 Path newPath = Paths.get(newFile.getAbsolutePath());
905 // delete destination file - not usually necessary but Just In Case...
906 Cache.log.trace("BACKUPFILES deleting " + newFile.getAbsolutePath());
908 Cache.log.trace("BACKUPFILES moving " + oldFile.getAbsolutePath()
909 + " to " + newFile.getAbsolutePath());
910 Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
912 Cache.log.trace("BACKUPFILES move seems to have succeeded");
913 } catch (IOException e)
915 Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
916 + newPath.toString() + "'");
917 Cache.log.error(e.getMessage());
918 Cache.log.debug(Cache.getStackTraceString(e));
920 } catch (Exception e)
922 Cache.log.error(e.getMessage());
923 Cache.log.debug(Cache.getStackTraceString(e));