Search in sources :

Example 1 with DownOperationResult

use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.

the class RenameNoDownloadMultiChunksScenarioTest method testRenameAndCheckIfMultiChunksAreDownloaded.

@Test
public void testRenameAndCheckIfMultiChunksAreDownloaded() throws Exception {
    // Setup 
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    TestClient clientB = new TestClient("B", testConnection);
    // Run 
    // Prepare, create file at A, sync it to B
    clientA.createNewFile("A-file1");
    clientA.sync();
    clientB.sync();
    // Now move file, and sync
    clientA.moveFile("A-file1", "A-file-moved1");
    clientA.up();
    DownOperationResult downOperationResult = clientB.down();
    assertEquals("No multichunks should have been downloaded.", 0, downOperationResult.getDownloadedMultiChunks().size());
    assertTrue("Moved files should exist.", clientB.getLocalFile("A-file-moved1").exists());
    assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
    assertSqlDatabaseEquals(clientA.getDatabaseFile(), clientB.getDatabaseFile());
    // Tear down
    clientA.deleteTestData();
    clientB.deleteTestData();
}
Also used : DownOperationResult(org.syncany.operations.down.DownOperationResult) TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 2 with DownOperationResult

use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.

the class FileSystemActionReconciliatorTest method testFileSystemActionReconDeleteNonExistingFolder.

@Test
public void testFileSystemActionReconDeleteNonExistingFolder() throws Exception {
    // Setup
    TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
    TestClient clientA = new TestClient("A", testConnection);
    Config testConfigA = clientA.getConfig();
    // - Create first database version
    clientA.createNewFolder("new folder/some subfolder");
    clientA.upWithForceChecksum();
    // Delete this!
    clientA.deleteFile("new folder/some subfolder");
    // - Create new version (delete folder)
    TestSqlDatabase sqlDatabaseA = new TestSqlDatabase(testConfigA);
    PartialFileHistory folderFileHistoryWithLastVersion = sqlDatabaseA.getFileHistoryWithLastVersion("new folder/some subfolder");
    FileVersion deletedFolderVersion = folderFileHistoryWithLastVersion.getLastVersion().clone();
    deletedFolderVersion.setStatus(FileStatus.DELETED);
    deletedFolderVersion.setVersion(deletedFolderVersion.getVersion() + 1);
    PartialFileHistory deletedFolderVersionHistory = new PartialFileHistory(folderFileHistoryWithLastVersion.getFileHistoryId());
    deletedFolderVersionHistory.addFileVersion(deletedFolderVersion);
    DatabaseVersion winnersDatabaseVersion = TestDatabaseUtil.createDatabaseVersion(sqlDatabaseA.getLastDatabaseVersionHeader());
    winnersDatabaseVersion.addFileHistory(deletedFolderVersionHistory);
    // - Create memory database with this version
    MemoryDatabase winnersDatabase = new MemoryDatabase();
    winnersDatabase.addDatabaseVersion(winnersDatabaseVersion);
    // Run! Finally!
    DownOperationResult outDownOperationResult = new DownOperationResult();
    FileSystemActionReconciliator fileSystemActionReconciliator = new FileSystemActionReconciliator(testConfigA, outDownOperationResult.getChangeSet());
    List<FileSystemAction> fileSystemActions = fileSystemActionReconciliator.determineFileSystemActions(winnersDatabase);
    assertNotNull(fileSystemActions);
    assertEquals(0, fileSystemActions.size());
    // Tear down
    clientA.deleteTestData();
}
Also used : Config(org.syncany.config.Config) DownOperationResult(org.syncany.operations.down.DownOperationResult) FileSystemAction(org.syncany.operations.down.actions.FileSystemAction) TestClient(org.syncany.tests.util.TestClient) FileVersion(org.syncany.database.FileVersion) MemoryDatabase(org.syncany.database.MemoryDatabase) TestSqlDatabase(org.syncany.tests.util.TestSqlDatabase) TransferSettings(org.syncany.plugins.transfer.TransferSettings) PartialFileHistory(org.syncany.database.PartialFileHistory) DatabaseVersion(org.syncany.database.DatabaseVersion) FileSystemActionReconciliator(org.syncany.operations.down.FileSystemActionReconciliator) Test(org.junit.Test)

Example 3 with DownOperationResult

use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.

the class DownCommand method printResults.

