use of org.syncany.operations.cleanup.CleanupOperationResult.CleanupResultCode in project syncany by syncany.
the class CleanupOperation method execute.
@Override
public CleanupOperationResult execute() throws Exception {
logger.log(Level.INFO, "");
logger.log(Level.INFO, "Running 'Cleanup' at client " + config.getMachineName() + " ...");
logger.log(Level.INFO, "--------------------------------------------");
// Do initial check out remote repository preconditions
CleanupResultCode preconditionResult = checkPreconditions();
fireStartEvent();
if (preconditionResult != CleanupResultCode.OK) {
fireEndEvent();
return new CleanupOperationResult(preconditionResult);
}
fireCleanupNeededEvent();
// At this point, the operation will lock the repository
startOperation();
// If other clients have unfinished transactions with deletions, do not proceed.
try {
transferManager.cleanTransactions();
} catch (BlockingTransfersException ignored) {
finishOperation();
fireEndEvent();
return new CleanupOperationResult(CleanupResultCode.NOK_REPO_BLOCKED);
}
// Wait two seconds (conservative cleanup, see #104)
logger.log(Level.INFO, "Cleanup: Waiting a while to be sure that no other actions are running ...");
Thread.sleep(BEFORE_DOUBLE_CHECK_TIME);
// Check again. No other clients should be busy, because we waited BEFORE_DOUBLE_CHECK_TIME
preconditionResult = checkPreconditions();
if (preconditionResult != CleanupResultCode.OK) {
finishOperation();
fireEndEvent();
return new CleanupOperationResult(preconditionResult);
}
// If we do cleanup, we are no longer allowed to resume a transaction
transferManager.clearResumableTransactions();
transferManager.clearPendingTransactions();
// Now do the actual work!
logger.log(Level.INFO, "Cleanup: Starting transaction.");
remoteTransaction = new RemoteTransaction(config, transferManager);
removeOldVersions();
if (options.isRemoveUnreferencedTemporaryFiles()) {
transferManager.removeUnreferencedTemporaryFiles();
}
mergeRemoteFiles();
// We went succesfully through the entire operation and checked everything. Hence we update the last cleanup time.
updateLastCleanupTime();
finishOperation();
fireEndEvent();
return updateResultCode(result);
}
Aggregations