{
String tempfilename = file.getName();
File tempdir = file.getParentFile();
+ Cache.log.debug(
+ "BACKUPFILES [file!=null] attempting to create temp file "
+ + tempfilename + " in dir " + tempdir);
temp = File.createTempFile(tempfilename,
TEMP_FILE_EXT + newTempFileSuffix, tempdir);
}
else
{
+ Cache.log.debug(
+ "BACKUPFILES [file==null] attempting to create default temp file "
+ + DEFAULT_TEMP_FILE + " with extension "
+ + TEMP_FILE_EXT);
temp = File.createTempFile(DEFAULT_TEMP_FILE, TEMP_FILE_EXT);
}
} catch (IOException e)
{
- Cache.log.error(
- "Could not create temp file to save into (IOException)");
+ Cache.log
+ .error("Could not create temp file to save to (IOException)");
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
} catch (Exception e)
{
Cache.log.error("Exception ctreating temp file for saving");
+ Cache.log.debug(e.getStackTrace());
}
this.setTempFile(temp);
}
public static void classInit()
{
+ Cache.log.debug("BACKUPFILES classInit");
setEnabled(Cache.getDefault(ENABLED, true));
BackupFilesPresetEntry bfpe = BackupFilesPresetEntry
.getSavedBackupEntry();
Cache.log.error(
"IOException when getting Canonical Path of temp file '"
+ this.getTempFile().getName() + "'");
+ Cache.log.debug(e.getStackTrace());
}
return path;
}
return true;
}
+ Cache.log.debug("BACKUPFILES rollBackupFiles starting");
+
String dir = "";
File dirFile;
try
{
dirFile = file.getParentFile();
dir = dirFile.getCanonicalPath();
- Cache.log.debug("BACKUPFILES: dir: " + dir);
+ Cache.log.debug("BACKUPFILES dir: " + dir);
} catch (Exception e)
{
Cache.log.error(
"Could not get canonical path for file '" + file + "'");
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
return false;
}
String filename = file.getName();
String basename = filename;
+ Cache.log.debug("BACKUPFILES filename is " + filename);
boolean ret = true;
// Create/move backups up one
if (backupFiles.length == 0)
{
// No other backup files. Just need to move existing file to backupfile_1
+ Cache.log.debug(
+ "BACKUPFILES no existing backup files, setting index to 1");
nextIndexNum = 1;
}
else
if (reverseOrder)
{
// backup style numbering
+ Cache.log.debug("BACKUPFILES rolling files in reverse order");
int tempMax = noMax ? -1 : max;
// noMax == true means no limits
// no "oldest" file to delete
previousFile = backupfile_n;
fileToBeDeleted = null;
+ Cache.log.debug("BACKUPFILES No oldest file to delete");
continue;
}
File replacementFile = backupfile_n;
long fileToBeDeletedLMT = fileToBeDeleted.lastModified();
long replacementFileLMT = replacementFile.lastModified();
+ Cache.log.debug("BACKUPFILES fileToBeDeleted is "
+ + fileToBeDeleted.getAbsolutePath());
+ Cache.log.debug("BACKUPFILES replacementFile is "
+ + backupfile_n.getAbsolutePath());
try
{
boolean delete = confirmNewerDeleteFile(fileToBeDeleted,
replacementFile, true);
+ Cache.log.debug("BACKUPFILES "
+ + (delete ? "confirmed" : "not") + " deleting file "
+ + fileToBeDeleted.getAbsolutePath()
+ + " which is newer than "
+ + replacementFile.getAbsolutePath());
if (delete)
{
}
else
{
+ Cache.log.debug("BACKUPFILES moving "
+ + fileToBeDeleted.getAbsolutePath() + " to "
+ + oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
}
}
else
{
+ Cache.log.debug("BACKUPFILES going to move "
+ + fileToBeDeleted.getAbsolutePath() + " to "
+ + oldestTempFile.getAbsolutePath());
moveFileToFile(fileToBeDeleted, oldestTempFile);
addDeleteFile(oldestTempFile);
}
if (delete)
{
addDeleteFile(fileToBeDeleted);
- Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDelted): "
+ Cache.log.debug("BACKUPFILES addDeleteFile(fileToBeDeleted): "
+ fileToBeDeleted);
}
int pos = deleteFiles.indexOf(fileToBeDeleted);
if (pos > -1)
{
+ Cache.log.debug("BACKUPFILES not adding file "
+ + fileToBeDeleted.getAbsolutePath()
+ + " to the delete list (already at index" + pos + ")");
return true;
}
else
{
+ Cache.log.debug("BACKUPFILES adding file "
+ + fileToBeDeleted.getAbsolutePath() + " to the delete list");
deleteFiles.add(fileToBeDeleted);
}
return ret;
try
{
// delete destination file - not usually necessary but Just In Case...
+ Cache.log.debug("BACKUPFILES deleting " + newFile.getAbsolutePath());
newFile.delete();
+ Cache.log.debug("BACKUPFILES moving " + oldFile.getAbsolutePath()
+ + " to " + newFile.getAbsolutePath());
Files.move(oldPath, newPath, StandardCopyOption.REPLACE_EXISTING);
ret = true;
+ Cache.log.debug("BACKUPFILES move seemse to have succeeded");
} catch (IOException e)
{
Cache.log.warn("Could not move file '" + oldPath.toString() + "' to '"
+ newPath.toString() + "'");
- Cache.log.error(e.getStackTrace());
+ Cache.log.error(e.getMessage());
+ Cache.log.debug(e.getStackTrace());
ret = false;
} catch (Exception e)
{
Cache.log.error(e.getMessage());
- Cache.log.error(e.getStackTrace());
+ Cache.log.debug(e.getStackTrace());
ret = false;
}
return ret;