]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: try to find non-recursive share source 47279/head
authorRobin Appelman <robin@icewind.nl>
Tue, 30 Jul 2024 13:32:07 +0000 (15:32 +0200)
committerRobin Appelman <robin@icewind.nl>
Fri, 16 Aug 2024 14:36:52 +0000 (16:36 +0200)
instead of always picking the first one, try to find one that won't blow up

Signed-off-by: Robin Appelman <robin@icewind.nl>
apps/files_sharing/lib/SharedStorage.php

index 413a4460ad3e80f95ddf6aa45ec1ec5070ae2016..40eb06faa9e906694ec5fdae4026c34077b5f015 100644 (file)
@@ -171,19 +171,29 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
                        $this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner());
                        $sourceId = $this->superShare->getNodeId();
                        $ownerNodes = $this->ownerUserFolder->getById($sourceId);
-                       /** @var Node|false $ownerNode */
-                       $ownerNode = current($ownerNodes);
-                       if (!$ownerNode) {
+
+                       if (count($ownerNodes) === 0) {
                                $this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]);
                                $this->cache = new FailedCache();
                                $this->rootPath = '';
                        } else {
-                               $this->nonMaskedStorage = $ownerNode->getStorage();
-                               if ($this->nonMaskedStorage instanceof Wrapper && $this->nonMaskedStorage->isWrapperOf($this)) {
+                               foreach ($ownerNodes as $ownerNode) {
+                                       $nonMaskedStorage = $ownerNode->getStorage();
+
+                                       // check if potential source node would lead to a recursive share setup
+                                       if ($nonMaskedStorage instanceof Wrapper && $nonMaskedStorage->isWrapperOf($this)) {
+                                               continue;
+                                       }
+                                       $this->nonMaskedStorage = $nonMaskedStorage;
+                                       $this->sourcePath = $ownerNode->getPath();
+                                       $this->rootPath = $ownerNode->getInternalPath();
+                                       $this->cache = null;
+                                       break;
+                               }
+                               if (!$this->nonMaskedStorage) {
+                                       // all potential source nodes would have been recursive
                                        throw new \Exception('recursive share detected');
                                }
-                               $this->sourcePath = $ownerNode->getPath();
-                               $this->rootPath = $ownerNode->getInternalPath();
                                $this->storage = new PermissionsMask([
                                        'storage' => $this->nonMaskedStorage,
                                        'mask' => $this->superShare->getPermissions(),