1
1
/* ownCloud Android Library is available under MIT license
2
- * Copyright (C) 2022 ownCloud GmbH.
2
+ * Copyright (C) 2023 ownCloud GmbH.
3
3
*
4
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
* of this software and associated documentation files (the "Software"), to deal
@@ -44,34 +44,38 @@ import java.util.concurrent.TimeUnit
44
44
* @author David A. Velasco
45
45
* @author Christian Schabesberger
46
46
* @author David González V.
47
+ * @author Juan Carlos Garrote Gascón
47
48
*
48
- * @param srcRemotePath Remote path of the file/folder to copy.
49
+ * @param sourceRemotePath Remote path of the file/folder to copy.
49
50
* @param targetRemotePath Remote path desired for the file/folder to copy it.
50
51
*/
51
52
class CopyRemoteFileOperation (
52
- private val srcRemotePath : String ,
53
+ private val sourceRemotePath : String ,
53
54
private val targetRemotePath : String ,
55
+ private val sourceSpaceWebDavUrl : String? = null ,
56
+ private val targetSpaceWebDavUrl : String? = null ,
54
57
) : RemoteOperation<String>() {
58
+
55
59
/* *
56
60
* Performs the rename operation.
57
61
*
58
62
* @param client Client object to communicate with the remote ownCloud server.
59
63
*/
60
64
override fun run (client : OwnCloudClient ): RemoteOperationResult <String > {
61
- if (targetRemotePath == srcRemotePath ) {
65
+ if (targetRemotePath == sourceRemotePath && sourceSpaceWebDavUrl == targetSpaceWebDavUrl ) {
62
66
// nothing to do!
63
67
return RemoteOperationResult (ResultCode .OK )
64
68
}
65
- if (targetRemotePath.startsWith(srcRemotePath) ) {
69
+ if (targetRemotePath.startsWith(sourceRemotePath) && sourceSpaceWebDavUrl == targetSpaceWebDavUrl ) {
66
70
return RemoteOperationResult (ResultCode .INVALID_COPY_INTO_DESCENDANT )
67
71
}
68
72
69
73
// / perform remote operation
70
74
var result: RemoteOperationResult <String >
71
75
try {
72
76
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),
75
79
).apply {
76
80
setReadTimeout(COPY_READ_TIMEOUT , TimeUnit .SECONDS )
77
81
setConnectionTimeout(COPY_CONNECTION_TIMEOUT , TimeUnit .SECONDS )
@@ -95,10 +99,10 @@ class CopyRemoteFileOperation(
95
99
client.exhaustResponse(copyMethod.getResponseBodyAsStream())
96
100
}
97
101
}
98
- Timber .i(" Copy $srcRemotePath to $targetRemotePath : ${result.logMessage} " )
102
+ Timber .i(" Copy $sourceRemotePath to $targetRemotePath : ${result.logMessage} " )
99
103
} catch (e: Exception ) {
100
104
result = RemoteOperationResult (e)
101
- Timber .e(e, " Copy $srcRemotePath to $targetRemotePath : ${result.logMessage} " )
105
+ Timber .e(e, " Copy $sourceRemotePath to $targetRemotePath : ${result.logMessage} " )
102
106
}
103
107
return result
104
108
}
0 commit comments