1 /* ownCloud Android client application
3 * @author David A. Velasco
5 * Copyright (C) 2012-2014 ownCloud Inc.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2,
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
.operations
;
23 import com
.owncloud
.android
.datamodel
.OCFile
;
24 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
25 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
27 import com
.owncloud
.android
.lib
.resources
.files
.RemoveRemoteFileOperation
;
28 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
32 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
34 public class RemoveFileOperation
extends SyncOperation
{
36 // private static final String TAG = RemoveFileOperation.class.getSimpleName();
40 boolean mOnlyLocalCopy
;
46 * @param remotePath RemotePath of the OCFile instance describing the remote file or
47 * folder to remove from the server
48 * @param onlyLocalCopy When 'true', and a local copy of the file exists, only this is
51 public RemoveFileOperation(String remotePath
, boolean onlyLocalCopy
) {
52 mRemotePath
= remotePath
;
53 mOnlyLocalCopy
= onlyLocalCopy
;
58 * Getter for the file to remove (or removed, if the operation was successfully performed).
60 * @return File to remove or already removed.
62 public OCFile
getFile() {
67 * Performs the remove operation
69 * @param client Client object to communicate with the remote ownCloud server.
72 protected RemoteOperationResult
run(OwnCloudClient client
) {
73 RemoteOperationResult result
= null
;
75 mFileToRemove
= getStorageManager().getFileByPath(mRemotePath
);
77 boolean localRemovalFailed
= false
;
78 if (!mOnlyLocalCopy
) {
79 RemoveRemoteFileOperation operation
= new RemoveRemoteFileOperation(mRemotePath
);
80 result
= operation
.execute(client
);
81 if (result
.isSuccess() || result
.getCode() == ResultCode
.FILE_NOT_FOUND
) {
82 localRemovalFailed
= !(getStorageManager().removeFile(mFileToRemove
, true
, true
));
86 localRemovalFailed
= !(getStorageManager().removeFile(mFileToRemove
, false
, true
));
87 if (!localRemovalFailed
) {
88 result
= new RemoteOperationResult(ResultCode
.OK
);
92 if (localRemovalFailed
) {
93 result
= new RemoteOperationResult(ResultCode
.LOCAL_STORAGE_NOT_REMOVED
);