Search in sources :

Example 1 with RestoreOperationOptions

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);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 2 with RestoreOperationOptions

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);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 3 with RestoreOperationOptions

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);
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 4 with RestoreOperationOptions

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;
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) FileHistoryId(org.syncany.database.PartialFileHistory.FileHistoryId) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 5 with RestoreOperationOptions

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;
}
Also used : RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) RestoreOperationResult(org.syncany.operations.restore.RestoreOperationResult) RestoreOperation(org.syncany.operations.restore.RestoreOperation)

Aggregations

RestoreOperationOptions (org.syncany.operations.restore.RestoreOperationOptions)6 Test (org.junit.Test)4 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 TestClient (org.syncany.tests.util.TestClient)4 File (java.io.File)3 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)1 FileVersion (org.syncany.database.FileVersion)1 WatchServer (org.syncany.operations.daemon.WatchServer)1 AlreadySyncingResponse (org.syncany.operations.daemon.messages.AlreadySyncingResponse)1 GetFileFolderRequest (org.syncany.operations.daemon.messages.GetFileFolderRequest)1 GetFileHistoryFolderRequest (org.syncany.operations.daemon.messages.GetFileHistoryFolderRequest)1 GetFileHistoryFolderResponse (org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse)1 LsFolderRequest (org.syncany.operations.daemon.messages.LsFolderRequest)1 LsFolderResponse (org.syncany.operations.daemon.messages.LsFolderResponse)1 RestoreFolderRequest (org.syncany.operations.daemon.messages.RestoreFolderRequest)1 RestoreFolderResponse (org.syncany.operations.daemon.messages.RestoreFolderResponse)1 StatusFolderRequest (org.syncany.operations.daemon.messages.StatusFolderRequest)1