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(e.getStackTrace());
156 } catch (Exception e)
158 Cache.log.error("Exception creating temp file for saving");
159 Cache.log.debug(e.getStackTrace());
161 this.setTempFile(temp);
164 public static void classInit()
166 Cache.log.debug("BACKUPFILES classInit");
167 boolean e = Cache.getDefault(ENABLED, !Platform.isJS());
169 Cache.log.debug("BACKUPFILES " + (e ? "enabled" : "disabled"));
170 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
171 .getSavedBackupEntry();
172 Cache.log.debug("BACKUPFILES preset scheme " + bfpe.toString());
173 setConfirmDelete(bfpe.confirmDelete);
174 Cache.log.debug("BACKUPFILES confirm delete " + bfpe.confirmDelete);
177 public static void setEnabled(boolean flag)
182 public static boolean getEnabled()
188 public static void setConfirmDelete(boolean flag)
190 confirmDelete = flag;
193 public static boolean getConfirmDelete()
196 return confirmDelete;
199 // set, get and rename temp file into place
200 public void setTempFile(File temp)
202 this.tempFile = temp;
205 public File getTempFile()
210 public String getTempFilePath()
215 path = this.getTempFile().getCanonicalPath();
216 } catch (IOException e)
219 "IOException when getting Canonical Path of temp file '"
220 + this.getTempFile().getName() + "'");
221 Cache.log.debug(e.getStackTrace());
226 public boolean setWriteSuccess(boolean flag)
228 boolean old = this.tempFileWriteSuccess;
229 this.tempFileWriteSuccess = flag;
233 public boolean getWriteSuccess()
235 return this.tempFileWriteSuccess;
238 public boolean renameTempFile()
240 return moveFileToFile(tempFile, file);
243 // roll the backupfiles
244 public boolean rollBackupFiles()
246 return this.rollBackupFiles(true);
249 public boolean rollBackupFiles(boolean tidyUp)
251 // file doesn't yet exist or backups are not enabled or template is null or
253 if ((!file.exists()) || (!enabled) || max < 0 || suffix == null
254 || suffix.length() == 0)
257 Cache.log.debug("BACKUPFILES rollBackupFiles nothing to do." + ", "
258 + "filename: " + (file != null ? file.getName() : "null")
259 + ", " + "file exists: " + file.exists() + ", " + "enabled: "
260 + enabled + ", " + "max: " + max + ", " + "suffix: '" + suffix
265 Cache.log.debug("BACKUPFILES rollBackupFiles starting");
271 dirFile = file.getParentFile();
272 dir = dirFile.getCanonicalPath();
273 Cache.log.debug("BACKUPFILES dir: " + dir);
274 } catch (Exception e)
277 "Could not get canonical path for file '" + file + "'");
278 Cache.log.error(e.getMessage());
279 Cache.log.debug(e.getStackTrace());
282 String filename = file.getName();
283 String basename = filename;
285 Cache.log.debug("BACKUPFILES filename is " + filename);
287 // Create/move backups up one
291 // find existing backup files
292 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
294 File[] backupFiles = dirFile.listFiles(bff);
295 int nextIndexNum = 0;
298 .debug("BACKUPFILES backupFiles.length: " + backupFiles.length);
299 if (backupFiles.length == 0)
301 // No other backup files. Just need to move existing file to backupfile_1
303 "BACKUPFILES no existing backup files, setting index to 1");
308 TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
309 backupFiles, basename);
310 // bfTreeMap now a sorted list of <Integer index>,<File backupfile>
315 // backup style numbering
316 Cache.log.debug("BACKUPFILES rolling files in reverse order");
318 int tempMax = noMax ? -1 : max;
319 // noMax == true means no limits
320 // look for first "gap" in backupFiles
321 // if tempMax is -1 at this stage just keep going until there's a gap,
322 // then hopefully tempMax gets set to the right index (a positive
323 // integer so the loop breaks)...
324 // why do I feel a little uneasy about this loop?..
325 for (int i = 1; tempMax < 0 || i <= max; i++)
327 if (!bfTreeMap.containsKey(i)) // first index without existent
334 File previousFile = null;
335 File fileToBeDeleted = null;
336 for (int n = tempMax; n > 0; n--)
338 String backupfilename = dir + File.separatorChar
339 + BackupFilenameParts.getBackupFilename(n, basename,
341 File backupfile_n = new File(backupfilename);
343 if (!backupfile_n.exists())
345 // no "oldest" file to delete
346 previousFile = backupfile_n;
347 fileToBeDeleted = null;
348 Cache.log.debug("BACKUPFILES No oldest file to delete");
352 // check the modification time of this (backupfile_n) and the previous
353 // file (fileToBeDeleted) if the previous file is going to be deleted
354 if (fileToBeDeleted != null)
356 File replacementFile = backupfile_n;
357 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
358 long replacementFileLMT = replacementFile.lastModified();
359 Cache.log.debug("BACKUPFILES fileToBeDeleted is "
360 + fileToBeDeleted.getAbsolutePath());
361 Cache.log.debug("BACKUPFILES replacementFile is "
362 + backupfile_n.getAbsolutePath());
366 File oldestTempFile = nextTempFile(fileToBeDeleted.getName(),
369 if (fileToBeDeletedLMT > replacementFileLMT)
371 String fileToBeDeletedLMTString = sdf
372 .format(fileToBeDeletedLMT);
373 String replacementFileLMTString = sdf
374 .format(replacementFileLMT);
375 Cache.log.warn("WARNING! I am set to delete backupfile "
376 + fileToBeDeleted.getName()
377 + " has modification time "
378 + fileToBeDeletedLMTString
379 + " which is newer than its replacement "
380 + replacementFile.getName()
381 + " with modification time "
382 + replacementFileLMTString);
384 boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
385 replacementFile, true);
386 Cache.log.debug("BACKUPFILES "
387 + (delete ? "confirmed" : "not") + " deleting file "
388 + fileToBeDeleted.getAbsolutePath()
389 + " which is newer than "
390 + replacementFile.getAbsolutePath());
394 // User has confirmed delete -- no need to add it to the list
395 fileToBeDeleted.delete();
399 Cache.log.debug("BACKUPFILES moving "
400 + fileToBeDeleted.getAbsolutePath() + " to "
401 + oldestTempFile.getAbsolutePath());
402 moveFileToFile(fileToBeDeleted, oldestTempFile);
407 Cache.log.debug("BACKUPFILES going to move "
408 + fileToBeDeleted.getAbsolutePath() + " to "
409 + oldestTempFile.getAbsolutePath());
410 moveFileToFile(fileToBeDeleted, oldestTempFile);
411 addDeleteFile(oldestTempFile);
414 } catch (Exception e)
417 "Error occurred, probably making new temp file for '"
418 + fileToBeDeleted.getName() + "'");
419 Cache.log.error(e.getStackTrace());
423 fileToBeDeleted = null;
426 if (!noMax && n == tempMax && backupfile_n.exists())
428 fileToBeDeleted = backupfile_n;
432 if (previousFile != null)
434 ret = ret && moveFileToFile(backupfile_n, previousFile);
438 previousFile = backupfile_n;
441 // index to use for the latest backup
444 else // not reverse numbering
446 // version style numbering (with earliest file deletion if max files
449 bfTreeMap.values().toArray(backupFiles);
450 StringBuilder bfsb = new StringBuilder();
451 for (int i = 0; i < backupFiles.length; i++)
453 if (bfsb.length() > 0)
457 bfsb.append(backupFiles[i].getName());
459 Cache.log.debug("BACKUPFILES backupFiles: " + bfsb.toString());
461 // noMax == true means keep all backup files
462 if ((!noMax) && bfTreeMap.size() >= max)
464 Cache.log.debug("BACKUPFILES noMax: " + noMax + ", " + "max: "
465 + max + ", " + "bfTreeMap.size(): " + bfTreeMap.size());
466 // need to delete some files to keep number of backups to designated
468 // Note that if the suffix is not numbered then do not delete any
469 // backup files later or we'll delete the new backup file (there can
471 int numToDelete = suffix.indexOf(NUM_PLACEHOLDER) > -1
472 ? bfTreeMap.size() - max + 1
474 Cache.log.debug("BACKUPFILES numToDelete: " + numToDelete);
475 // the "replacement" file is the latest backup file being kept (it's
476 // not replacing though)
477 File replacementFile = numToDelete < backupFiles.length
478 ? backupFiles[numToDelete]
480 for (int i = 0; i < numToDelete; i++)
482 // check the deletion files for modification time of the last
483 // backupfile being saved
484 File fileToBeDeleted = backupFiles[i];
485 boolean delete = true;
488 "BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
490 boolean newer = false;
491 if (replacementFile != null)
493 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
494 long replacementFileLMT = replacementFile != null
495 ? replacementFile.lastModified()
497 if (fileToBeDeletedLMT > replacementFileLMT)
499 String fileToBeDeletedLMTString = sdf
500 .format(fileToBeDeletedLMT);
501 String replacementFileLMTString = sdf
502 .format(replacementFileLMT);
504 Cache.log.warn("WARNING! I am set to delete backupfile '"
505 + fileToBeDeleted.getName()
506 + "' has modification time "
507 + fileToBeDeletedLMTString
508 + " which is newer than the oldest backupfile being kept '"
509 + replacementFile.getName()
510 + "' with modification time "
511 + replacementFileLMTString);
513 delete = confirmNewerDeleteFile(fileToBeDeleted,
514 replacementFile, false);
517 // User has confirmed delete -- no need to add it to the list
518 fileToBeDeleted.delete();
519 Cache.log.debug("BACKUPFILES deleting fileToBeDeleted: "
525 // keeping file, nothing to do!
526 Cache.log.debug("BACKUPFILES keeping fileToBeDeleted: "
533 addDeleteFile(fileToBeDeleted);
534 Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
542 nextIndexNum = bfTreeMap.lastKey() + 1;
546 // Let's make the new backup file!! yay, got there at last!
547 String latestBackupFilename = dir + File.separatorChar
548 + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
550 Cache.log.debug("BACKUPFILES Moving old file [" + file
551 + "] to latestBackupFilename [" + latestBackupFilename + "]");
552 ret |= moveFileToFile(file, new File(latestBackupFilename));
554 "BACKUPFILES moving " + file + " to " + latestBackupFilename
555 + " was " + (ret ? "" : "NOT ") + "successful");
558 Cache.log.debug("BACKUPFILES tidying up files");
565 private static File nextTempFile(String filename, File dirFile)
569 COUNT: for (int i = 1; i < 1000; i++)
571 File trythis = new File(dirFile,
572 filename + '~' + Integer.toString(i));
573 if (!trythis.exists())
582 temp = File.createTempFile(filename, TEMP_FILE_EXT, dirFile);
587 private void tidyUpFiles()
592 private static boolean confirmNewerDeleteFile(File fileToBeDeleted,
593 File replacementFile, boolean replace)
595 StringBuilder messageSB = new StringBuilder();
597 File ftbd = fileToBeDeleted;
598 String ftbdLMT = sdf.format(ftbd.lastModified());
599 String ftbdSize = Long.toString(ftbd.length());
601 File rf = replacementFile;
602 String rfLMT = sdf.format(rf.lastModified());
603 String rfSize = Long.toString(rf.length());
605 int confirmButton = JvOptionPane.NO_OPTION;
608 File saveFile = null;
611 saveFile = nextTempFile(ftbd.getName(), ftbd.getParentFile());
612 } catch (Exception e)
615 "Error when confirming to keep backup file newer than other backup files.");
618 messageSB.append(MessageManager.formatMessage(
619 "label.newerdelete_replacement_line", new String[]
620 { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
622 // "Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted and
623 // replaced by apparently older file \n''{1}''\t(modified {3}, size
625 messageSB.append("\n\n");
626 messageSB.append(MessageManager.formatMessage(
627 "label.confirm_deletion_or_rename", new String[]
628 { ftbd.getName(), saveFile.getName() }));
629 // "Confirm deletion of ''{0}'' or rename to ''{1}''?"
630 String[] options = new String[] {
631 MessageManager.getString("label.delete"),
632 MessageManager.getString("label.rename") };
634 confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
635 : JvOptionPane.showOptionDialog(Desktop.desktop,
636 messageSB.toString(),
637 MessageManager.getString(
638 "label.backupfiles_confirm_delete"),
640 JvOptionPane.YES_NO_OPTION,
641 JvOptionPane.WARNING_MESSAGE, null, options,
646 messageSB.append(MessageManager
647 .formatMessage("label.newerdelete_line", new String[]
648 { ftbd.getName(), rf.getName(), ftbdLMT, rfLMT, ftbdSize,
650 // "Backup file\n''{0}''\t(modified {2}, size {4})\nis to be deleted but
651 // is newer than the oldest remaining backup file \n''{1}''\t(modified
653 messageSB.append("\n\n");
654 messageSB.append(MessageManager
655 .formatMessage("label.confirm_deletion", new String[]
656 { ftbd.getName() }));
657 // "Confirm deletion of ''{0}''?"
658 String[] options = new String[] {
659 MessageManager.getString("label.delete"),
660 MessageManager.getString("label.keep") };
662 confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
663 : JvOptionPane.showOptionDialog(Desktop.desktop,
664 messageSB.toString(),
665 MessageManager.getString(
666 "label.backupfiles_confirm_delete"),
668 JvOptionPane.YES_NO_OPTION,
669 JvOptionPane.WARNING_MESSAGE, null, options,
673 // return should be TRUE if file is to be deleted
674 return (confirmButton == JvOptionPane.YES_OPTION);
677 private void deleteOldFiles()
679 if (deleteFiles != null && !deleteFiles.isEmpty())
681 boolean doDelete = false;
682 StringBuilder messageSB = null;
683 if (confirmDelete && deleteFiles.size() > 0)
685 messageSB = new StringBuilder();
686 messageSB.append(MessageManager
687 .getString("label.backupfiles_confirm_delete_old_files"));
688 // "Delete the following older backup files? (see the Backups tab in
689 // Preferences for more options)"
690 for (int i = 0; i < deleteFiles.size(); i++)
692 File df = deleteFiles.get(i);
693 messageSB.append("\n");
694 messageSB.append(df.getName());
695 messageSB.append(" ");
696 messageSB.append(MessageManager.formatMessage("label.file_info",
698 { sdf.format(df.lastModified()),
699 Long.toString(df.length()) }));
700 // "(modified {0}, size {1})"
703 int confirmButton = Platform.isHeadless() ? JvOptionPane.YES_OPTION
704 : JvOptionPane.showConfirmDialog(Desktop.desktop,
705 messageSB.toString(),
706 MessageManager.getString(
707 "label.backupfiles_confirm_delete"),
709 JvOptionPane.YES_NO_OPTION,
710 JvOptionPane.WARNING_MESSAGE);
712 doDelete = (confirmButton == JvOptionPane.YES_OPTION);
721 for (int i = 0; i < deleteFiles.size(); i++)
723 File fileToDelete = deleteFiles.get(i);
725 "BACKUPFILES deleting fileToDelete:" + fileToDelete);
726 fileToDelete.delete();
727 Cache.log.warn("deleting '" + fileToDelete.getName() + "'");
736 private TreeMap<Integer, File> sortBackupFilesAsTreeMap(
737 File[] backupFiles, String basename)
739 // sort the backup files (based on integer found in the suffix) using a
740 // precomputed Hashmap for speed
741 Map<Integer, File> bfHashMap = new HashMap<>();
742 for (int i = 0; i < backupFiles.length; i++)
744 File f = backupFiles[i];
745 BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
747 bfHashMap.put(bfp.indexNum(), f);
749 TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
750 bfTreeMap.putAll(bfHashMap);
754 public boolean rollBackupsAndRenameTempFile()
756 boolean write = this.getWriteSuccess();
758 boolean roll = false;
759 boolean rename = false;
762 roll = this.rollBackupFiles(false); // tidyUpFiles at the end
763 rename = this.renameTempFile();
767 * Not sure that this confirmation is desirable. By this stage the new file is
768 * already written successfully, but something (e.g. disk full) has happened while
769 * trying to roll the backup files, and most likely the filename needed will already
770 * be vacant so renaming the temp file is nearly always correct!
772 boolean okay = roll && rename;
775 StringBuilder messageSB = new StringBuilder();
776 messageSB.append(MessageManager.getString(
777 "label.backupfiles_confirm_save_file_backupfiles_roll_wrong"));
778 // "Something possibly went wrong with the backups of this file."
781 if (messageSB.length() > 0)
783 messageSB.append("\n");
785 messageSB.append(MessageManager.getString(
786 "label.backupfiles_confirm_save_new_saved_file_ok"));
787 // "The new saved file seems okay."
791 if (messageSB.length() > 0)
793 messageSB.append("\n");
795 messageSB.append(MessageManager.getString(
796 "label.backupfiles_confirm_save_new_saved_file_not_ok"));
797 // "The new saved file might not be okay."
800 int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION
801 : JvOptionPane.showConfirmDialog(Desktop.desktop,
802 messageSB.toString(),
803 MessageManager.getString(
804 "label.backupfiles_confirm_save_file"),
805 // "Confirm save file"
806 JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
807 okay = confirmButton == JvOptionPane.OK_OPTION;
817 public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
818 String fileName, String suffix, int digits)
820 File[] backupFiles = null;
822 File file = new File(fileName);
827 dirFile = file.getParentFile();
828 } catch (Exception e)
831 "Could not get canonical path for file '" + file + "'");
832 return new TreeMap<>();
835 String filename = file.getName();
836 String basename = filename;
838 // find existing backup files
839 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
841 backupFiles = dirFile.listFiles(bff); // is clone needed?
843 // sort the backup files (based on integer found in the suffix) using a
844 // precomputed Hashmap for speed
845 Map<Integer, File> bfHashMap = new HashMap<>();
846 for (int i = 0; i < backupFiles.length; i++)
848 File f = backupFiles[i];
849 BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
851 bfHashMap.put(bfp.indexNum(), f);
853 TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
854 bfTreeMap.putAll(bfHashMap);
860 private boolean addDeleteFile(File fileToBeDeleted, File originalFile,
861 boolean delete, boolean newer)
863 return addDeleteFile(fileToBeDeleted, originalFile, null, delete, newer);
866 private boolean addDeleteFile(File fileToBeDeleted)
869 int pos = deleteFiles.indexOf(fileToBeDeleted);
872 Cache.log.debug("BACKUPFILES not adding file "
873 + fileToBeDeleted.getAbsolutePath()
874 + " to the delete list (already at index" + pos + ")");
879 Cache.log.debug("BACKUPFILES adding file "
880 + fileToBeDeleted.getAbsolutePath() + " to the delete list");
881 deleteFiles.add(fileToBeDeleted);
886 public static boolean moveFileToFile(File oldFile, File newFile)
889 Path oldPath = Paths.get(oldFile.getAbsolutePath());
890 Path newPath = Paths.get(newFile.getAbsolutePath());
893 // delete destination file - not usually necessary but Just In Case...
894 Cache.log.debug("BACKUPFILES deleting " + newFile.getAbsolutePath());
896 Cache.log.debug("BACKUPFILES moving " + oldFile.getAbsolutePath()
897 + " to " + newFile.getAbsolutePath());
898 Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
900 Cache.log.debug("BACKUPFILES move seems to have succeeded");
901 } catch (IOException e)
903 Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
904 + newPath.toString() + "'");
905 Cache.log.error(e.getMessage());
906 Cache.log.debug(e.getStackTrace());
908 } catch (Exception e)
910 Cache.log.error(e.getMessage());
911 Cache.log.debug(e.getStackTrace());