Search in sources :

Example 1 with RemoveFileRemoteOperation

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

the class AbstractOnServerIT method deleteAllFiles.

public static void deleteAllFiles() {
    RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
    assertTrue(result.getLogMessage(), result.isSuccess());
    for (Object object : result.getData()) {
        RemoteFile remoteFile = (RemoteFile) object;
        if (!remoteFile.getRemotePath().equals("/")) {
            if (remoteFile.isEncrypted()) {
                assertTrue(new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(), remoteFile.getRemotePath(), false).execute(client).isSuccess());
            }
            assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath()).execute(client).isSuccess());
        }
    }
}
Also used : RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ReadFolderRemoteOperation(com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) ToggleEncryptionRemoteOperation(com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation) RemoveFileRemoteOperation(com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation)

Example 2 with RemoveFileRemoteOperation

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

the class RemoveFileOperation method run.

/**
 * Performs the remove operation
 *
 * @param   client      Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    RemoteOperation operation;
    if (MimeTypeUtil.isImage(fileToRemove.getMimeType())) {
        // store resized image
        ThumbnailsCacheManager.generateResizedImage(fileToRemove);
    }
    boolean localRemovalFailed = false;
    if (!onlyLocalCopy) {
        if (fileToRemove.isEncrypted()) {
            OCFile parent = getStorageManager().getFileByPath(fileToRemove.getParentRemotePath());
            operation = new RemoveRemoteEncryptedFileOperation(fileToRemove.getRemotePath(), parent.getLocalId(), account, context, fileToRemove.getEncryptedFileName());
        } else {
            operation = new RemoveFileRemoteOperation(fileToRemove.getRemotePath());
        }
        result = operation.execute(client);
        if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
            localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, true, true));
        }
    } else {
        localRemovalFailed = !(getStorageManager().removeFile(fileToRemove, false, true));
        if (!localRemovalFailed) {
            result = new RemoteOperationResult(ResultCode.OK);
        }
    }
    if (localRemovalFailed) {
        result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_REMOVED);
    }
    return result;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoveFileRemoteOperation(com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RemoveFileRemoteOperation(com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation)

Aggregations

RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)2 RemoveFileRemoteOperation (com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation)2 OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)1 ToggleEncryptionRemoteOperation (com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation)1 ReadFolderRemoteOperation (com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation)1 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)1