]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix moving files of encrypted local storage to unencrypted local storage 35894/head
authorRobin Appelman <robin@icewind.nl>
Tue, 27 Dec 2022 14:32:59 +0000 (15:32 +0100)
committerVincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com>
Tue, 24 Jan 2023 16:40:41 +0000 (16:40 +0000)
for example when moving encrypted files to a groupfolder

Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Storage/Local.php

index 9daa3517825170e791e5c30c38d5469170f8d879..b021d40d335bbec1c4da4bfadf555ea12d4df968 100644 (file)
@@ -44,6 +44,7 @@
 namespace OC\Files\Storage;
 
 use OC\Files\Filesystem;
+use OC\Files\Storage\Wrapper\Encryption;
 use OC\Files\Storage\Wrapper\Jail;
 use OCP\Constants;
 use OCP\Files\ForbiddenException;
@@ -543,6 +544,16 @@ class Local extends \OC\Files\Storage\Common {
                }
        }
 
+       private function canDoCrossStorageMove(IStorage $sourceStorage) {
+               return $sourceStorage->instanceOfStorage(Local::class)
+                       // Don't treat ACLStorageWrapper like local storage where copy can be done directly.
+                       // Instead, use the slower recursive copying in php from Common::copyFromStorage with
+                       // more permissions checks.
+                       && !$sourceStorage->instanceOfStorage('OCA\GroupFolders\ACL\ACLStorageWrapper')
+                       // when moving encrypted files we have to handle keys and the target might not be encrypted
+                       && !$sourceStorage->instanceOfStorage(Encryption::class);
+       }
+
        /**
         * @param IStorage $sourceStorage
         * @param string $sourceInternalPath
@@ -551,10 +562,7 @@ class Local extends \OC\Files\Storage\Common {
         * @return bool
         */
        public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
-               // Don't treat ACLStorageWrapper like local storage where copy can be done directly.
-               // Instead use the slower recursive copying in php from Common::copyFromStorage with
-               // more permissions checks.
-               if ($sourceStorage->instanceOfStorage(Local::class) && !$sourceStorage->instanceOfStorage('OCA\GroupFolders\ACL\ACLStorageWrapper')) {
+               if ($this->canDoCrossStorageMove($sourceStorage)) {
                        if ($sourceStorage->instanceOfStorage(Jail::class)) {
                                /**
                                 * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage
@@ -578,7 +586,7 @@ class Local extends \OC\Files\Storage\Common {
         * @return bool
         */
        public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
-               if ($sourceStorage->instanceOfStorage(Local::class)) {
+               if ($this->canDoCrossStorageMove($sourceStorage)) {
                        if ($sourceStorage->instanceOfStorage(Jail::class)) {
                                /**
                                 * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage