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 Abel García de Prada
parent dbc42c3e4c
commit 49a298cfc4
7 changed files with 19 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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