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(
|
class MoveMethod(
|
||||||
url: URL,
|
url: URL,
|
||||||
private val destinationUrl: String,
|
private val destinationUrl: String,
|
||||||
private val forceOverride: Boolean
|
private val forceOverride: Boolean = false
|
||||||
) : DavMethod(url) {
|
) : DavMethod(url) {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun onDavExecute(davResource: DavOCResource): Int {
|
override fun onDavExecute(davResource: DavOCResource): Int {
|
||||||
|
@ -49,7 +49,6 @@ import java.util.concurrent.TimeUnit
|
|||||||
open class MoveRemoteFileOperation(
|
open class MoveRemoteFileOperation(
|
||||||
private val sourceRemotePath: String,
|
private val sourceRemotePath: String,
|
||||||
private val targetRemotePath: String,
|
private val targetRemotePath: String,
|
||||||
private val forceOverwrite: Boolean
|
|
||||||
) : RemoteOperation<Unit>() {
|
) : RemoteOperation<Unit>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +75,6 @@ open class MoveRemoteFileOperation(
|
|||||||
val moveMethod = MoveMethod(
|
val moveMethod = MoveMethod(
|
||||||
url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
|
url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)),
|
||||||
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
||||||
forceOverride = forceOverwrite
|
|
||||||
).apply {
|
).apply {
|
||||||
addRequestHeaders(this)
|
addRequestHeaders(this)
|
||||||
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||||
@ -85,18 +83,22 @@ open class MoveRemoteFileOperation(
|
|||||||
|
|
||||||
val status = client.executeHttpMethod(moveMethod)
|
val status = client.executeHttpMethod(moveMethod)
|
||||||
|
|
||||||
if (isSuccess(status)) {
|
when {
|
||||||
|
isSuccess(status) -> {
|
||||||
result = RemoteOperationResult<Unit>(ResultCode.OK)
|
result = RemoteOperationResult<Unit>(ResultCode.OK)
|
||||||
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !forceOverwrite) {
|
}
|
||||||
|
isPreconditionFailed(status) -> {
|
||||||
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
|
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
|
||||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||||
|
|
||||||
/// for other errors that could be explicitly handled, check first:
|
/// for other errors that could be explicitly handled, check first:
|
||||||
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
/// http://www.webdav.org/specs/rfc4918.html#rfc.section.9.9.4
|
||||||
} else {
|
}
|
||||||
|
else -> {
|
||||||
result = RemoteOperationResult<Unit>(moveMethod)
|
result = RemoteOperationResult<Unit>(moveMethod)
|
||||||
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timber.i("Move $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
Timber.i("Move $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -120,7 +122,9 @@ open class MoveRemoteFileOperation(
|
|||||||
open fun addRequestHeaders(moveMethod: MoveMethod) {
|
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 {
|
companion object {
|
||||||
private const val MOVE_READ_TIMEOUT = 10L
|
private const val MOVE_READ_TIMEOUT = 10L
|
||||||
|
@ -38,13 +38,11 @@ import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation
|
|||||||
class MoveRemoteChunksFileOperation(
|
class MoveRemoteChunksFileOperation(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
overwrite: Boolean,
|
|
||||||
private val fileLastModificationTimestamp: String,
|
private val fileLastModificationTimestamp: String,
|
||||||
private val fileLength: Long
|
private val fileLength: Long
|
||||||
) : MoveRemoteFileOperation(
|
) : MoveRemoteFileOperation(
|
||||||
sourceRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath,
|
targetRemotePath = targetRemotePath,
|
||||||
forceOverwrite = overwrite
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
override fun getSrcWebDavUriForClient(client: OwnCloudClient): Uri = client.uploadsWebDavUri
|
||||||
|
@ -35,7 +35,6 @@ interface ChunkService : Service {
|
|||||||
fun moveFile(
|
fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
overwrite: Boolean,
|
|
||||||
fileLastModificationTimestamp: String,
|
fileLastModificationTimestamp: String,
|
||||||
fileLength: Long
|
fileLength: Long
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
@ -49,7 +49,6 @@ interface FileService : Service {
|
|||||||
fun moveFile(
|
fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
forceOverwrite: Boolean,
|
|
||||||
): RemoteOperationResult<Unit>
|
): RemoteOperationResult<Unit>
|
||||||
|
|
||||||
fun refreshFolder(
|
fun refreshFolder(
|
||||||
|
@ -38,15 +38,13 @@ class OCChunkService(override val client: OwnCloudClient) : ChunkService {
|
|||||||
override fun moveFile(
|
override fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
overwrite: Boolean,
|
|
||||||
fileLastModificationTimestamp: String,
|
fileLastModificationTimestamp: String,
|
||||||
fileLength: Long
|
fileLength: Long
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
MoveRemoteChunksFileOperation(
|
MoveRemoteChunksFileOperation(
|
||||||
sourceRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath,
|
targetRemotePath = targetRemotePath,
|
||||||
overwrite = overwrite,
|
|
||||||
fileLastModificationTimestamp = fileLastModificationTimestamp,
|
fileLastModificationTimestamp = fileLastModificationTimestamp,
|
||||||
fileLength = fileLength
|
fileLength = fileLength,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,10 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
override fun moveFile(
|
override fun moveFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
forceOverwrite: Boolean
|
|
||||||
): RemoteOperationResult<Unit> =
|
): RemoteOperationResult<Unit> =
|
||||||
MoveRemoteFileOperation(
|
MoveRemoteFileOperation(
|
||||||
sourceRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath,
|
targetRemotePath = targetRemotePath,
|
||||||
forceOverwrite = forceOverwrite
|
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> =
|
override fun refreshFolder(remotePath: String): RemoteOperationResult<ArrayList<RemoteFile>> =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user