void commitTempFile(File temp) throws ConfigurationPersistenceException { if (!doneBootup.get()) { return; } if (persistOriginal) { FilePersistenceUtils.moveTempFileToMain(temp, mainFile); } else { FilePersistenceUtils.moveTempFileToMain(temp, lastFile); } }
private void moveFile(final File file, final File backup) throws IOException { if (backup.exists()) { backup.delete(); } FilePersistenceUtils.rename(file, backup); }
String snapshot() throws ConfigurationPersistenceException { String name = getTimeStamp(new Date()) + mainFileName; File snapshot = new File(snapshotsDirectory, name); try { FilePersistenceUtils.copyFile(mainFile, snapshot); } catch (IOException e) { throw MESSAGES.failedToTakeSnapshot(e, mainFile, snapshot); } return snapshot.toString(); }
void fileWritten() throws ConfigurationPersistenceException { if (!doneBootup.get() || !persistOriginal) { return; } try { FilePersistenceUtils.copyFile(mainFile, lastFile); } catch (IOException e) { throw MESSAGES.failedToBackup(e, mainFile); } }
void successfulBoot() throws ConfigurationPersistenceException { synchronized (this) { if (doneBootup.get()) { return; } final File copySource; if (persistOriginal) { copySource = mainFile; } else { copySource = new File(mainFile.getParentFile(), mainFile.getName() + ".boot"); FilePersistenceUtils.deleteFile(copySource); } try { if (!bootFile.equals(copySource)) { FilePersistenceUtils.copyFile(bootFile, copySource); } createHistoryDirectory(); final File historyBase = new File(historyRoot, mainFile.getName()); lastFile = addSuffixToFile(historyBase, LAST); final File boot = addSuffixToFile(historyBase, BOOT); final File initial = addSuffixToFile(historyBase, INITIAL); if (!initial.exists()) { FilePersistenceUtils.copyFile(copySource, initial); } FilePersistenceUtils.copyFile(copySource, lastFile); FilePersistenceUtils.copyFile(copySource, boot); } catch (IOException e) { throw MESSAGES.failedToCreateConfigurationBackup(e, bootFile); } finally { if (!persistOriginal) { // Delete the temporary file try { FilePersistenceUtils.deleteFile(copySource); } catch (Exception ignore) { } } } doneBootup.set(true); } }