use of org.syncany.operations.restore.RestoreOperationOptions in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedFileWithTargetFile.
@Test
public void testRestoreDeletedFileWithTargetFile() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFile("A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
File deletedFile = new File(tempDir, "A-original-DELETED");
FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
clientA.upWithForceChecksum();
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
operationOptions.setRelativeTargetPath("restored-file");
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("restored-file").exists());
assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("restored-file"))));
assertEquals(deletedFile.lastModified(), clientA.getLocalFile("restored-file").lastModified());
assertEquals(deletedFile.length(), clientA.getLocalFile("restored-file").length());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.operations.restore.RestoreOperationOptions in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedFile.
@Test
public void testRestoreDeletedFile() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFile("A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
File deletedFile = new File(tempDir, "A-original-DELETED");
FileUtils.moveFile(clientA.getLocalFile("A-original"), deletedFile);
clientA.upWithForceChecksum();
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("A-original (restored version 1)").exists());
assertEquals(StringUtil.toHex(TestFileUtil.createChecksum(deletedFile)), StringUtil.toHex(TestFileUtil.createChecksum(clientA.getLocalFile("A-original (restored version 1)"))));
assertEquals(deletedFile.lastModified(), clientA.getLocalFile("A-original (restored version 1)").lastModified());
assertEquals(deletedFile.length(), clientA.getLocalFile("A-original (restored version 1)").length());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.operations.restore.RestoreOperationOptions in project syncany by syncany.
the class RestoreFileScenarioTest method testRestoreDeletedWithSubfolders.
@Test
public void testRestoreDeletedWithSubfolders() throws Exception {
// Setup
File tempDir = TestFileUtil.createTempDirectoryInSystemTemp();
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
java.sql.Connection databaseConnectionA = DatabaseConnectionFactory.createConnection(clientA.getDatabaseFile(), false);
// A new/up
clientA.createNewFolder("folder/subfolder");
clientA.createNewFile("folder/subfolder/A-original");
clientA.upWithForceChecksum();
String originalFileHistoryStr = TestSqlUtil.runSqlSelect("select filehistory_id from fileversion where path='folder/subfolder/A-original'", databaseConnectionA);
assertNotNull(originalFileHistoryStr);
FileHistoryId originalFileHistoryId = FileHistoryId.parseFileId(originalFileHistoryStr);
// A "delete"
FileUtils.deleteDirectory(clientA.getLocalFile("folder"));
clientA.upWithForceChecksum();
assertFalse(clientA.getLocalFile("folder").exists());
// A restore
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
operationOptions.setFileHistoryId(originalFileHistoryId);
operationOptions.setFileVersion(1);
clientA.restore(operationOptions);
assertTrue(clientA.getLocalFile("folder/subfolder").exists());
assertTrue(clientA.getLocalFile("folder/subfolder/A-original (restored version 1)").exists());
// Tear down
clientA.deleteTestData();
TestFileUtil.deleteDirectory(tempDir);
}
use of org.syncany.operations.restore.RestoreOperationOptions in project syncany by syncany.
the class RestoreCommand method parseOptions.
@Override
public RestoreOperationOptions parseOptions(String[] operationArgs) throws Exception {
RestoreOperationOptions operationOptions = new RestoreOperationOptions();
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
OptionSpec<Integer> optionRevision = parser.acceptsAll(asList("r", "revision")).withRequiredArg().ofType(Integer.class);
OptionSpec<String> optionTarget = parser.acceptsAll(asList("t", "target")).withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(operationArgs);
// --revision=<n>
if (options.has(optionRevision)) {
operationOptions.setFileVersion(options.valueOf(optionRevision));
}
// --target=<file>
if (options.has(optionTarget)) {
operationOptions.setRelativeTargetPath(options.valueOf(optionTarget));
}
// <file-history-id>
List<?> nonOptionArgs = options.nonOptionArguments();
if (nonOptionArgs.size() != 1) {
throw new Exception("Invalid Syntax: File history ID must be specified.");
}
FileHistoryId restoreFileHistory = FileHistoryId.parseFileId(nonOptionArgs.get(0).toString());
operationOptions.setFileHistoryId(restoreFileHistory);
return operationOptions;
}
use of org.syncany.operations.restore.RestoreOperationOptions in project syncany by syncany.
the class RestoreCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
RestoreOperationOptions operationOptions = parseOptions(operationArgs);
RestoreOperationResult operationResult = new RestoreOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
Aggregations