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.bin.Console;
37 import jalview.gui.Desktop;
38 import jalview.gui.JvOptionPane;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
43 * BackupFiles used for manipulating (naming rolling/deleting) backup/version files when an alignment or project file is saved.
44 * User configurable options are:
45 * BACKUPFILES_ENABLED - boolean flag as to whether to use this mechanism or act as before, including overwriting files as saved.
46 * The rest of the options are now saved as BACKUPFILES_PRESET, BACKUPFILES_SAVED and BACKUPFILES_CUSTOM
47 * (see BackupFilesPresetEntry)
50 public class BackupFiles
53 // labels for saved params in Cache and .jalview_properties
54 public static final String NS = "BACKUPFILES";
56 public static final String ENABLED = NS + "_ENABLED";
58 public static final String NUM_PLACEHOLDER = "%n";
60 private static final String DEFAULT_TEMP_FILE = "jalview_temp_file_" + NS;
62 private static final String TEMP_FILE_EXT = ".tmp";
64 // file - File object to be backed up and then updated (written over)
67 // enabled - default flag as to whether to do the backup file roll (if not
68 // defined in preferences)
69 private static boolean enabled;
71 // confirmDelete - default flag as to whether to confirm with the user before
72 // deleting old backup/version files
73 private static boolean confirmDelete;
75 // defaultSuffix - default template to use to append to basename of file
76 private String suffix;
78 // noMax - flag to turn off a maximum number of files
79 private boolean noMax;
81 // defaultMax - default max number of backup files
84 // defaultDigits - number of zero-led digits to use in the filename
87 // reverseOrder - set to true to make newest (latest) files lowest number
88 // (like rolled log files)
89 private boolean reverseOrder;
91 // temp saved file to become new saved file
92 private File tempFile;
94 // flag set to see if file save to temp file was successful
95 private boolean tempFileWriteSuccess;
97 // array of files to be deleted, with extra information
98 private ArrayList<File> deleteFiles = new ArrayList<>();
100 // date formatting for modification times
101 private static final SimpleDateFormat sdf = new SimpleDateFormat(
102 "yyyy-MM-dd HH:mm:ss");
104 private static final String newTempFileSuffix = "_newfile";
106 private static final String oldTempFileSuffix = "_oldfile_tobedeleted";
108 public BackupFiles(String filename)
110 this(new File(filename));
113 // first time defaults for SUFFIX, NO_MAX, ROLL_MAX, SUFFIX_DIGITS and
115 public BackupFiles(File file)
119 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
120 .getSavedBackupEntry();
121 this.suffix = bfpe.suffix;
122 this.noMax = bfpe.keepAll;
123 this.max = bfpe.rollMax;
124 this.digits = bfpe.digits;
125 this.reverseOrder = bfpe.reverse;
127 // create a temp file to save new data in
133 String tempfilename = file.getName();
134 File tempdir = file.getParentFile();
136 "BACKUPFILES [file!=null] attempting to create temp file for "
137 + tempfilename + " in dir " + tempdir);
138 temp = File.createTempFile(tempfilename,
139 TEMP_FILE_EXT + newTempFileSuffix, tempdir);
141 "BACKUPFILES using temp file " + temp.getAbsolutePath());
146 "BACKUPFILES [file==null] attempting to create default temp file "
147 + DEFAULT_TEMP_FILE + " with extension "
149 temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
151 } catch (IOException e)
153 Console.error("Could not create temp file to save to (IOException)");
154 Console.error(e.getMessage());
155 Console.debug(Cache.getStackTraceString(e));
156 } catch (Exception e)
158 Console.error("Exception creating temp file for saving");
159 Console.debug(Cache.getStackTraceString(e));
161 this.setTempFile(temp);
164 public static void classInit()
166 Console.initLogger();
167 Console.trace("BACKUPFILES classInit");
168 boolean e = Cache.getDefault(ENABLED, !Platform.isJS());
170 Console.trace("BACKUPFILES " + (e ? "enabled" : "disabled"));
171 BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
172 .getSavedBackupEntry();
173 Console.trace("BACKUPFILES preset scheme " + bfpe.toString());
174 setConfirmDelete(bfpe.confirmDelete);
175 Console.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)
219 Console.error("IOException when getting Canonical Path of temp file '"
220 + this.getTempFile().getName() + "'");
221 Console.debug(Cache.getStackTraceString(e));
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 Console.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 Console.trace("BACKUPFILES rollBackupFiles starting");
271 dirFile = file.getParentFile();
272 dir = dirFile.getCanonicalPath();
273 Console.trace("BACKUPFILES dir: " + dir);
274 } catch (Exception e)
276 Console.error("Could not get canonical path for file '" + file + "'");
277 Console.error(e.getMessage());
278 Console.debug(Cache.getStackTraceString(e));
281 String filename = file.getName();
282 String basename = filename;
284 Console.trace("BACKUPFILES filename is " + filename);
286 // Create/move backups up one
290 // find existing backup files
291 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
293 File[] backupFiles = dirFile.listFiles(bff);
294 int nextIndexNum = 0;
296 Console.trace("BACKUPFILES backupFiles.length: " + backupFiles.length);
297 if (backupFiles.length == 0)
299 // No other backup files. Just need to move existing file to backupfile_1
301 "BACKUPFILES no existing backup files, setting index to 1");
306 TreeMap<Integer, File> bfTreeMap = sortBackupFilesAsTreeMap(
307 backupFiles, basename);
308 // bfTreeMap now a sorted list of <Integer index>,<File backupfile>
313 // backup style numbering
314 Console.trace("BACKUPFILES rolling files in reverse order");
316 int tempMax = noMax ? -1 : max;
317 // noMax == true means no limits
318 // look for first "gap" in backupFiles
319 // if tempMax is -1 at this stage just keep going until there's a gap,
320 // then hopefully tempMax gets set to the right index (a positive
321 // integer so the loop breaks)...
322 // why do I feel a little uneasy about this loop?..
323 for (int i = 1; tempMax < 0 || i <= max; i++)
325 if (!bfTreeMap.containsKey(i)) // first index without existent
332 File previousFile = null;
333 File fileToBeDeleted = null;
334 for (int n = tempMax; n > 0; n--)
336 String backupfilename = dir + File.separatorChar
337 + BackupFilenameParts.getBackupFilename(n, basename,
339 File backupfile_n = new File(backupfilename);
341 if (!backupfile_n.exists())
343 // no "oldest" file to delete
344 previousFile = backupfile_n;
345 fileToBeDeleted = null;
346 Console.trace("BACKUPFILES No oldest file to delete");
350 // check the modification time of this (backupfile_n) and the previous
351 // file (fileToBeDeleted) if the previous file is going to be deleted
352 if (fileToBeDeleted != null)
354 File replacementFile = backupfile_n;
355 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
356 long replacementFileLMT = replacementFile.lastModified();
357 Console.trace("BACKUPFILES fileToBeDeleted is "
358 + fileToBeDeleted.getAbsolutePath());
359 Console.trace("BACKUPFILES replacementFile is "
360 + backupfile_n.getAbsolutePath());
364 File oldestTempFile = nextTempFile(fileToBeDeleted.getName(),
367 if (fileToBeDeletedLMT > replacementFileLMT)
369 String fileToBeDeletedLMTString = sdf
370 .format(fileToBeDeletedLMT);
371 String replacementFileLMTString = sdf
372 .format(replacementFileLMT);
373 Console.warn("WARNING! I am set to delete backupfile "
374 + fileToBeDeleted.getName()
375 + " has modification time "
376 + fileToBeDeletedLMTString
377 + " which is newer than its replacement "
378 + replacementFile.getName()
379 + " with modification time "
380 + replacementFileLMTString);
382 boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
383 replacementFile, true);
384 Console.trace("BACKUPFILES " + (delete ? "confirmed" : "not")
386 + fileToBeDeleted.getAbsolutePath()
387 + " which is newer than "
388 + replacementFile.getAbsolutePath());
392 // User has confirmed delete -- no need to add it to the list
393 fileToBeDeleted.delete();
397 Console.debug("BACKUPFILES moving "
398 + fileToBeDeleted.getAbsolutePath() + " to "
399 + oldestTempFile.getAbsolutePath());
400 moveFileToFile(fileToBeDeleted, oldestTempFile);
405 Console.debug("BACKUPFILES going to move "
406 + fileToBeDeleted.getAbsolutePath() + " to "
407 + oldestTempFile.getAbsolutePath());
408 moveFileToFile(fileToBeDeleted, oldestTempFile);
409 addDeleteFile(oldestTempFile);
412 } catch (Exception e)
415 "Error occurred, probably making new temp file for '"
416 + fileToBeDeleted.getName() + "'");
417 Console.error(Cache.getStackTraceString(e));
421 fileToBeDeleted = null;
424 if (!noMax && n == tempMax && backupfile_n.exists())
426 fileToBeDeleted = backupfile_n;
430 if (previousFile != null)
432 // using boolean '&' instead of '&&' as don't want moveFileToFile
433 // attempt to be conditional (short-circuit)
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 Console.trace("BACKUPFILES backupFiles: " + bfsb.toString());
461 // noMax == true means keep all backup files
462 if ((!noMax) && bfTreeMap.size() >= max)
464 Console.trace("BACKUPFILES noMax: " + noMax + ", " + "max: " + max
465 + ", " + "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 Console.trace("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;
487 Console.trace("BACKUPFILES fileToBeDeleted: " + fileToBeDeleted);
489 boolean newer = false;
490 if (replacementFile != null)
492 long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
493 long replacementFileLMT = replacementFile != null
494 ? replacementFile.lastModified()
496 if (fileToBeDeletedLMT > replacementFileLMT)
498 String fileToBeDeletedLMTString = sdf
499 .format(fileToBeDeletedLMT);
500 String replacementFileLMTString = sdf
501 .format(replacementFileLMT);
503 Console.warn("WARNING! I am set to delete backupfile '"
504 + fileToBeDeleted.getName()
505 + "' has modification time "
506 + fileToBeDeletedLMTString
507 + " which is newer than the oldest backupfile being kept '"
508 + replacementFile.getName()
509 + "' with modification time "
510 + replacementFileLMTString);
512 delete = confirmNewerDeleteFile(fileToBeDeleted,
513 replacementFile, false);
516 // User has confirmed delete -- no need to add it to the list
517 fileToBeDeleted.delete();
518 Console.debug("BACKUPFILES deleting fileToBeDeleted: "
524 // keeping file, nothing to do!
525 Console.debug("BACKUPFILES keeping fileToBeDeleted: "
532 addDeleteFile(fileToBeDeleted);
533 Console.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
541 nextIndexNum = bfTreeMap.lastKey() + 1;
545 // Let's make the new backup file!! yay, got there at last!
546 String latestBackupFilename = dir + File.separatorChar
547 + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
549 Console.trace("BACKUPFILES Moving old file [" + file
550 + "] to latestBackupFilename [" + latestBackupFilename + "]");
551 // using boolean '&' instead of '&&' as don't want moveFileToFile attempt to
552 // be conditional (short-circuit)
553 ret = ret & moveFileToFile(file, new File(latestBackupFilename));
554 Console.debug("BACKUPFILES moving " + file + " to " + latestBackupFilename
555 + " was " + (ret ? "" : "NOT ") + "successful");
558 Console.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);
724 Console.trace("BACKUPFILES about to delete fileToDelete:"
726 fileToDelete.delete();
727 Console.warn("deleted '" + 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."
799 if (messageSB.length() > 0)
801 messageSB.append("\n");
804 .append(MessageManager.getString("label.continue_operation"));
806 int confirmButton = Platform.isHeadless() ? JvOptionPane.OK_OPTION
807 : JvOptionPane.showConfirmDialog(Desktop.desktop,
808 messageSB.toString(),
809 MessageManager.getString(
810 "label.backupfiles_confirm_save_file"),
811 // "Confirm save file"
812 JvOptionPane.OK_OPTION, JvOptionPane.WARNING_MESSAGE);
813 okay = confirmButton == JvOptionPane.OK_OPTION;
823 public static TreeMap<Integer, File> getBackupFilesAsTreeMap(
824 String fileName, String suffix, int digits)
826 File[] backupFiles = null;
828 File file = new File(fileName);
833 dirFile = file.getParentFile();
834 } catch (Exception e)
836 Console.error("Could not get canonical path for file '" + file + "'");
837 return new TreeMap<>();
840 String filename = file.getName();
841 String basename = filename;
843 // find existing backup files
844 BackupFilenameFilter bff = new BackupFilenameFilter(basename, suffix,
846 backupFiles = dirFile.listFiles(bff); // is clone needed?
848 // sort the backup files (based on integer found in the suffix) using a
849 // precomputed Hashmap for speed
850 Map<Integer, File> bfHashMap = new HashMap<>();
851 for (int i = 0; i < backupFiles.length; i++)
853 File f = backupFiles[i];
854 BackupFilenameParts bfp = new BackupFilenameParts(f, basename, suffix,
856 bfHashMap.put(bfp.indexNum(), f);
858 TreeMap<Integer, File> bfTreeMap = new TreeMap<>();
859 bfTreeMap.putAll(bfHashMap);
865 private boolean addDeleteFile(File fileToBeDeleted, File originalFile,
866 boolean delete, boolean newer)
868 return addDeleteFile(fileToBeDeleted, originalFile, null, delete, newer);
871 private boolean addDeleteFile(File fileToBeDeleted)
874 int pos = deleteFiles.indexOf(fileToBeDeleted);
877 Console.debug("BACKUPFILES not adding file "
878 + fileToBeDeleted.getAbsolutePath()
879 + " to the delete list (already at index" + pos + ")");
884 Console.debug("BACKUPFILES adding file "
885 + fileToBeDeleted.getAbsolutePath() + " to the delete list");
886 deleteFiles.add(fileToBeDeleted);
891 public static boolean moveFileToFile(File oldFile, File newFile)
893 Console.initLogger();
895 Path oldPath = Paths.get(oldFile.getAbsolutePath());
896 Path newPath = Paths.get(newFile.getAbsolutePath());
899 // delete destination file - not usually necessary but Just In Case...
900 Console.trace("BACKUPFILES deleting " + newFile.getAbsolutePath());
902 Console.trace("BACKUPFILES moving " + oldFile.getAbsolutePath() + " to "
903 + newFile.getAbsolutePath());
904 Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
906 Console.trace("BACKUPFILES move seems to have succeeded");
907 } catch (IOException e)
909 Console.warn("Could not move file '" + oldPath.toString() + "' to '"
910 + newPath.toString() + "'");
911 Console.error(e.getMessage());
912 Console.debug(Cache.getStackTraceString(e));
914 } catch (Exception e)
916 Console.error(e.getMessage());
917 Console.debug(Cache.getStackTraceString(e));