use of org.syncany.operations.cleanup.CleanupOperationOptions in project syncany by syncany.
the class CleanupCommand method parseOptions.
@Override
public CleanupOperationOptions parseOptions(String[] operationArgs) throws Exception {
CleanupOperationOptions operationOptions = new CleanupOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Void> optionForce = parser.acceptsAll(asList("f", "force"));
OptionSpec<Void> optionNoOlderVersionRemoval = parser.acceptsAll(asList("O", "no-delete-older-than"));
OptionSpec<Void> optionNoVersionRemovalByInterval = parser.acceptsAll(asList("I", "no-delete-interval"));
OptionSpec<Void> optionNoRemoveTempFiles = parser.acceptsAll(asList("T", "no-temp-removal"));
OptionSpec<String> optionKeepMinTime = parser.acceptsAll(asList("o", "delete-older-than")).withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(operationArgs);
// -F, --force
operationOptions.setForce(options.has(optionForce));
// -V, --no-version-removal
operationOptions.setRemoveOldVersions(!options.has(optionNoOlderVersionRemoval));
// -T, --no-temp-removal
operationOptions.setRemoveUnreferencedTemporaryFiles(!options.has(optionNoRemoveTempFiles));
// -I, --no-delete-interval
operationOptions.setRemoveVersionsByInterval(!options.has(optionNoVersionRemovalByInterval));
// -o=<time>, --delete-older-than=<time>
if (options.has(optionKeepMinTime)) {
long keepDeletedFilesForSeconds = CommandLineUtil.parseTimePeriod(options.valueOf(optionKeepMinTime));
if (keepDeletedFilesForSeconds < 0) {
throw new Exception("Invalid value for --delete-older-than==" + keepDeletedFilesForSeconds + "; must be >= 0");
}
operationOptions.setMinKeepSeconds(keepDeletedFilesForSeconds);
}
// Parse 'status' options
operationOptions.setStatusOptions(parseStatusOptions(operationArgs));
return operationOptions;
}
use of org.syncany.operations.cleanup.CleanupOperationOptions 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.CleanupOperationOptions 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.CleanupOperationOptions in project syncany by syncany.
the class ManySyncUpsAndDatabaseFileCleanupScenarioTest method testManySyncUpsAndDatabaseFileCleanup.
@Test
public void testManySyncUpsAndDatabaseFileCleanup() throws Exception {
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
// ROUND 1: many sync up (no cleanup expected here)
for (int i = 1; i <= 15; i++) {
clientA.createNewFile("file" + i, 1);
clientA.up();
}
for (int i = 1; i <= 15; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 2: 1x sync up (cleanup expected!)
clientA.createNewFile("file16", 1);
clientA.up();
// Force cleanup
clientA.cleanup();
for (int i = 1; i <= 15; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 17; i <= 17; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 3: many sync up (no cleanup expected here)
for (int i = 17; i <= 30; i++) {
clientA.createNewFile("file" + i, 1);
clientA.up();
}
for (int i = 1; i <= 16; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 17; i <= 31; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// ROUND 4: 1x sync up (cleanup expected!)
clientA.createNewFile("file31", 1);
clientA.up();
CleanupOperationOptions options = new CleanupOperationOptions();
options.setForce(true);
// Force cleanup
clientA.cleanup(options);
for (int i = 1; i <= 32; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file should NOT exist: " + expectedDatabaseFile, !expectedDatabaseFile.exists());
}
for (int i = 33; i <= 33; i++) {
DatabaseRemoteFile expectedDatabaseRemoteFile = new DatabaseRemoteFile("A", i);
File expectedDatabaseFile = new File(testConnection.getPath() + "/databases/" + expectedDatabaseRemoteFile.getName());
assertTrue("Database file SHOULD exist: " + expectedDatabaseFile, expectedDatabaseFile.exists());
}
// Tear down
TestClient clientB = new TestClient("B", testConnection);
clientB.down();
assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.operations.cleanup.CleanupOperationOptions in project syncany by syncany.
the class Issue288ScenarioTest method testIssue288.
@Test
public void testIssue288() throws Exception {
/*
* This tests issue #288, an issue in which a file with duplicate chunks are created
* incorrectly, because the cleanup throws away too many entries in the filecontent_chunks
* database table.
*
* The test first creates a file with duplicate chunks, then syncs this file, and then
* moves this file on both clients -- that forces the other client to recreate the file
* from scratch.
*/
// Setup
LocalTransferSettings testConnection = (LocalTransferSettings) TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
java.sql.Connection databaseConnectionB = DatabaseConnectionFactory.createConnection(clientB.getDatabaseFile(), false);
CleanupOperationOptions cleanupOptionsKeepOne = new CleanupOperationOptions();
cleanupOptionsKeepOne.setForce(true);
// Create file content with two duplicate chunks
// The file has 4 chunks (4 * 512 bytes), the middle chunks are identical
// 1 MB
byte[] fileContentA = new byte[2 * 1024 * 1024];
for (int i = 0; i < 512 * 1024; i++) {
// First chunk
fileContentA[i] = (byte) i;
}
for (int i = 512 * 1024; i < 1536 * 1024; i++) {
// Two identical middle chunks
fileContentA[i] = 99;
}
for (int i = 1536 * 1024; i < 2 * 1024 * 1024; i++) {
// Last chunk
fileContentA[i] = (byte) (i + i);
}
FileUtils.writeByteArrayToFile(clientA.getLocalFile("fileA"), fileContentA);
clientA.upWithForceChecksum();
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionA));
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionA));
// Sync file to client B
clientB.down();
assertEquals("3", TestSqlUtil.runSqlSelect("select count(*) from chunk", databaseConnectionB));
assertEquals("4", TestSqlUtil.runSqlSelect("select count(*) from filecontent_chunk", databaseConnectionB));
// Move file, sync again and perform cleanup (wipe everything but one file version)
clientA.moveFile("fileA", "fileA-moved");
clientA.upWithForceChecksum();
clientA.cleanup(cleanupOptionsKeepOne);
// Delete file locally and sync down
clientB.deleteFile("fileA");
// <<<< This throws an exception!
clientB.down();
// Tear down
clientB.deleteTestData();
clientA.deleteTestData();
}
Aggregations