Search in sources :

Example 1 with RenameRemoteFileOperation

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

the class RenameFileOperation method run.

/**
     * Performs the rename operation.
     * 
     * @param   client      Client object to communicate with the remote ownCloud server.
     */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    mFile = getStorageManager().getFileByPath(mRemotePath);
    // check if the new name is valid in the local file system
    try {
        if (!isValidNewName()) {
            return new RemoteOperationResult(ResultCode.INVALID_LOCAL_FILE_NAME);
        }
        String parent = (new File(mFile.getRemotePath())).getParent();
        parent = (parent.endsWith(OCFile.PATH_SEPARATOR)) ? parent : parent + OCFile.PATH_SEPARATOR;
        mNewRemotePath = parent + mNewName;
        if (mFile.isFolder()) {
            mNewRemotePath += OCFile.PATH_SEPARATOR;
        }
        // check local overwrite
        if (getStorageManager().getFileByPath(mNewRemotePath) != null) {
            return new RemoteOperationResult(ResultCode.INVALID_OVERWRITE);
        }
        RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(), mNewName, mFile.isFolder());
        result = operation.execute(client);
        if (result.isSuccess()) {
            if (mFile.isFolder()) {
                saveLocalDirectory(parent);
            } else {
                saveLocalFile();
            }
        }
    } catch (IOException e) {
        Log_OC.e(TAG, "Rename " + mFile.getRemotePath() + " to " + ((mNewRemotePath == null) ? mNewName : mNewRemotePath) + ": " + ((result != null) ? result.getLogMessage() : ""), e);
    }
    return result;
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RenameRemoteFileOperation(com.owncloud.android.lib.resources.files.RenameRemoteFileOperation) IOException(java.io.IOException) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Aggregations

OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 RenameRemoteFileOperation (com.owncloud.android.lib.resources.files.RenameRemoteFileOperation)1 File (java.io.File)1 IOException (java.io.IOException)1