@Override
public void printResults(OperationResult operationResult) {
    DownOperationResult concreteOperationResult = (DownOperationResult) operationResult;
    if (concreteOperationResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
        ChangeSet changeSet = concreteOperationResult.getChangeSet();
        if (changeSet.hasChanges()) {
            List<String> newFiles = new ArrayList<String>(changeSet.getNewFiles());
            List<String> changedFiles = new ArrayList<String>(changeSet.getChangedFiles());
            List<String> deletedFiles = new ArrayList<String>(changeSet.getDeletedFiles());
            Collections.sort(newFiles);
            Collections.sort(changedFiles);
            Collections.sort(deletedFiles);
            for (String newFile : newFiles) {
                out.println("A " + newFile);
            }
            for (String changedFile : changedFiles) {
                out.println("M " + changedFile);
            }
            for (String deletedFile : deletedFiles) {
                out.println("D " + deletedFile);
            }
        } else {
            out.println(concreteOperationResult.getDownloadedUnknownDatabases().size() + " database file(s) processed.");
        }
        out.println("Sync down finished.");
    } else {
        out.println("Sync down skipped, no remote changes.");
    }
}
Also used : DownOperationResult(org.syncany.operations.down.DownOperationResult) ArrayList(java.util.ArrayList) ChangeSet(org.syncany.operations.ChangeSet)

Example 4 with DownOperationResult

use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.

the class DownCommand method execute.

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

Example 5 with DownOperationResult

use of org.syncany.operations.down.DownOperationResult in project syncany by syncany.

the class WatchOperation method runSync.

/**
	 * Runs one iteration of the main synchronization loop, containing a {@link DownOperation},
	 * an {@link UpOperation} and (if required), a {@link CleanupOperation}.
	 */
private void runSync() throws Exception {
    if (!syncRunning.get()) {
        syncRunning.set(true);
        syncRequested.set(false);
        logger.log(Level.INFO, "RUNNING SYNC ...");
        fireStartEvent();
        try {
            boolean notifyChanges = false;
            // Run down
            DownOperationResult downResult = new DownOperation(config, options.getDownOptions()).execute();
            if (downResult.getResultCode() == DownResultCode.OK_WITH_REMOTE_CHANGES) {
            // TODO [low] Do something?
            }
            // Run up
            UpOperationResult upOperationResult = new UpOperation(config, options.getUpOptions()).execute();
            if (upOperationResult.getResultCode() == UpResultCode.OK_CHANGES_UPLOADED && upOperationResult.getChangeSet().hasChanges()) {
                upCount.incrementAndGet();
                notifyChanges = true;
            }
            CleanupOperationResult cleanupOperationResult = new CleanupOperation(config, options.getCleanupOptions()).execute();
            if (cleanupOperationResult.getResultCode() == CleanupResultCode.OK) {
                notifyChanges = true;
            }
            // Fire change event if up and/or cleanup
            if (notifyChanges) {
                notifyChanges();
            }
        } finally {
            logger.log(Level.INFO, "SYNC DONE.");
            syncRunning.set(false);
            fireEndEvent();
        }
    } else {
        // Can't do a log message here, because this bit is called thousand
        // of times when file system events occur.
        syncRequested.set(true);
    }
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) CleanupOperationResult(org.syncany.operations.cleanup.CleanupOperationResult) DownOperationResult(org.syncany.operations.down.DownOperationResult) DownOperation(org.syncany.operations.down.DownOperation) CleanupOperation(org.syncany.operations.cleanup.CleanupOperation) UpOperationResult(org.syncany.operations.up.UpOperationResult)

Aggregations

DownOperationResult (org.syncany.operations.down.DownOperationResult)12 Test (org.junit.Test)9 TestClient (org.syncany.tests.util.TestClient)9 File (java.io.File)6 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)6 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)5 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 TransferSettings (org.syncany.plugins.transfer.TransferSettings)4 FilenameFilter (java.io.FilenameFilter)3 ChangeSet (org.syncany.operations.ChangeSet)2 CleanupOperationResult (org.syncany.operations.cleanup.CleanupOperationResult)2 DownOperation (org.syncany.operations.down.DownOperation)2 Path (java.nio.file.Path)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Config (org.syncany.config.Config)1 DatabaseVersion (org.syncany.database.DatabaseVersion)1 FileVersion (org.syncany.database.FileVersion)1 MemoryDatabase (org.syncany.database.MemoryDatabase)1