1
0
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:
Abel García de Prada 2021-05-11 18:16:19 +02:00 committed by Juan Carlos Garrote
parent 5dc3c0e79b
commit a71a52ac0b
7 changed files with 19 additions and 23 deletions

View File

@ -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 {

View File

@ -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,18 +83,22 @@ open class MoveRemoteFileOperation(
val status = client.executeHttpMethod(moveMethod)
if (isSuccess(status)) {
when {
isSuccess(status) -> {
result = RemoteOperationResult<Unit>(ResultCode.OK)
} else if (status == HttpConstants.HTTP_PRECONDITION_FAILED && !forceOverwrite) {
}
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 {
}
else -> {
result = RemoteOperationResult<Unit>(moveMethod)
client.exhaustResponse(moveMethod.getResponseBodyAsStream())
}
}
Timber.i("Move $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
} catch (e: Exception) {
@ -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

View File

@ -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

View File

@ -35,7 +35,6 @@ interface ChunkService : Service {
fun moveFile(
sourceRemotePath: String,
targetRemotePath: String,
overwrite: Boolean,
fileLastModificationTimestamp: String,
fileLength: Long
): RemoteOperationResult<Unit>

View File

@ -49,7 +49,6 @@ interface FileService : Service {
fun moveFile(
sourceRemotePath: String,
targetRemotePath: String,
forceOverwrite: Boolean,
): RemoteOperationResult<Unit>
fun refreshFolder(

View File

@ -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)
}

View File

@ -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>> =