Merge branch 'develop' into refactor_update_filelist_from_database
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / RemoveFileOperation.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.operations;
19
20 import com.owncloud.android.datamodel.OCFile;
21 import com.owncloud.android.lib.common.OwnCloudClient;
22 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
23 import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
24 import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
25 import com.owncloud.android.operations.common.SyncOperation;
26
27
28 /**
29 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
30 *
31 * @author David A. Velasco
32 * @author masensio
33 */
34 public class RemoveFileOperation extends SyncOperation {
35
36 // private static final String TAG = RemoveFileOperation.class.getSimpleName();
37
38 OCFile mFileToRemove;
39 String mRemotePath;
40 boolean mDeleteLocalCopy;
41
42
43 /**
44 * Constructor
45 *
46 * @param remotePath RemotePath of the OCFile instance describing the remote file or folder to remove from the server
47 * @param deleteLocalCopy When 'true', and a local copy of the file exists, it is also removed.
48 */
49 public RemoveFileOperation(String remotePath, boolean deleteLocalCopy) {
50 mRemotePath = remotePath;
51 mDeleteLocalCopy = deleteLocalCopy;
52 }
53
54
55 /**
56 * Getter for the file to remove (or removed, if the operation was successfully performed).
57 *
58 * @return File to remove or already removed.
59 */
60 public OCFile getFile() {
61 return mFileToRemove;
62 }
63
64 /**
65 * Performs the remove operation
66 *
67 * @param client Client object to communicate with the remote ownCloud server.
68 */
69 @Override
70 protected RemoteOperationResult run(OwnCloudClient client) {
71 RemoteOperationResult result = null;
72
73 RemoveRemoteFileOperation operation = new RemoveRemoteFileOperation(mRemotePath);
74 result = operation.execute(client);
75
76 mFileToRemove = getStorageManager().getFileByPath(mRemotePath);
77
78 if (result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND) {
79 getStorageManager().removeFile(mFileToRemove, true, mDeleteLocalCopy);
80 }
81
82 return result;
83 }
84
85 }