Search in sources :

Example 1 with LsOperationOptions

use of org.syncany.operations.ls.LsOperationOptions in project syncany by syncany.

the class LsCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    LsOperationOptions operationOptions = parseOptions(operationArgs);
    LsOperationResult operationResult = new LsOperation(config, operationOptions).execute();
    printResults(operationResult);
    return 0;
}
Also used : LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) LsOperationResult(org.syncany.operations.ls.LsOperationResult) LsOperation(org.syncany.operations.ls.LsOperation)

Example 2 with LsOperationOptions

use of org.syncany.operations.ls.LsOperationOptions in project syncany by syncany.

the class IdenticalFileMoveScenarioTest method testIdenticalFileMove.

@Test
public void testIdenticalFileMove() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    // Create folder structure
    clientA.createNewFolder("folder");
    clientA.createNewFolder("folder/subfolder1");
    clientA.createNewFolder("folder/subfolder2");
    // Create identical files
    clientA.createNewFile("folder/subfolder1/A-file1.jpg", 100);
    clientA.copyFile("folder/subfolder1/A-file1.jpg", "folder/subfolder2/A-file1.jpg");
    clientA.up();
    // Move the two identical files
    clientA.moveFile("folder", "moved_folder");
    clientA.up();
    // A just upped, so there should not be changes.
    assertFalse(clientA.status().getChangeSet().hasChanges());
    // Check if the file histories were based on the correct originals
    LsOperationOptions options = new LsOperationOptions();
    options.setFetchHistories(true);
    options.setPathExpression("moved_folder/subfolder1/");
    LsOperationResult lsOperationResult = clientA.ls(options);
    for (PartialFileHistory fileHistory : lsOperationResult.getFileVersions().values()) {
        assertTrue(fileHistory.getFileVersion(2).getPath().endsWith(fileHistory.getFileVersion(1).getPath()));
    }
    options.setPathExpression("moved_folder/subfolder2/");
    lsOperationResult = clientA.ls(options);
    for (PartialFileHistory fileHistory : lsOperationResult.getFileVersions().values()) {
        assertTrue(fileHistory.getFileVersion(2).getPath().endsWith(fileHistory.getFileVersion(1).getPath()));
    }
    // Tear down
    clientA.deleteTestData();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) PartialFileHistory(org.syncany.database.PartialFileHistory) LsOperationResult(org.syncany.operations.ls.LsOperationResult) Test(org.junit.Test)

Example 3 with LsOperationOptions

use of org.syncany.operations.ls.LsOperationOptions in project syncany by syncany.

the class LsCommand method parseOptions.

@Override
public LsOperationOptions parseOptions(String[] operationArgs) throws Exception {
    LsOperationOptions operationOptions = new LsOperationOptions();
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    OptionSpec<String> optionDateStr = parser.acceptsAll(asList("D", "date")).withRequiredArg();
    OptionSpec<Void> optionRecursive = parser.acceptsAll(asList("r", "recursive"));
    OptionSpec<String> optionFileTypes = parser.acceptsAll(asList("t", "types")).withRequiredArg();
    OptionSpec<Void> optionLongChecksums = parser.acceptsAll(asList("f", "full-checksums"));
    OptionSpec<Void> optionWithVersions = parser.acceptsAll(asList("V", "versions"));
    OptionSpec<Void> optionGroupedVersions = parser.acceptsAll(asList("g", "group"));
    OptionSpec<Void> optionFileHistoryId = parser.acceptsAll(asList("H", "file-history"));
    OptionSpec<Void> optionDeleted = parser.acceptsAll(asList("q", "deleted"));
    OptionSet options = parser.parse(operationArgs);
    // --date=..
    if (options.has(optionDateStr)) {
        Date logViewDate = parseDateOption(options.valueOf(optionDateStr));
        operationOptions.setDate(logViewDate);
    }
    // --recursive
    operationOptions.setRecursive(options.has(optionRecursive));
    // --types=[tds]
    if (options.has(optionFileTypes)) {
        String fileTypesStr = options.valueOf(optionFileTypes).toLowerCase();
        HashSet<FileType> fileTypes = new HashSet<>();
        if (fileTypesStr.contains("f")) {
            fileTypes.add(FileType.FILE);
        }
        if (fileTypesStr.contains("d")) {
            fileTypes.add(FileType.FOLDER);
        }
        if (fileTypesStr.contains("s")) {
            fileTypes.add(FileType.SYMLINK);
        }
        operationOptions.setFileTypes(fileTypes);
    }
    // --versions
    fetchHistories = options.has(optionWithVersions) || options.has(optionFileHistoryId);
    operationOptions.setFetchHistories(fetchHistories);
    // --file-history
    operationOptions.setFileHistoryId(options.has(optionFileHistoryId));
    // --long-checksums (display option)
    checksumLength = (options.has(optionLongChecksums)) ? CHECKSUM_LENGTH_LONG : CHECKSUM_LENGTH_SHORT;
    // --group (display option)
    groupedVersions = options.has(optionGroupedVersions);
    // --deleted
    operationOptions.setDeleted(options.has(optionDeleted));
    // <path-expr>
    List<?> nonOptionArgs = options.nonOptionArguments();
    if (nonOptionArgs.size() > 0) {
        operationOptions.setPathExpression(nonOptionArgs.get(0).toString());
    }
    return operationOptions;
}
Also used : FileType(org.syncany.database.FileVersion.FileType) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser) Date(java.util.Date) HashSet(java.util.HashSet)

