1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.operations
;
20 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
21 import com
.owncloud
.android
.datamodel
.OCFile
;
22 import com
.owncloud
.android
.lib
.network
.OwnCloudClient
;
23 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperation
;
24 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
;
25 import com
.owncloud
.android
.lib
.operations
.common
.RemoteOperationResult
.ResultCode
;
26 import com
.owncloud
.android
.lib
.operations
.remote
.RemoveRemoteFileOperation
;
30 * Remote operation performing the removal of a remote file or folder in the ownCloud server.
32 * @author David A. Velasco
34 public class RemoveFileOperation
extends RemoteOperation
{
36 // private static final String TAG = RemoveFileOperation.class.getSimpleName();
39 boolean mDeleteLocalCopy
;
40 FileDataStorageManager mDataStorageManager
;
46 * @param fileToRemove 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 * @param storageManager Reference to the local database corresponding to the account where the file is contained.
50 public RemoveFileOperation(OCFile fileToRemove
, boolean deleteLocalCopy
, FileDataStorageManager storageManager
) {
51 mFileToRemove
= fileToRemove
;
52 mDeleteLocalCopy
= deleteLocalCopy
;
53 mDataStorageManager
= storageManager
;
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 RemoveRemoteFileOperation operation
= new RemoveRemoteFileOperation(mFileToRemove
.getRemotePath());
76 result
= operation
.execute(client
);
78 if (result
.isSuccess() || result
.getCode() == ResultCode
.FILE_NOT_FOUND
) {
79 mDataStorageManager
.removeFile(mFileToRemove
, true
, mDeleteLocalCopy
);