mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Make overwrite option disabled by default for move operations
This commit is contained in:
parent
7c825b2dc3
commit
f849cd76d4
@ -36,7 +36,7 @@ import java.net.URL
|
||||
class MoveMethod(
|
||||
url: URL,
|
||||
private val destinationUrl: String,
|
||||
private val forceOverride: Boolean
|
||||
private val forceOverride: Boolean = false
|
||||
) : DavMethod(url) {
|
||||
@Throws(Exception::class)
|
||||
override fun onDavExecute(davResource: DavOCResource): Int {
|
||||
|
@ -49,7 +49,6 @@ import java.util.concurrent.TimeUnit
|
||||
open class MoveRemoteFileOperation(
|
||||
private val sourceRemotePath: String,
|
||||
private val targetRemotePath: String,
|
||||
private val forceOverwrite: Boolean
|
||||
) : RemoteOperation<Unit>() {
|
||||
|
||||
/**
|
||||
@ -76,7 +75,6 @@ open class MoveRemoteFileOperation(
|
||||
val moveMethod = MoveMethod(
|
||||
url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
|
||||
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
||||
forceOverride = forceOverwrite
|
||||
).apply {
|
||||
addRequestHeaders(this)
|
||||
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||
@ -85,17 +83,21 @@ open class MoveRemoteFileOperation(
|
||||
|
||||
val status = client.executeHttpMethod(moveMethod)
|
||||
|
||||
if (isSuccess(status)) {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.OK)
|
||||
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !forceOverwrite) {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||
when {
|
||||
isSuccess(status) -> {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.OK)
|
||||
}
|
||||
isPreconditionFailed(status) -> {
|
||||
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
|
||||
client.exhaustResponse(moveMethod.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 = RemoteOperationResult<Unit>(moveMethod)
|
||||
client.exhaustResponse(moveMethod.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 = RemoteOperationResult<Unit>(moveMethod)
|
||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||
}
|
||||
}
|
||||
|
||||
Timber.i("Move $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||
@ -120,7 +122,9 @@ open class MoveRemoteFileOperation(
|
||||
open fun addRequestHeaders(moveMethod: MoveMethod) {
|
||||
}
|
||||
|
||||
protected fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
|
||||
private fun isSuccess(status: Int) = status.isOneOf(HttpConstants.HTTP_CREATED, HttpConstants.HTTP_NO_CONTENT)
|
||||
|
||||
private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED
|
||||
|
||||
companion object {
|
||||
private const val MOVE_READ_TIMEOUT = 10L
|
||||
|
@ -38,13 +38,11 @@ import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation
|
||||
class MoveRemoteChunksFileOperation(
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
overwrite: Boolean,
|
||||
private val fileLastModificationTimestamp: String,
|
||||
private val fileLength: Long
|
||||
) : MoveRemoteFileOperation(
|
||||
sourceRemotePath = sourceRemotePath,
|
||||
targetRemotePath = targetRemotePath,
|
||||
forceOverwrite = overwrite
|
||||
) {
|
||||
|
||||
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
||||
|
@ -35,7 +35,6 @@ interface ChunkService : Service {
|
||||
fun moveFile(
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
overwrite: Boolean,
|
||||
fileLastModificationTimestamp: String,
|
||||
fileLength: Long
|
||||
): RemoteOperationResult<Unit>
|
||||
|
@ -49,7 +49,6 @@ interface FileService : Service {
|
||||
fun moveFile(
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
forceOverwrite: Boolean,
|
||||
): RemoteOperationResult<Unit>
|
||||
|
||||
fun refreshFolder(
|
||||
|
@ -38,15 +38,13 @@ class OCChunkService(override val client: OwnCloudClient) : ChunkService {
|
||||
override fun moveFile(
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
overwrite: Boolean,
|
||||
fileLastModificationTimestamp: String,
|
||||
fileLength: Long
|
||||
): RemoteOperationResult<Unit> =
|
||||
MoveRemoteChunksFileOperation(
|
||||
sourceRemotePath = sourceRemotePath,
|
||||
targetRemotePath = targetRemotePath,
|
||||
overwrite = overwrite,
|
||||
fileLastModificationTimestamp = fileLastModificationTimestamp,
|
||||
fileLength = fileLength
|
||||
fileLength = fileLength,
|
||||
).execute(client)
|
||||
}
|
||||
|
@ -72,12 +72,10 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
||||
override fun moveFile(
|
||||
sourceRemotePath: String,
|
||||
targetRemotePath: String,
|
||||
forceOverwrite: Boolean
|
||||
): RemoteOperationResult<Unit> =
|
||||
MoveRemoteFileOperation(
|
||||
sourceRemotePath = sourceRemotePath,
|
||||
targetRemotePath = targetRemotePath,
|
||||
forceOverwrite = forceOverwrite
|
||||
).execute(client)
|
||||
|
||||
override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> =
|
||||
|
Loading…
x
Reference in New Issue
Block a user