Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit a395787

Browse files
committed
Adapted copy operation for spaces
1 parent e9f2913 commit a395787

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CopyRemoteFileOperation.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2022 ownCloud GmbH.
2+
* Copyright (C) 2023 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -44,34 +44,38 @@ import java.util.concurrent.TimeUnit
4444
* @author David A. Velasco
4545
* @author Christian Schabesberger
4646
* @author David González V.
47+
* @author Juan Carlos Garrote Gascón
4748
*
48-
* @param srcRemotePath Remote path of the file/folder to copy.
49+
* @param sourceRemotePath Remote path of the file/folder to copy.
4950
* @param targetRemotePath Remote path desired for the file/folder to copy it.
5051
*/
5152
class CopyRemoteFileOperation(
52-
private val srcRemotePath: String,
53+
private val sourceRemotePath: String,
5354
private val targetRemotePath: String,
55+
private val sourceSpaceWebDavUrl: String? = null,
56+
private val targetSpaceWebDavUrl: String? = null,
5457
) : RemoteOperation<String>() {
58+
5559
/**
5660
* Performs the rename operation.
5761
*
5862
* @param client Client object to communicate with the remote ownCloud server.
5963
*/
6064
override fun run(client: OwnCloudClient): RemoteOperationResult<String> {
61-
if (targetRemotePath == srcRemotePath) {
65+
if (targetRemotePath == sourceRemotePath && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
6266
// nothing to do!
6367
return RemoteOperationResult(ResultCode.OK)
6468
}
65-
if (targetRemotePath.startsWith(srcRemotePath)) {
69+
if (targetRemotePath.startsWith(sourceRemotePath) && sourceSpaceWebDavUrl == targetSpaceWebDavUrl) {
6670
return RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT)
6771
}
6872

6973
/// perform remote operation
7074
var result: RemoteOperationResult<String>
7175
try {
7276
val copyMethod = CopyMethod(
73-
URL(client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(srcRemotePath)),
74-
client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath),
77+
URL((sourceSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)),
78+
(targetSpaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath),
7579
).apply {
7680
setReadTimeout(COPY_READ_TIMEOUT, TimeUnit.SECONDS)
7781
setConnectionTimeout(COPY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
@@ -95,10 +99,10 @@ class CopyRemoteFileOperation(
9599
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
96100
}
97101
}
98-
Timber.i("Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
102+
Timber.i("Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
99103
} catch (e: Exception) {
100104
result = RemoteOperationResult(e)
101-
Timber.e(e, "Copy $srcRemotePath to $targetRemotePath: ${result.logMessage}")
105+
Timber.e(e, "Copy $sourceRemotePath to $targetRemotePath: ${result.logMessage}")
102106
}
103107
return result
104108
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ interface FileService : Service {
3939
fun copyFile(
4040
sourceRemotePath: String,
4141
targetRemotePath: String,
42+
sourceSpaceWebDavUrl: String?,
43+
targetSpaceWebDavUrl: String?,
4244
): RemoteOperationResult<String>
4345

4446
fun createFolder(

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ class OCFileService(override val client: OwnCloudClient) : FileService {
5656

5757
override fun copyFile(
5858
sourceRemotePath: String,
59-
targetRemotePath: String
59+
targetRemotePath: String,
60+
sourceSpaceWebDavUrl: String?,
61+
targetSpaceWebDavUrl: String?,
6062
): RemoteOperationResult<String> =
6163
CopyRemoteFileOperation(
62-
srcRemotePath = sourceRemotePath,
63-
targetRemotePath = targetRemotePath
64+
sourceRemotePath = sourceRemotePath,
65+
targetRemotePath = targetRemotePath,
66+
sourceSpaceWebDavUrl = sourceSpaceWebDavUrl,
67+
targetSpaceWebDavUrl = targetSpaceWebDavUrl,
6468
).execute(client)
6569

6670
override fun createFolder(

0 commit comments

Comments
 (0)