Search in sources :

Example 1 with LsRemoteOperationResult

use of org.syncany.operations.ls_remote.LsRemoteOperationResult in project syncany by syncany.

the class DownOperation method checkPreconditions.

/**
	 * Checks whether any new databases are only and whether any other conflicting
	 * actions are running.
	 *
	 * <p>This method sets the result code in <tt>result</tt> according to the
	 * checking result and returns <tt>true</tt> if the rest of the operation can
	 * continue, <tt>false</tt> otherwise.
	 */
private boolean checkPreconditions() throws Exception {
    // Check strategies
    if (options.getConflictStrategy() != DownConflictStrategy.RENAME) {
        logger.log(Level.INFO, "Conflict strategy " + options.getConflictStrategy() + " not yet implemented.");
        result.setResultCode(DownResultCode.NOK);
        return false;
    }
    // practice, but it does in stresstests (#433)
    if (otherRemoteOperationsRunning(CleanupOperation.ACTION_ID)) {
        logger.log(Level.INFO, "* Cleanup running. Skipping down operation.");
        result.setResultCode(DownResultCode.NOK);
        return false;
    }
    // Check which remote databases to download based on the last local vector clock
    LsRemoteOperationResult lsRemoteResult = listUnknownRemoteDatabases();
    result.setLsRemoteResult(lsRemoteResult);
    if (lsRemoteResult.getUnknownRemoteDatabases().isEmpty()) {
        logger.log(Level.INFO, "* Nothing new. Skipping down operation.");
        result.setResultCode(DownResultCode.OK_NO_REMOTE_CHANGES);
        return false;
    }
    return true;
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult)

Example 2 with LsRemoteOperationResult

use of org.syncany.operations.ls_remote.LsRemoteOperationResult in project syncany by syncany.

the class LsRemoteFolderRequestHandler method handleRequest.

@Override
public Response handleRequest(FolderRequest request) {
    try {
        LsRemoteOperation operation = new LsRemoteOperation(config);
        LsRemoteOperationResult operationResult = operation.execute();
        LsRemoteFolderResponse response = new LsRemoteFolderResponse(operationResult, request.getId());
        return response;
    } catch (Exception e) {
        logger.log(Level.WARNING, "Cannot obtain status.", e);
        return new BadRequestResponse(request.getId(), "Cannot execute operation: " + e.getMessage());
    }
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) LsRemoteOperation(org.syncany.operations.ls_remote.LsRemoteOperation)

Example 3 with LsRemoteOperationResult

use of org.syncany.operations.ls_remote.LsRemoteOperationResult 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 LsRemoteOperationResult

use of org.syncany.operations.ls_remote.LsRemoteOperationResult in project syncany by syncany.

the class LsRemoteCommand method execute.

@Override
public int execute(String[] operationArgs) throws Exception {
    LsRemoteOperationResult operationResult = new LsRemoteOperation(config).execute();
    printResults(operationResult);
    return 0;
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) LsRemoteOperation(org.syncany.operations.ls_remote.LsRemoteOperation)

Example 5 with LsRemoteOperationResult

use of org.syncany.operations.ls_remote.LsRemoteOperationResult in project syncany by syncany.

the class LsRemoteCommand method printResults.

@Override
public void printResults(OperationResult operationResult) {
    LsRemoteOperationResult concreteOperationResult = (LsRemoteOperationResult) operationResult;
    List<DatabaseRemoteFile> remoteStatus = concreteOperationResult.getUnknownRemoteDatabases();
    if (remoteStatus.size() > 0) {
        for (RemoteFile unknownRemoteFile : remoteStatus) {
            out.println("? " + unknownRemoteFile.getName());
        }
    } else {
        out.println("No remote changes.");
    }
}
Also used : LsRemoteOperationResult(org.syncany.operations.ls_remote.LsRemoteOperationResult) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) DatabaseRemoteFile(org.syncany.plugins.transfer.files.DatabaseRemoteFile) RemoteFile(org.syncany.plugins.transfer.files.RemoteFile)

Aggregations

LsRemoteOperationResult (org.syncany.operations.ls_remote.LsRemoteOperationResult)5 LsRemoteOperation (org.syncany.operations.ls_remote.LsRemoteOperation)3 DatabaseRemoteFile (org.syncany.plugins.transfer.files.DatabaseRemoteFile)2 ChangeSet (org.syncany.operations.ChangeSet)1 StatusOperation (org.syncany.operations.status.StatusOperation)1 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)1 RemoteFile (org.syncany.plugins.transfer.files.RemoteFile)1