1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Merge pull request #571 from owncloud/feature/copy_move_conflic_solved_users

[FEATURE REQUEST] Copy/move conflict solved by users
This commit is contained in:
Manuel Plazas Palacio 2023-06-21 08:33:47 +02:00 committed by GitHub
commit 063c3fa9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 6 deletions

View File

@ -36,7 +36,7 @@ import java.net.URL
class CopyMethod( class CopyMethod(
val url: URL, val url: URL,
private val destinationUrl: String, private val destinationUrl: String,
private val forceOverride: Boolean = false val forceOverride: Boolean = false
) : DavMethod(url) { ) : DavMethod(url) {
@Throws(Exception::class) @Throws(Exception::class)
public override fun onDavExecute(davResource: DavOCResource): Int { public override fun onDavExecute(davResource: DavOCResource): Int {

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

@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit
* @author Christian Schabesberger * @author Christian Schabesberger
* @author David González V. * @author David González V.
* @author Juan Carlos Garrote Gascón * @author Juan Carlos Garrote Gascón
* @author Manuel Plazas Palacio
* *
* @param sourceRemotePath Remote path of the file/folder to copy. * @param sourceRemotePath Remote path of the file/folder to copy.
* @param targetRemotePath Remote path desired for the file/folder to copy it. * @param targetRemotePath Remote path desired for the file/folder to copy it.
@ -54,6 +55,7 @@ class CopyRemoteFileOperation(
private val targetRemotePath: String, private val targetRemotePath: String,
private val sourceSpaceWebDavUrl: String? = null, private val sourceSpaceWebDavUrl: String? = null,
private val targetSpaceWebDavUrl: String? = null, private val targetSpaceWebDavUrl: String? = null,
private val forceOverride: Boolean = false,
) : RemoteOperation<String>() { ) : RemoteOperation<String>() {
/** /**
@ -74,9 +76,11 @@ class CopyRemoteFileOperation(
var result: RemoteOperationResult<String> var result: RemoteOperationResult<String>
try { try {
val copyMethod = CopyMethod( val copyMethod = CopyMethod(
URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), url = URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
(targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), destinationUrl = (targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
forceOverride = forceOverride,
).apply { ).apply {
addRequestHeaders(this)
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS) setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS) setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
} }
@ -87,6 +91,7 @@ class CopyRemoteFileOperation(
result = RemoteOperationResult(ResultCode.OK) result = RemoteOperationResult(ResultCode.OK)
result.setData(fileRemoteId) result.setData(fileRemoteId)
} }
isPreconditionFailed(status) -> { isPreconditionFailed(status) -> {
result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE) result = RemoteOperationResult(ResultCode.INVALID_OVERWRITE)
client.exhaustResponse(copyMethod.getResponseBodyAsStream()) client.exhaustResponse(copyMethod.getResponseBodyAsStream())
@ -94,6 +99,7 @@ class CopyRemoteFileOperation(
/// 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(copyMethod) result = RemoteOperationResult(copyMethod)
client.exhaustResponse(copyMethod.getResponseBodyAsStream()) client.exhaustResponse(copyMethod.getResponseBodyAsStream())
@ -107,6 +113,13 @@ class CopyRemoteFileOperation(
return result return result
} }
private fun addRequestHeaders(copyMethod: CopyMethod) {
//Adding this because the library has an error with override
if (copyMethod.forceOverride) {
copyMethod.setRequestHeader(OVERWRITE, TRUE)
}
}
private 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 private fun isPreconditionFailed(status: Int) = status == HttpConstants.HTTP_PRECONDITION_FAILED
@ -114,5 +127,7 @@ class CopyRemoteFileOperation(
companion object { companion object {
private const val COPY_READ_TIMEOUT = 10L private const val COPY_READ_TIMEOUT = 10L
private const val COPY_CONNECTION_TIMEOUT = 6L private const val COPY_CONNECTION_TIMEOUT = 6L
private const val OVERWRITE = "overwrite"
private const val TRUE = "T"
} }
} }

View File

@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit
* @author David González Verdugo * @author David González Verdugo
* @author Abel García de Prada * @author Abel García de Prada
* @author Juan Carlos Garrote Gascón * @author Juan Carlos Garrote Gascón
* @author Manuel Plazas Palacio
* *
* @param sourceRemotePath Remote path of the file/folder to copy. * @param sourceRemotePath Remote path of the file/folder to copy.
* @param targetRemotePath Remote path desired for the file/folder to copy it. * @param targetRemotePath Remote path desired for the file/folder to copy it.
@ -54,6 +55,7 @@ open class MoveRemoteFileOperation(
private val sourceRemotePath: String, private val sourceRemotePath: String,
private val targetRemotePath: String, private val targetRemotePath: String,
private val spaceWebDavUrl: String? = null, private val spaceWebDavUrl: String? = null,
private val forceOverride: Boolean = false,
) : RemoteOperation<Unit>() { ) : RemoteOperation<Unit>() {
/** /**
@ -80,6 +82,7 @@ open class MoveRemoteFileOperation(
val moveMethod = MoveMethod( val moveMethod = MoveMethod(
url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
forceOverride = forceOverride,
).apply { ).apply {
addRequestHeaders(this) addRequestHeaders(this)
setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS) setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS)
@ -92,6 +95,7 @@ open class MoveRemoteFileOperation(
isSuccess(status) -> { isSuccess(status) -> {
result = RemoteOperationResult<Unit>(ResultCode.OK) result = RemoteOperationResult<Unit>(ResultCode.OK)
} }
isPreconditionFailed(status) -> { isPreconditionFailed(status) -> {
result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE) result = RemoteOperationResult<Unit>(ResultCode.INVALID_OVERWRITE)
client.exhaustResponse(moveMethod.getResponseBodyAsStream()) client.exhaustResponse(moveMethod.getResponseBodyAsStream())
@ -99,6 +103,7 @@ open class MoveRemoteFileOperation(
/// 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())
@ -125,6 +130,10 @@ open class MoveRemoteFileOperation(
* In case new headers are needed, override this method * In case new headers are needed, override this method
*/ */
open fun addRequestHeaders(moveMethod: MoveMethod) { open fun addRequestHeaders(moveMethod: MoveMethod) {
//Adding this because the library has an error with override
if (moveMethod.forceOverride) {
moveMethod.setRequestHeader(OVERWRITE, TRUE)
}
} }
private 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)
@ -134,5 +143,7 @@ open class MoveRemoteFileOperation(
companion object { companion object {
private const val MOVE_READ_TIMEOUT = 10L private const val MOVE_READ_TIMEOUT = 10L
private const val MOVE_CONNECTION_TIMEOUT = 6L private const val MOVE_CONNECTION_TIMEOUT = 6L
private const val OVERWRITE = "overwrite"
private const val TRUE = "T"
} }
} }

View File

@ -39,7 +39,8 @@ interface FileService : Service {
targetRemotePath: String, targetRemotePath: String,
sourceSpaceWebDavUrl: String?, sourceSpaceWebDavUrl: String?,
targetSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?,
): RemoteOperationResult<String> replace: Boolean,
): RemoteOperationResult<String?>
fun createFolder( fun createFolder(
remotePath: String, remotePath: String,
@ -57,6 +58,7 @@ interface FileService : Service {
sourceRemotePath: String, sourceRemotePath: String,
targetRemotePath: String, targetRemotePath: String,
spaceWebDavUrl: String?, spaceWebDavUrl: String?,
replace: Boolean,
): RemoteOperationResult<Unit> ): RemoteOperationResult<Unit>
fun readFile( fun readFile(

View File

@ -54,12 +54,14 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
targetRemotePath: String, targetRemotePath: String,
sourceSpaceWebDavUrl: String?, sourceSpaceWebDavUrl: String?,
targetSpaceWebDavUrl: String?, targetSpaceWebDavUrl: String?,
): RemoteOperationResult<String> = replace: Boolean,
): RemoteOperationResult<String?> =
CopyRemoteFileOperation( CopyRemoteFileOperation(
sourceRemotePath = sourceRemotePath, sourceRemotePath = sourceRemotePath,
targetRemotePath = targetRemotePath, targetRemotePath = targetRemotePath,
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl, sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
targetSpaceWebDavUrl = targetSpaceWebDavUrl, targetSpaceWebDavUrl = targetSpaceWebDavUrl,
forceOverride = replace,
).execute(client) ).execute(client)
override fun createFolder( override fun createFolder(
@ -88,11 +90,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
sourceRemotePath: String, sourceRemotePath: String,
targetRemotePath: String, targetRemotePath: String,
spaceWebDavUrl: String?, spaceWebDavUrl: String?,
replace: Boolean,
): RemoteOperationResult<Unit> = ): RemoteOperationResult<Unit> =
MoveRemoteFileOperation( MoveRemoteFileOperation(
sourceRemotePath = sourceRemotePath, sourceRemotePath = sourceRemotePath,
targetRemotePath = targetRemotePath, targetRemotePath = targetRemotePath,
spaceWebDavUrl = spaceWebDavUrl, spaceWebDavUrl = spaceWebDavUrl,
forceOverride = replace,
).execute(client) ).execute(client)
override fun readFile( override fun readFile(