Search in sources :

Example 1 with ChangeSet

use of org.syncany.operations.ChangeSet in project syncany by syncany.

the class UpOperation method startIndexerThread.

private void startIndexerThread(BlockingQueue<DatabaseVersion> databaseVersionQueue) {
    // Get a list of files that have been updated
    ChangeSet localChanges = result.getStatusResult().getChangeSet();
    List<File> locallyUpdatedFiles = extractLocallyUpdatedFiles(localChanges);
    List<File> locallyDeletedFiles = extractLocallyDeletedFiles(localChanges);
    // Iterate over the changes, deduplicate, and feed DatabaseVersions into an iterator
    Deduper deduper = new Deduper(config.getChunker(), config.getMultiChunker(), config.getTransformer(), options.getTransactionSizeLimit(), options.getTransactionFileLimit());
    AsyncIndexer asyncIndexer = new AsyncIndexer(config, deduper, locallyUpdatedFiles, locallyDeletedFiles, databaseVersionQueue);
    new Thread(asyncIndexer, "AsyncI/" + config.getLocalDir().getName()).start();
}
Also used : Deduper(org.syncany.chunk.Deduper) ChangeSet(org.syncany.operations.ChangeSet) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) TransactionRemoteFile(org.syncany.plugins.transfer.files.TransactionRemoteFile) File(java.io.File) MultichunkRemoteFile(org.syncany.plugins.transfer.files.MultichunkRemoteFile)

Example 2 with ChangeSet

use of org.syncany.operations.ChangeSet in project syncany by syncany.

the class StatusOperation method execute.

@Override
public StatusOperationResult execute() throws Exception {
    logger.log(Level.INFO, "");
    logger.log(Level.INFO, "Running 'Status' at client " + config.getMachineName() + " ...");
    logger.log(Level.INFO, "--------------------------------------------");
    if (options != null && options.isForceChecksum()) {
        logger.log(Level.INFO, "Force checksum ENABLED.");
    }
    if (options != null && !options.isDelete()) {
        logger.log(Level.INFO, "Delete missing files DISABLED.");
    }
    // Get local database
    logger.log(Level.INFO, "Querying current file tree from database ...");
    eventBus.post(new StatusStartSyncExternalEvent(config.getLocalDir().getAbsolutePath()));
    // Path to actual file version
    final Map<String, FileVersion> filesInDatabase = localDatabase.getCurrentFileTree();
    // Find local changes
    logger.log(Level.INFO, "Analyzing local folder " + config.getLocalDir() + " ...");
    ChangeSet localChanges = findLocalChanges(filesInDatabase);
    if (!localChanges.hasChanges()) {
        logger.log(Level.INFO, "- No changes to local database");
    }
    // Return result
    StatusOperationResult statusResult = new StatusOperationResult();
    statusResult.setChangeSet(localChanges);
    eventBus.post(new StatusEndSyncExternalEvent(config.getLocalDir().getAbsolutePath(), localChanges.hasChanges()));
    return statusResult;
}
Also used : FileVersion(org.syncany.database.FileVersion) StatusEndSyncExternalEvent(org.syncany.operations.daemon.messages.StatusEndSyncExternalEvent) StatusStartSyncExternalEvent(org.syncany.operations.daemon.messages.StatusStartSyncExternalEvent) ChangeSet(org.syncany.operations.ChangeSet)

Example 3 with ChangeSet

use of org.syncany.operations.ChangeSet in project syncany by syncany.

the class UpOperation method checkPreconditions.

/**
 * This method checks if:
 *
 * <ul>
 * 	<li>If there are local changes => No need for Up.</li>
 *  <li>If another clients is running Cleanup => Not allowed to upload.</li>
 *  <li>If remote changes exist => Should Down first.</li>
 * </ul>
 *
 * @returns boolean true if Up can and should be done, false otherwise.
 */
