Search in sources :

Example 1 with CleanupOperationResult

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());
    }
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult)

Example 2 with CleanupOperationResult

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;
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) CleanupOperation(org.syncany.operations.cleanup.CleanupOperation)

Example 3 with CleanupOperationResult

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();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Example 4 with CleanupOperationResult

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();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) TimeUnit(org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit) Test(org.junit.Test)

Example 5 with CleanupOperationResult

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();
}
Also used : CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) CleanupOperationOptions(org.syncany.operations.cleanup.CleanupOperationOptions) Test(org.junit.Test)

Aggregations

CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)17 Test (org.junit.Test)14 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)14 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)14 TestClient (org.syncany.tests.util.TestClient)14 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)8 File (java.io.File)5 FilenameFilter (java.io.FilenameFilter)3 TimeUnit (org.syncany.operations.cleanup.CleanupOperationOptions.TimeUnit)3 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)3 UpOperationResult (org.syncany.operations.up.UpOperationResult)3 ActionRemoteFile (org.syncany.plugins.transfer.files.ActionRemoteFile)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)3 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)3 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)3 TempRemoteFile (org.syncany.plugins.transfer.files.TempRemoteFile)3 TransactionRemoteFile (org.syncany.plugins.transfer.files.TransactionRemoteFile)3 CleanupOperation (org.syncany.operations.cleanup.CleanupOperation)2 DownOperationResult (org.syncany.operations.down.DownOperationResult)2 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)2