Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Merging develop into feature/atomic-operations
Browse files Browse the repository at this point in the history
  • Loading branch information
pimotte committed Aug 16, 2014
1 parent 23b0d14 commit 8d28191
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions syncany-cli/src/main/java/org/syncany/cli/CleanupCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ private void printResults(CleanupOperationResult operationResult) {
case NOK_DIRTY_LOCAL:
out.println("Cannot cleanup database if local repository is in a dirty state; Call 'up' first.");
break;

case NOK_RECENTLY_CLEANED:
out.println("Cleanup has been done recently, so it is not necessary. If you are sure it is necessary, override with --force.");

case NOK_LOCAL_CHANGES:
out.println("Local changes detected. Please call 'up' first'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ private CleanupResultCode checkPreconditions() throws Exception {
if (hasDirtyDatabaseVersions()) {
return CleanupResultCode.NOK_DIRTY_LOCAL;
}

if (!options.isForce() && wasCleanedRecently()) {
return CleanupResultCode.NOK_RECENTLY_CLEANED;
}

if (hasLocalChanges()) {
return CleanupResultCode.NOK_LOCAL_CHANGES;
Expand All @@ -180,6 +184,8 @@ private CleanupResultCode checkPreconditions() throws Exception {
if (hasRemoteChanges()) {
return CleanupResultCode.NOK_REMOTE_CHANGES;
}



if (otherRemoteOperationsRunning(CleanupOperation.ACTION_ID, UpOperation.ACTION_ID, DownOperation.ACTION_ID)) {
return CleanupResultCode.NOK_OTHER_OPERATIONS_RUNNING;
Expand Down Expand Up @@ -314,16 +320,12 @@ private boolean hasRemoteChanges() throws Exception {
LsRemoteOperationResult lsRemoteOperationResult = new LsRemoteOperation(config).execute();
return lsRemoteOperationResult.getUnknownRemoteDatabases().size() > 0;
}

private boolean wasCleanedRecently() {
return getLastTimeCleaned() + options.getMinSecondsBetweenCleanups() > System.currentTimeMillis()/1000;
}

private void mergeRemoteFiles() throws IOException, StorageException {
boolean cleanedRecently = getLastTimeCleaned() + options.getMinSecondsBetweenCleanups() > System.currentTimeMillis()/1000;

if (!options.isForce() && cleanedRecently) {
logger.log(Level.INFO, "- Merge remote files: Not necessary, has been done recently");

return;
}

// Retrieve all database versions
Map<String, List<DatabaseRemoteFile>> allDatabaseFilesMap = retrieveAllRemoteDatabaseFiles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class CleanupOperationResult implements OperationResult {
public enum CleanupResultCode {
OK, OK_NOTHING_DONE, NOK_REMOTE_CHANGES, NOK_LOCAL_CHANGES, NOK_DIRTY_LOCAL, NOK_ERROR, NOK_OTHER_OPERATIONS_RUNNING
OK, OK_NOTHING_DONE, NOK_REMOTE_CHANGES, NOK_RECENTLY_CLEANED, NOK_LOCAL_CHANGES, NOK_DIRTY_LOCAL, NOK_ERROR, NOK_OTHER_OPERATIONS_RUNNING
}

private CleanupResultCode resultCode = CleanupResultCode.OK_NOTHING_DONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public void testQuickDoubleCleanup() throws Exception {

// Because of minimum timeout, this cleanup should not do anything
cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK_NOTHING_DONE, cleanupOperationResult.getResultCode());
assertEquals(CleanupResultCode.NOK_RECENTLY_CLEANED, cleanupOperationResult.getResultCode());

// When force is on, the cleanup should go through
options.setForce(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.syncany.database.dao.FileVersionSqlDao;
import org.syncany.database.dao.MultiChunkSqlDao;
import org.syncany.operations.ChangeSet;
import org.syncany.operations.cleanup.CleanupOperationOptions;
import org.syncany.operations.status.StatusOperationOptions;
import org.syncany.operations.status.StatusOperationResult;
import org.syncany.operations.up.UpOperationOptions;
Expand Down Expand Up @@ -133,6 +134,9 @@ public void testDirtyCleanupDirty() throws Exception {
UpOperationOptions upOptionsForceEnabled = new UpOperationOptions();
upOptionsForceEnabled.setStatusOptions(statusOptions);
upOptionsForceEnabled.setForceUploadEnabled(true);

CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
cleanupOptions.setMinSecondsBetweenCleanups(0);

// Run

Expand Down Expand Up @@ -259,7 +263,7 @@ public void testDirtyCleanupDirty() throws Exception {
numberOfDatabaseVersions++;

if (i % cleanupEveryXUps == 0) {
clientA.cleanup();
clientA.cleanup(cleanupOptions);
numberOfDatabaseVersions++;

assertEquals(""+numberOfDatabaseVersions, TestSqlUtil.runSqlSelect("select count(*) from databaseversion where status<>'DIRTY'", databaseConnectionA));
Expand All @@ -269,7 +273,7 @@ public void testDirtyCleanupDirty() throws Exception {
}
}

clientA.cleanup();
clientA.cleanup(cleanupOptions);

clientB.down();
clientC.down();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.syncany.operations.cleanup.CleanupOperationOptions;
import org.syncany.plugins.transfer.TransferSettings;
import org.syncany.tests.util.TestClient;
import org.syncany.tests.util.TestConfigUtil;
Expand All @@ -36,6 +37,9 @@ public void testChangeAttributes() throws Exception {
java.sql.Connection databaseConnectionA = clientA.getConfig().createDatabaseConnection();

TestClient clientB = new TestClient("B", testConnection);

CleanupOperationOptions cleanupOptions = new CleanupOperationOptions();
cleanupOptions.setMinSecondsBetweenCleanups(0);

// Scenario, see
// https://github.com/syncany/syncany/issues/143#issuecomment-50964685
Expand All @@ -53,7 +57,7 @@ public void testChangeAttributes() throws Exception {
clientA.upWithForceChecksum();
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

clientA.cleanup(); // Creates PURGE database version with deleted file
clientA.cleanup(cleanupOptions); // Creates PURGE database version with deleted file
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

TestFileUtil.copyFile(clientA.getLocalFile("file1.jpg"), clientA.getLocalFile("file1 (copy).jpg"));
Expand All @@ -64,7 +68,7 @@ public void testChangeAttributes() throws Exception {
clientA.upWithForceChecksum();
assertEquals("6", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

clientA.cleanup(); // Creates PURGE database version with deleted file
clientA.cleanup(cleanupOptions); // Creates PURGE database version with deleted file
assertEquals("7", TestSqlUtil.runSqlSelect("select count(*) from databaseversion", databaseConnectionA));

clientB.down(); // <<<< This creates the exception in #143
Expand Down

0 comments on commit 8d28191

Please sign in to comment.