mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Adapted copy operation for spaces
This commit is contained in:
parent
e9f291371d
commit
a395787e0b
@ -1,5 +1,5 @@
|
|||||||
/* ownCloud Android Library is available under MIT license
|
/* ownCloud Android Library is available under MIT license
|
||||||
* Copyright (C) 2022 ownCloud GmbH.
|
* Copyright (C) 2023 ownCloud GmbH.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -44,25 +44,29 @@ import java.util.concurrent.TimeUnit
|
|||||||
* @author David A. Velasco
|
* @author David A. Velasco
|
||||||
* @author Christian Schabesberger
|
* @author Christian Schabesberger
|
||||||
* @author David González V.
|
* @author David González V.
|
||||||
|
* @author Juan Carlos Garrote Gascón
|
||||||
*
|
*
|
||||||
* @param srcRemotePath 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.
|
||||||
*/
|
*/
|
||||||
class CopyRemoteFileOperation(
|
class CopyRemoteFileOperation(
|
||||||
private val srcRemotePath: String,
|
private val sourceRemotePath: String,
|
||||||
private val targetRemotePath: String,
|
private val targetRemotePath: String,
|
||||||
|
private val sourceSpaceWebDavUrl: String? = null,
|
||||||
|
private val targetSpaceWebDavUrl: String? = null,
|
||||||
) : RemoteOperation<String>() {
|
) : RemoteOperation<String>() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the rename operation.
|
* Performs the rename operation.
|
||||||
*
|
*
|
||||||
* @param client Client object to communicate with the remote ownCloud server.
|
* @param client Client object to communicate with the remote ownCloud server.
|
||||||
*/
|
*/
|
||||||
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
|
||||||
if (targetRemotePath == srcRemotePath) {
|
if (targetRemotePath == sourceRemotePath && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
|
||||||
// nothing to do!
|
// nothing to do!
|
||||||
return RemoteOperationResult(ResultCode.OK)
|
return RemoteOperationResult(ResultCode.OK)
|
||||||
}
|
}
|
||||||
if (targetRemotePath.startsWith(srcRemotePath)) {
|
if (targetRemotePath.startsWith(sourceRemotePath) && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
|
||||||
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +74,8 @@ class CopyRemoteFileOperation(
|
|||||||
var result: RemoteOperationResult<String>
|
var result: RemoteOperationResult<String>
|
||||||
try {
|
try {
|
||||||
val copyMethod = CopyMethod(
|
val copyMethod = CopyMethod(
|
||||||
URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(srcRemotePath)),
|
URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
|
||||||
client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
|
(targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
|
||||||
).apply {
|
).apply {
|
||||||
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
|
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
|
||||||
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
|
||||||
@ -95,10 +99,10 @@ class CopyRemoteFileOperation(
|
|||||||
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Timber.i("Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
|
Timber.i("Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
result = RemoteOperationResult(e)
|
result = RemoteOperationResult(e)
|
||||||
Timber.e(e, "Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
|
Timber.e(e, "Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ interface FileService : Service {
|
|||||||
fun copyFile(
|
fun copyFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String,
|
targetRemotePath: String,
|
||||||
|
sourceSpaceWebDavUrl: String?,
|
||||||
|
targetSpaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<String>
|
): RemoteOperationResult<String>
|
||||||
|
|
||||||
fun createFolder(
|
fun createFolder(
|
||||||
|
@ -56,11 +56,15 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
|
|||||||
|
|
||||||
override fun copyFile(
|
override fun copyFile(
|
||||||
sourceRemotePath: String,
|
sourceRemotePath: String,
|
||||||
targetRemotePath: String
|
targetRemotePath: String,
|
||||||
|
sourceSpaceWebDavUrl: String?,
|
||||||
|
targetSpaceWebDavUrl: String?,
|
||||||
): RemoteOperationResult<String> =
|
): RemoteOperationResult<String> =
|
||||||
CopyRemoteFileOperation(
|
CopyRemoteFileOperation(
|
||||||
srcRemotePath = sourceRemotePath,
|
sourceRemotePath = sourceRemotePath,
|
||||||
targetRemotePath = targetRemotePath
|
targetRemotePath = targetRemotePath,
|
||||||
|
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
|
||||||
|
targetSpaceWebDavUrl = targetSpaceWebDavUrl,
|
||||||
).execute(client)
|
).execute(client)
|
||||||
|
|
||||||
override fun createFolder(
|
override fun createFolder(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user