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
.oc_framework
.network
.webdav
.WebdavClient
;
23 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
24 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
25 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
.ResultCode
;
26 import com
.owncloud
.android
.oc_framework
.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(WebdavClient 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
);
83 // delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mFileToRemove.getRemotePath()));
84 // int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);
85 // if (delete.succeeded() || status == HttpStatus.SC_NOT_FOUND) {
86 // mDataStorageManager.removeFile(mFileToRemove, true, mDeleteLocalCopy);
88 // delete.getResponseBodyAsString(); // exhaust the response, although not interesting
89 // result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status, delete.getResponseHeaders());
90 // Log_OC.i(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage());
92 // } catch (Exception e) {
93 // result = new RemoteOperationResult(e);
94 // Log_OC.e(TAG, "Remove " + mFileToRemove.getRemotePath() + ": " + result.getLogMessage(), e);
97 // if (delete != null)
98 // delete.releaseConnection();