]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix path handling when transferring incoming shares 31204/head
authorVincent Petry <vincent@nextcloud.com>
Thu, 10 Feb 2022 08:50:21 +0000 (09:50 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 16 Feb 2022 09:49:44 +0000 (09:49 +0000)
When transferring incoming shares from a guest user without specifying a
path, the $path is empty.
The fix properly handles that situation to avoid looking for shares in a
path with doubled slashes which failed to find shares to transfer.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
apps/files/lib/Service/OwnershipTransferService.php

index 93a3a188399ff49d887e7fb4d4c066d4ba40f4f5..670e6419d755f87d5d8d73958482175b68ac4a1a 100644 (file)
@@ -444,13 +444,17 @@ class OwnershipTransferService {
                $output->writeln("Restoring incoming shares ...");
                $progress = new ProgressBar($output, count($sourceShares));
                $prefix = "$destinationUid/files";
+               $finalShareTarget = '';
                if (substr($finalTarget, 0, strlen($prefix)) === $prefix) {
                        $finalShareTarget = substr($finalTarget, strlen($prefix));
                }
                foreach ($sourceShares as $share) {
                        try {
                                // Only restore if share is in given path.
-                               $pathToCheck = '/' . trim($path) . '/';
+                               $pathToCheck = '/';
+                               if (trim($path, '/') !== '') {
+                                       $pathToCheck = '/' . trim($path) . '/';
+                               }
                                if (substr($share->getTarget(), 0, strlen($pathToCheck)) !== $pathToCheck) {
                                        continue;
                                }