1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 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 android
.accounts
.Account
;
21 import android
.util
.Log
;
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
.CopyRemoteFileOperation
;
28 import com
.owncloud
.android
.operations
.common
.SyncOperation
;
32 * Operation copying an {@link OCFile} to a different folder.
34 * @author David A. Velasco
36 public class CopyFileOperation
extends SyncOperation
{
38 //private static final String TAG = MoveFileOperation.class.getSimpleName();
40 private String mSrcPath
;
41 private String mTargetParentPath
;
49 * @param srcPath Remote path of the {@link OCFile} to move.
50 * @param targetParentPath Path to the folder where the file will be copied into.
51 * @param account OwnCloud account containing both the file and the target folder
53 public CopyFileOperation(String srcPath
, String targetParentPath
, Account account
) {
55 mTargetParentPath
= targetParentPath
;
56 if (!mTargetParentPath
.endsWith(OCFile
.PATH_SEPARATOR
)) {
57 mTargetParentPath
+= OCFile
.PATH_SEPARATOR
;
64 * Performs the operation.
66 * @param client Client object to communicate with the remote ownCloud server.
69 protected RemoteOperationResult
run(OwnCloudClient client
) {
70 RemoteOperationResult result
;
72 /// 1. check copy validity
73 if (mTargetParentPath
.startsWith(mSrcPath
)) {
74 return new RemoteOperationResult(ResultCode
.INVALID_MOVE_INTO_DESCENDANT
);
76 mFile
= getStorageManager().getFileByPath(mSrcPath
);
78 return new RemoteOperationResult(ResultCode
.FILE_NOT_FOUND
);
82 String targetPath
= mTargetParentPath
+ mFile
.getFileName();
83 if (mFile
.isFolder()) {
84 targetPath
+= OCFile
.PATH_SEPARATOR
;
86 CopyRemoteFileOperation operation
= new CopyRemoteFileOperation(
91 result
= operation
.execute(client
);
94 if (result
.isSuccess()) {
95 getStorageManager().copyLocalFile(mFile
, targetPath
);
97 // TODO handle ResultCode.PARTIAL_COPY_DONE in client Activity, for the moment