diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt index 949d72e9..c4fdd5da 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt @@ -54,6 +54,7 @@ class CopyRemoteFileOperation( private val targetRemotePath: String, private val sourceSpaceWebDavUrl: String? = null, private val targetSpaceWebDavUrl: String? = null, + private val forceOverride: Boolean = false, ) : RemoteOperation() { /** @@ -74,8 +75,9 @@ class CopyRemoteFileOperation( var result: RemoteOperationResult try { val copyMethod = CopyMethod( - URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), - (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), + url = URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), + destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), + forceOverride = forceOverride, ).apply { setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS) setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) @@ -87,6 +89,7 @@ class CopyRemoteFileOperation( result = RemoteOperationResult(ResultCode.OK) result.setData(fileRemoteId) } + isPreconditionFailed(status) -> { result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE) client.exhaustResponse(copyMethod.getResponseBodyAsStream()) @@ -94,6 +97,7 @@ class CopyRemoteFileOperation( /// for other errors that could be explicitly handled, check first: /// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4 } + else -> { result = RemoteOperationResult(copyMethod) client.exhaustResponse(copyMethod.getResponseBodyAsStream()) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt index b524dc3f..d92d7dc2 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt @@ -39,7 +39,8 @@ interface FileService : Service { targetRemotePath: String, sourceSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?, - ): RemoteOperationResult + replace: Boolean, + ): RemoteOperationResult fun createFolder( remotePath: String, diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt index 7b86a4fa..170bcfab 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt @@ -54,12 +54,14 @@ class OCFileService(override val client: OwnCloudClient) : FileService { targetRemotePath: String, sourceSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?, - ): RemoteOperationResult = + replace: Boolean, + ): RemoteOperationResult = CopyRemoteFileOperation( sourceRemotePath = sourceRemotePath, targetRemotePath = targetRemotePath, sourceSpaceWebDavUrl = sourceSpaceWebDavUrl, targetSpaceWebDavUrl = targetSpaceWebDavUrl, + forceOverride = replace, ).execute(client) override fun createFolder(