use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class CleanupCommand method printResults.
@Override
public void printResults(OperationResult operationResult) {
CleanupOperationResult concreteOperationResult = (CleanupOperationResult) operationResult;
switch(concreteOperationResult.getResultCode()) {
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.");
out.println("If you are sure it is necessary, override with --force.");
break;
case NOK_LOCAL_CHANGES:
out.println("Local changes detected. Please call 'up' first'.");
break;
case NOK_REMOTE_CHANGES:
out.println("Remote changes detected or repository is locked by another user. Please call 'down' first.");
break;
case NOK_OTHER_OPERATIONS_RUNNING:
out.println("Cannot run cleanup while other clients are performing up/down/cleanup. Try again later.");
break;
case OK:
if (concreteOperationResult.getMergedDatabaseFilesCount() > 0) {
out.println(concreteOperationResult.getMergedDatabaseFilesCount() + " database files merged.");
}
if (concreteOperationResult.getRemovedMultiChunksCount() > 0) {
out.printf("%d multichunk(s) deleted on remote storage (freed %.2f MB)\n", concreteOperationResult.getRemovedMultiChunksCount(), (double) concreteOperationResult.getRemovedMultiChunksSize() / 1024 / 1024);
}
if (concreteOperationResult.getRemovedOldVersionsCount() > 0) {
out.println(concreteOperationResult.getRemovedOldVersionsCount() + " file histories shortened.");
// TODO [low] This counts only the file histories, not file versions; not very helpful!
}
out.println("Cleanup successful.");
break;
case OK_NOTHING_DONE:
out.println("Cleanup not necessary. Nothing done.");
break;
default:
throw new RuntimeException("Invalid result code: " + concreteOperationResult.getResultCode().toString());
}
}
use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class CleanupCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
CleanupOperationOptions operationOptions = parseOptions(operationArgs);
CleanupOperationResult operationResult = new CleanupOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class Issue316ScenarioTest method testIssue316CleanupThenDeleteFileButLocalFileChanged.
@Test
public void testIssue316CleanupThenDeleteFileButLocalFileChanged() throws Exception {
/*
* Same test as above, but local file has changed at client B.
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { // << 3 retries!
"rel=(5|6|7) .+download.+multichunk" }));
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
cleanupOptionsKeepOne.setMaxDatabaseFiles(1);
cleanupOptionsKeepOne.setForce(true);
clientA.createNewFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
clientB.down();
assertTrue(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// <<<<<<<<< Different from above test
clientB.changeFile("Kazam_screencast_00010.mp4");
clientA.createNewFile("SomeFileTOIncreaseTheDatabaseFileCount");
clientA.upWithForceChecksum();
CleanupOperationResult cleanupResult = clientA.cleanup(cleanupOptionsKeepOne);
assertEquals(CleanupResultCode.OK, cleanupResult.getResultCode());
clientA.deleteFile("Kazam_screencast_00010.mp4");
clientA.upWithForceChecksum();
// First 'down' of client B after the cleanup.
// This fails AFTER the local database was wiped.
boolean downFailedAtB = false;
try {
clientB.down();
} catch (Exception e) {
downFailedAtB = true;
}
assertTrue("Down operation should have failed.", downFailedAtB);
// Second 'down' of client B; This should delete the file 'Kazam_screencast_00010.mp4',
// because it matches the checksum of the 'DELETED' entry
clientB.down();
// <<<<<<<<< Different from above test
assertConflictingFileExists("Kazam_screencast_00010.mp4", clientB.getLocalFiles());
assertFalse(clientB.getLocalFile("Kazam_screencast_00010.mp4").exists());
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class CleanupOperationTest method testCleanupMaxDatabaseFiles.
@Test
public void testCleanupMaxDatabaseFiles() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setMinSecondsBetweenCleanups(0);
options.setPurgeFileVersionSettings(new TreeMap<Long, TimeUnit>());
options.setRemoveOldVersions(true);
options.setMaxDatabaseFiles(3);
// Run
// A: Create some file versions
clientA.createNewFile("file.jpg");
for (int i = 1; i <= 4; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// B: Cleanup
CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(4, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
// B: Create some file versions
clientB.createNewFile("file-B.jpg");
for (int i = 1; i <= 6; i++) {
clientB.changeFile("file-B.jpg");
clientB.upWithForceChecksum();
}
// B: Cleanup (2 clients, so 7 databases is too much)
cleanupOperationResult = clientB.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(7, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.operations.cleanup.CleanupOperationResult in project syncany by syncany.
the class CleanupOperationTest method testQuickDoubleCleanup.
@Test
public void testQuickDoubleCleanup() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
CleanupOperationOptions options = new CleanupOperationOptions();
options.setRemoveOldVersions(false);
options.setRemoveVersionsByInterval(false);
options.setMinSecondsBetweenCleanups(40000000);
// Run
// A: Create some file versions
clientA.createNewFile("file.jpg");
for (int i = 1; i <= 16; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// B: Cleanup
CleanupOperationResult cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
for (int i = 1; i <= 15; i++) {
clientA.changeFile("file.jpg");
clientA.upWithForceChecksum();
}
// Because of minimum timeout, this cleanup should not do anything
cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.NOK_RECENTLY_CLEANED, cleanupOperationResult.getResultCode());
// When force is on, the cleanup should go through
options.setForce(true);
cleanupOperationResult = clientA.cleanup(options);
assertEquals(CleanupResultCode.OK, cleanupOperationResult.getResultCode());
assertEquals(16, cleanupOperationResult.getMergedDatabaseFilesCount());
assertEquals(0, cleanupOperationResult.getRemovedMultiChunksCount());
assertEquals(0, cleanupOperationResult.getRemovedOldVersionsCount());
// Tear down
clientA.deleteTestData();
}
Aggregations