Example 4 with LsOperationOptions

use of org.syncany.operations.ls.LsOperationOptions in project syncany by syncany.

the class BasicWatchServerTest method testWatchServer.

/**
	 * The WatchServerTest tests all things WatchServer.
	 * This is one single test to prevent issues with parallelism. (Occupied ports, EventBus mixups etc.)
	 */
@Test
public void testWatchServer() throws Exception {
    final TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    final TestClient clientA = new TestClient("ClientA", testConnection);
    final TestClient clientB = new TestClient("ClientB", testConnection);
    int port = 58443;
    // Load config template
    DaemonConfigTO daemonConfig = TestDaemonUtil.loadDaemonConfig("daemonTwoFoldersNoWebServer.xml");
    // Set port to prevent conflicts with default daemons
    daemonConfig.getWebServer().setBindPort(port);
    // Dynamically insert paths
    daemonConfig.getFolders().get(0).setPath(clientA.getConfig().getLocalDir().getAbsolutePath());
    daemonConfig.getFolders().get(1).setPath(clientB.getConfig().getLocalDir().getAbsolutePath());
    // Create access token (not needed in this test, but prevents errors in daemon)
    daemonConfig.setPortTO(TestDaemonUtil.createPortTO(port));
    // Create watchServer
    WatchServer watchServer = new WatchServer();
    clientA.createNewFile("file-1");
    watchServer.start(daemonConfig);
    for (int i = 0; i < 20; i++) {
        if (clientB.getLocalFile("file-1").exists()) {
            break;
        }
        Thread.sleep(1000);
    }
    assertTrue("File has not synced to clientB", clientB.getLocalFile("file-1").exists());
    assertEquals(clientA.getLocalFile("file-1").length(), clientB.getLocalFile("file-1").length());
    registerWithBus();
    // Create watchServer
    clientA.createNewFolder("folder");
    clientA.createNewFile("folder/file-2");
    // Allow server to settle
    Thread.sleep(100);
    // Repeat request until 3 files are found.
    FileVersion[] files = null;
    for (int i = 0; i < 20; i++) {
        LsFolderRequest request = new LsFolderRequest();
        LsOperationOptions lsOperationOption = new LsOperationOptions();
        request.setId(i);
        request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
        request.setOptions(lsOperationOption);
        eventBus.post(request);
        Response response = waitForResponse(i);
        if (response instanceof AlreadySyncingResponse) {
            Thread.sleep(1000);
            continue;
        }
        assertTrue(response instanceof LsFolderResponse);
        LsFolderResponse treeResponse = (LsFolderResponse) response;
        files = treeResponse.getResult().getFileList().toArray(new FileVersion[] {});
        if (files.length == 2) {
            break;
        }
        if (i == 19) {
            assertEquals(2, files.length);
        } else {
            Thread.sleep(1000);
        }
    }
    if (files[0].getName().equals("folder")) {
        files = new FileVersion[] { files[1], files[0] };
    }
    assertEquals(clientA.getLocalFile("file-1").getName(), files[0].getName());
    assertEquals(clientA.getLocalFile("file-1").length(), (long) files[0].getSize());
    assertEquals(clientA.getLocalFile("folder").getName(), files[1].getName());
    assertTrue(clientA.getLocalFile("folder").isDirectory());
    assertEquals(files[1].getType(), FileVersion.FileType.FOLDER);
    // Create GetFileHistoryRequest for the first returned file
    GetFileHistoryFolderRequest request = new GetFileHistoryFolderRequest();
    request.setId(21);
    request.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    request.setFileHistoryId(files[0].getFileHistoryId().toString());
    eventBus.post(request);
    Response response = waitForResponse(21);
    assertTrue(response instanceof GetFileHistoryFolderResponse);
    GetFileHistoryFolderResponse fileHistoryResponse = (GetFileHistoryFolderResponse) response;
    assertEquals(1, fileHistoryResponse.getFiles().size());
    assertEquals(files[0], fileHistoryResponse.getFiles().get(0));
    // Create GetFileRequest for the first returned file
    GetFileFolderRequest getFileRequest = new GetFileFolderRequest();
    getFileRequest.setId(22);
    getFileRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    getFileRequest.setFileHistoryId(files[0].getFileHistoryId().toString());
    getFileRequest.setVersion(1);
    eventBus.post(getFileRequest);
    int i = 0;
    while (internalResponse == null && i < 40) {
        Thread.sleep(100);
        i++;
    }
    assertEquals((long) files[0].getSize(), internalResponse.getTempFile().length());
    // Cli Requests
    clientA.copyFile("file-1", "file-1.bak");
    // CLI request while running.
    StatusFolderRequest statusRequest = new StatusFolderRequest();
    StatusOperationOptions statusOperationOption = new StatusOperationOptions();
    statusOperationOption.setForceChecksum(true);
    statusRequest.setId(30);
    statusRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    statusRequest.setOptions(statusOperationOption);
    // Create big file to trigger sync
    clientA.createNewFile("bigfileforlongsync", 10 * 1024 * 1024);
    // ^^ Now sync should start and we send 'status' requests
    boolean syncRunningMessageReceived = false;
    for (i = 30; i < 59; i++) {
        statusRequest.setId(i);
        eventBus.post(statusRequest);
        response = waitForResponse(i);
        if (response instanceof AlreadySyncingResponse) {
            syncRunningMessageReceived = true;
            break;
        }
        Thread.sleep(200);
    }
    assertTrue(syncRunningMessageReceived);
    // Allow daemon to sync
    Thread.sleep(10000);
    for (i = 59; i < 69; i++) {
        statusRequest.setId(i);
        eventBus.post(statusRequest);
        response = waitForResponse(i);
        if (response instanceof StatusFolderResponse) {
            break;
        }
        Thread.sleep(1000);
    }
    assertNotNull(response);
    //assertEquals("No local changes.\n", cliResponse.getOutput());
    // Restore file test
    RestoreFolderRequest restoreRequest = new RestoreFolderRequest();
    RestoreOperationOptions restoreOperationOption = new RestoreOperationOptions();
    restoreOperationOption.setFileHistoryId(files[0].getFileHistoryId());
    restoreOperationOption.setFileVersion(1);
    restoreRequest.setId(70);
    restoreRequest.setRoot(clientA.getConfig().getLocalDir().getAbsolutePath());
    restoreRequest.setOptions(restoreOperationOption);
    eventBus.post(restoreRequest);
    response = waitForResponse(70);
    assertTrue(response instanceof RestoreFolderResponse);
    RestoreFolderResponse restoreResponse = (RestoreFolderResponse) response;
    byte[] copyChecksum = FileUtil.createChecksum(clientA.getLocalFile("file-1.bak"), "SHA1");
    byte[] restoreChecksum = FileUtil.createChecksum(restoreResponse.getResult().getTargetFile(), "SHA1");
    assertArrayEquals(copyChecksum, restoreChecksum);
    watchServer.stop();
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : WatchServer(org.syncany.operations.daemon.WatchServer) RestoreOperationOptions(org.syncany.operations.restore.RestoreOperationOptions) LsFolderRequest(org.syncany.operations.daemon.messages.LsFolderRequest) GetFileHistoryFolderResponse(org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse) StatusFolderRequest(org.syncany.operations.daemon.messages.StatusFolderRequest) LsFolderResponse(org.syncany.operations.daemon.messages.LsFolderResponse) StatusFolderResponse(org.syncany.operations.daemon.messages.StatusFolderResponse) DaemonConfigTO(org.syncany.config.to.DaemonConfigTO) TransferSettings(org.syncany.plugins.transfer.TransferSettings) LsOperationOptions(org.syncany.operations.ls.LsOperationOptions) RestoreFolderRequest(org.syncany.operations.daemon.messages.RestoreFolderRequest) StatusOperationOptions(org.syncany.operations.status.StatusOperationOptions) GetFileFolderRequest(org.syncany.operations.daemon.messages.GetFileFolderRequest) RestoreFolderResponse(org.syncany.operations.daemon.messages.RestoreFolderResponse) LsFolderResponse(org.syncany.operations.daemon.messages.LsFolderResponse) GetFileHistoryFolderResponse(org.syncany.operations.daemon.messages.GetFileHistoryFolderResponse) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) StatusFolderResponse(org.syncany.operations.daemon.messages.StatusFolderResponse) Response(org.syncany.operations.daemon.messages.api.Response) AlreadySyncingResponse(org.syncany.operations.daemon.messages.AlreadySyncingResponse) TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) GetFileHistoryFolderRequest(org.syncany.operations.daemon.messages.GetFileHistoryFolderRequest) RestoreFolderResponse(org.syncany.operations.daemon.messages.RestoreFolderResponse) Test(org.junit.Test)

Aggregations

LsOperationOptions (org.syncany.operations.ls.LsOperationOptions)4 Test (org.junit.Test)2 LsOperationResult (org.syncany.operations.ls.LsOperationResult)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 TestClient (org.syncany.tests.util.TestClient)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 DaemonConfigTO (org.syncany.config.to.DaemonConfigTO)1 FileVersion (org.syncany.database.FileVersion)1 FileType (org.syncany.database.FileVersion.FileType)1 PartialFileHistory (org.syncany.database.PartialFileHistory)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