private boolean checkPreconditions() throws Exception {
    // Find local changes
    StatusOperation statusOperation = new StatusOperation(config, options.getStatusOptions());
    StatusOperationResult statusOperationResult = statusOperation.execute();
    ChangeSet localChanges = statusOperationResult.getChangeSet();
    result.getStatusResult().setChangeSet(localChanges);
    if (!localChanges.hasChanges()) {
        logger.log(Level.INFO, "Local database is up-to-date (change set). NOTHING TO DO!");
        result.setResultCode(UpResultCode.OK_NO_CHANGES);
        return false;
    }
    // Check if other operations are running
    if (otherRemoteOperationsRunning(CleanupOperation.ACTION_ID)) {
        logger.log(Level.INFO, "* Cleanup running. Skipping down operation.");
        result.setResultCode(UpResultCode.NOK_UNKNOWN_DATABASES);
        return false;
    }
    // Find remote changes (unless --force is enabled)
    if (!options.forceUploadEnabled()) {
        LsRemoteOperationResult lsRemoteOperationResult = new LsRemoteOperation(config, transferManager).execute();
        List<DatabaseRemoteFile> unknownRemoteDatabases = lsRemoteOperationResult.getUnknownRemoteDatabases();
        if (unknownRemoteDatabases.size() > 0) {
            logger.log(Level.INFO, "There are remote changes. Call 'down' first or use --force-upload you must, Luke!");
            logger.log(Level.FINE, "Unknown remote databases are: " + unknownRemoteDatabases);
            result.setResultCode(UpResultCode.NOK_UNKNOWN_DATABASES);
            return false;
        } else {
            logger.log(Level.INFO, "No remote changes, ready to upload.");
        }
    } else {
        logger.log(Level.INFO, "Force (--force-upload) is enabled, ignoring potential remote changes.");
    }
    return true;
}
Also used : StatusOperation(org.syncany.operations.status.StatusOperation) LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) ChangeSet(org.syncany.operations.ChangeSet) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) LsRemoteOperation(org.syncany.operations.ls_remote.LsRemoteOperation)

Example 4 with ChangeSet

use of org.syncany.operations.ChangeSet in project syncany by syncany.

the class StatusOperationTest method testNotSoRecentFileModificationWithoutSizeOrModifiedDateChange.

@Test
public void testNotSoRecentFileModificationWithoutSizeOrModifiedDateChange() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    File testFile = TestFileUtil.createRandomFileInDirectory(config.getLocalDir(), 40);
    // Perform 'up', wait a second and then change test file
    // IMPORTANT: Sleep to prevent detailed checksum-based update check in 'status' operation
    new UpOperation(config).execute();
    Thread.sleep(2000);
    TestFileUtil.changeRandomPartOfBinaryFile(testFile);
    // Run 'status', this should NOT run a checksum-based file comparison
    ChangeSet changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getChangedFiles().size(), 1);
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Example 5 with ChangeSet

use of org.syncany.operations.ChangeSet in project syncany by syncany.

the class StatusOperationTest method testCreateFolderAndRunStatus.

@Test
public void testCreateFolderAndRunStatus() throws Exception {
    // Setup
    Config config = TestConfigUtil.createTestLocalConfig();
    new File(config.getLocalDir() + "/somefolder").mkdir();
    // Run 'status', this SHOULD list the folder
    ChangeSet changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 1);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    assertEquals(changeSet.getUnchangedFiles().size(), 0);
    // Run 'up' to check in the folder
    new UpOperation(config).execute();
    // Run 'status', this SHOULD NOT list the folder in the changed/new files
    changeSet = (new StatusOperation(config).execute()).getChangeSet();
    assertEquals(changeSet.getNewFiles().size(), 0);
    assertEquals(changeSet.getChangedFiles().size(), 0);
    assertEquals(changeSet.getDeletedFiles().size(), 0);
    assertEquals(changeSet.getUnchangedFiles().size(), 1);
    // Cleanup
    TestConfigUtil.deleteTestLocalConfigAndData(config);
}
Also used : UpOperation(org.syncany.operations.up.UpOperation) StatusOperation(org.syncany.operations.status.StatusOperation) Config(org.syncany.config.Config) File(java.io.File) ChangeSet(org.syncany.operations.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (org.syncany.operations.ChangeSet)11 File (java.io.File)6 Test (org.junit.Test)6 StatusOperation (org.syncany.operations.status.StatusOperation)5 Config (org.syncany.config.Config)4 UpOperation (org.syncany.operations.up.UpOperation)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)3 FileVersion (org.syncany.database.FileVersion)2 StatusOperationOptions (org.syncany.operations.status.StatusOperationOptions)2 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)2 TransferSettings (org.syncany.plugins.transfer.TransferSettings)2 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)2 TestClient (org.syncany.tests.util.TestClient)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Deduper (org.syncany.chunk.Deduper)1 PartialFileHistory (org.syncany.database.PartialFileHistory)1 SqlDatabase (org.syncany.database.SqlDatabase)1 CleanupOperationOptions (org.syncany.operations.cleanup.CleanupOperationOptions)1