Search in sources :

Example 1 with MoveFileRemoteOperation

use of com.owncloud.android.lib.resources.files.MoveFileRemoteOperation in project android by nextcloud.

the class MoveFileOperation method run.

/**
 * Performs the operation.
 *
 * @param   client      Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    // / 1. check move validity
    if (targetParentPath.startsWith(srcPath)) {
        return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
    }
    OCFile file = getStorageManager().getFileByPath(srcPath);
    if (file == null) {
        return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
    }
    // / 2. remote move
    String targetPath = targetParentPath + file.getFileName();
    if (file.isFolder()) {
        targetPath += OCFile.PATH_SEPARATOR;
    }
    RemoteOperationResult result = new MoveFileRemoteOperation(srcPath, targetPath, false).execute(client);
    // / 3. local move
    if (result.isSuccess()) {
        getStorageManager().moveLocalFile(file, targetPath, targetParentPath);
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) MoveFileRemoteOperation(com.owncloud.android.lib.resources.files.MoveFileRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 MoveFileRemoteOperation (com.owncloud.android.lib.resources.files.MoveFileRemoteOperation)1