diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt index e59388bd..d7e927be 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license -* Copyright (C) 2020 ownCloud GmbH. +* Copyright (C) 2023 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,6 +41,7 @@ import java.util.concurrent.TimeUnit * @author David A. Velasco * @author David González Verdugo * @author Abel García de Prada + * @author Juan Carlos Garrote Gascón * * @param remotePath Path to append to the URL owned by the client instance. * @param isUserLoggedIn When `true`, the username won't be added at the end of the PROPFIND url since is not @@ -48,21 +49,23 @@ import java.util.concurrent.TimeUnit */ class CheckPathExistenceRemoteOperation( val remotePath: String? = "", - val isUserLoggedIn: Boolean + val isUserLoggedIn: Boolean, + val spaceWebDavUrl: String? = null, ) : RemoteOperation() { override fun run(client: OwnCloudClient): RemoteOperationResult { - return try { - val stringUrl = - if (isUserLoggedIn) client.baseFilesWebDavUri.toString() - else client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(remotePath) + val baseStringUrl = spaceWebDavUrl ?: + if (isUserLoggedIn) client.baseFilesWebDavUri.toString() + else client.userFilesWebDavUri.toString() + val stringUrl = baseStringUrl + WebdavUtils.encodePath(remotePath) + return try { val propFindMethod = PropfindMethod(URL(stringUrl), 0, allPropset).apply { setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS) setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS) } - var status = client.executeHttpMethod(propFindMethod) + val status = client.executeHttpMethod(propFindMethod) /* PROPFIND method * 404 NOT FOUND: path doesn't exist, * 207 MULTI_STATUS: path exists. @@ -77,7 +80,7 @@ class CheckPathExistenceRemoteOperation( val result = RemoteOperationResult(e) Timber.e( e, - "Existence check for ${client.userFilesWebDavUri}${WebdavUtils.encodePath(remotePath)} : ${result.logMessage}" + "Existence check for $stringUrl : ${result.logMessage}" ) result } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt index 5741766a..6689c5f9 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/MoveRemoteFileOperation.kt @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2021 ownCloud GmbH. + * Copyright (C) 2023 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,17 +38,22 @@ import java.util.concurrent.TimeUnit /** * Remote operation moving a remote file or folder in the ownCloud server to a different folder - * in the same account. + * in the same account and space. * * Allows renaming the moving file/folder at the same time. * * @author David A. Velasco * @author David González Verdugo * @author Abel García de Prada + * @author Juan Carlos Garrote Gascón + * + * @param sourceRemotePath Remote path of the file/folder to copy. + * @param targetRemotePath Remote path desired for the file/folder to copy it. */ open class MoveRemoteFileOperation( private val sourceRemotePath: String, private val targetRemotePath: String, + private val spaceWebDavUrl: String? = null, ) : RemoteOperation() { /** @@ -73,8 +78,8 @@ open class MoveRemoteFileOperation( // so this uri has to be customizable val srcWebDavUri = getSrcWebDavUriForClient(client) val moveMethod = MoveMethod( - url = URL(srcWebDavUri.toString() + WebdavUtils.encodePath(sourceRemotePath)), - destinationUrl = client.userFilesWebDavUri.toString() + WebdavUtils.encodePath(targetRemotePath), + url = URL((spaceWebDavUrl ?: srcWebDavUri.toString()) + WebdavUtils.encodePath(sourceRemotePath)), + destinationUrl = (spaceWebDavUrl ?: client.userFilesWebDavUri.toString()) + WebdavUtils.encodePath(targetRemotePath), ).apply { addRequestHeaders(this) setReadTimeout(MOVE_READ_TIMEOUT, TimeUnit.SECONDS) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt index 89407585..25365301 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/FileService.kt @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2020 ownCloud GmbH. + * Copyright (C) 2023 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,7 +32,8 @@ interface FileService : Service { fun checkPathExistence( path: String, - isUserLogged: Boolean + isUserLogged: Boolean, + spaceWebDavUrl: String? = null, ): RemoteOperationResult fun copyFile( @@ -55,6 +56,7 @@ interface FileService : Service { fun moveFile( sourceRemotePath: String, targetRemotePath: String, + spaceWebDavUrl: String?, ): RemoteOperationResult fun readFile( diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt index e0c6a2f6..0a7b6e1f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/services/implementation/OCFileService.kt @@ -1,5 +1,5 @@ /* 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 * of this software and associated documentation files (the "Software"), to deal @@ -42,11 +42,13 @@ class OCFileService(override val client: OwnCloudClient) : FileService { override fun checkPathExistence( path: String, - isUserLogged: Boolean + isUserLogged: Boolean, + spaceWebDavUrl: String?, ): RemoteOperationResult = CheckPathExistenceRemoteOperation( remotePath = path, - isUserLoggedIn = isUserLogged + isUserLoggedIn = isUserLogged, + spaceWebDavUrl = spaceWebDavUrl, ).execute(client) override fun getUrlToOpenInWeb(openWebEndpoint: String, fileId: String): RemoteOperationResult = @@ -86,10 +88,12 @@ class OCFileService(override val client: OwnCloudClient) : FileService { override fun moveFile( sourceRemotePath: String, targetRemotePath: String, + spaceWebDavUrl: String?, ): RemoteOperationResult = MoveRemoteFileOperation( sourceRemotePath = sourceRemotePath, targetRemotePath = targetRemotePath, + spaceWebDavUrl = spaceWebDavUrl, ).execute(client) override fun readFile(