use of org.syncany.operations.status.StatusOperation in project syncany by syncany.
the class StatusFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
StatusFolderRequest concreteRequest = (StatusFolderRequest) request;
try {
StatusOperation operation = new StatusOperation(config, concreteRequest.getOptions());
StatusOperationResult operationResult = operation.execute();
StatusFolderResponse statusFolderResponse = new StatusFolderResponse(operationResult, request.getId());
return statusFolderResponse;
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot obtain status.", e);
return new BadRequestResponse(request.getId(), "Cannot execute operation: " + e.getMessage());
}
}
use of org.syncany.operations.status.StatusOperation 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);
}
use of org.syncany.operations.status.StatusOperation 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);
}
use of org.syncany.operations.status.StatusOperation 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;
}
use of org.syncany.operations.status.StatusOperation in project syncany by syncany.
the class StatusCommand method execute.
@Override
public int execute(String[] operationArgs) throws Exception {
StatusOperationOptions operationOptions = parseOptions(operationArgs);
StatusOperationResult operationResult = new StatusOperation(config, operationOptions).execute();
printResults(operationResult);
return 0;
}
Aggregations