2 * ownCloud Android client application
4 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 package com
.owncloud
.android
.operations
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
25 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
26 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
27 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
.ResultCode
;
28 import com
.owncloud
.android
.lib
.resources
.files
.RemoveRemoteFileOperation
;
29 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
33 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
35 public class RemoveFileOperation
extends SyncOperation
{
37 // private static final String TAG = RemoveFileOperation.class.getSimpleName();
41 boolean mOnlyLocalCopy
;
47 * @param remotePath RemotePath of the OCFile instance describing the remote file or
48 * folder to remove from the server
49 * @param onlyLocalCopy When 'true', and a local copy of the file exists, only this is
52 public RemoveFileOperation(String remotePath
, boolean onlyLocalCopy
) {
53 mRemotePath
= remotePath
;
54 mOnlyLocalCopy
= onlyLocalCopy
;
59 * Getter for the file to remove (or removed, if the operation was successfully performed).
61 * @return File to remove or already removed.
63 public OCFile
getFile() {
68 * Performs the remove operation
70 * @param client Client object to communicate with the remote ownCloud server.
73 protected RemoteOperationResult
run(OwnCloudClient client
) {
74 RemoteOperationResult result
= null
;
76 mFileToRemove
= getStorageManager().getFileByPath(mRemotePath
);
78 boolean localRemovalFailed
= false
;
79 if (!mOnlyLocalCopy
) {
80 RemoveRemoteFileOperation operation
= new RemoveRemoteFileOperation(mRemotePath
);
81 result
= operation
.execute(client
);
82 if (result
.isSuccess() || result
.getCode() == ResultCode
.FILE_NOT_FOUND
) {
83 localRemovalFailed
= !(getStorageManager().removeFile(mFileToRemove
, true
, true
));
87 localRemovalFailed
= !(getStorageManager().removeFile(mFileToRemove
, false
, true
));
88 if (!localRemovalFailed
) {
89 result
= new RemoteOperationResult(ResultCode
.OK
);
93 if (localRemovalFailed
) {
94 result
= new RemoteOperationResult(ResultCode
.LOCAL_STORAGE_NOT_REMOVED
);