Skip to content

Commit 9f1c6d7

Browse files
authored
Merge pull request #47279 from nextcloud/backport/46881/stable28
2 parents edd8a03 + 0571aa1 commit 9f1c6d7

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

apps/files_sharing/lib/SharedStorage.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,29 @@ private function init() {
171171
$this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner());
172172
$sourceId = $this->superShare->getNodeId();
173173
$ownerNodes = $this->ownerUserFolder->getById($sourceId);
174-
/** @var Node|false $ownerNode */
175-
$ownerNode = current($ownerNodes);
176-
if (!$ownerNode) {
174+
175+
if (count($ownerNodes) === 0) {
177176
$this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]);
178177
$this->cache = new FailedCache();
179178
$this->rootPath = '';
180179
} else {
181-
$this->nonMaskedStorage = $ownerNode->getStorage();
182-
if ($this->nonMaskedStorage instanceof Wrapper && $this->nonMaskedStorage->isWrapperOf($this)) {
180+
foreach ($ownerNodes as $ownerNode) {
181+
$nonMaskedStorage = $ownerNode->getStorage();
182+
183+
// check if potential source node would lead to a recursive share setup
184+
if ($nonMaskedStorage instanceof Wrapper && $nonMaskedStorage->isWrapperOf($this)) {
185+
continue;
186+
}
187+
$this->nonMaskedStorage = $nonMaskedStorage;
188+
$this->sourcePath = $ownerNode->getPath();
189+
$this->rootPath = $ownerNode->getInternalPath();
190+
$this->cache = null;
191+
break;
192+
}
193+
if (!$this->nonMaskedStorage) {
194+
// all potential source nodes would have been recursive
183195
throw new \Exception('recursive share detected');
184196
}
185-
$this->sourcePath = $ownerNode->getPath();
186-
$this->rootPath = $ownerNode->getInternalPath();
187197
$this->storage = new PermissionsMask([
188198
'storage' => $this->nonMaskedStorage,
189199
'mask' => $this->superShare->getPermissions(),

0 commit comments

Comments
 (0)