1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-08 00:16:09 +00:00

Merge pull request #260 from owncloud/document_provider/copy

[Document Provider] Copy
This commit is contained in:
David González Verdugo 2019-09-12 10:11:15 +02:00 committed by GitHub
commit 2b62387e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -50,6 +50,7 @@ public class HttpConstants {
public static final String CONTENT_TYPE_URLENCODED_UTF8 = "application/x-www-form-urlencoded; charset=utf-8";
public static final String ACCEPT_ENCODING_HEADER = "Accept-Encoding";
public static final String ACCEPT_ENCODING_IDENTITY = "identity";
public static final String OC_FILE_REMOTE_ID = "OC-FileId";
/***********************************************************************************************************
************************************************ STATUS CODES *********************************************

View File

@ -47,7 +47,7 @@ import java.util.concurrent.TimeUnit;
* @author David A. Velasco
* @author Christian Schabesberger
*/
public class CopyRemoteFileOperation extends RemoteOperation {
public class CopyRemoteFileOperation extends RemoteOperation<String> {
private static final String TAG = CopyRemoteFileOperation.class.getSimpleName();
@ -80,8 +80,7 @@ public class CopyRemoteFileOperation extends RemoteOperation {
* @param client Client object to communicate with the remote ownCloud server.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
protected RemoteOperationResult<String> run(OwnCloudClient client) {
OwnCloudVersion version = client.getOwnCloudVersion();
boolean versionWithForbiddenChars =
(version != null && version.isVersionWithForbiddenCharacters());
@ -101,9 +100,10 @@ public class CopyRemoteFileOperation extends RemoteOperation {
}
/// perform remote operation
RemoteOperationResult result = null;
RemoteOperationResult<String> result;
try {
CopyMethod copyMethod = new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
CopyMethod copyMethod =
new CopyMethod(new URL(client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mSrcRemotePath)),
client.getUserFilesWebDavUri() + WebdavUtils.encodePath(mTargetRemotePath),
mOverwrite);
@ -113,16 +113,17 @@ public class CopyRemoteFileOperation extends RemoteOperation {
final int status = client.executeHttpMethod(copyMethod);
if (status == HttpConstants.HTTP_CREATED || status == HttpConstants.HTTP_NO_CONTENT) {
String fileRemoteId = copyMethod.getResponseHeader(HttpConstants.OC_FILE_REMOTE_ID);
result = new RemoteOperationResult<>(ResultCode.OK);
result.setData(fileRemoteId);
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !mOverwrite) {
result = new RemoteOperationResult<>(ResultCode.INVALID_OVERWRITE);
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
/// for other errors that could be explicitly handled, check first:
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
} else {
result = new RemoteOperationResult<>(copyMethod);
client.exhaustResponse(copyMethod.getResponseBodyAsStream());
}