Skip to content

Commit 5faa903

Browse files
authored
Merge pull request #46881 from nextcloud/try-non-recursive-source
fix: try to find non-recursive share source
2 parents abd7514 + 7343da4 commit 5faa903

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

apps/files_sharing/lib/SharedStorage.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,30 @@ private function init() {
145145
$rootFolder = \OC::$server->get(IRootFolder::class);
146146
$this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner());
147147
$sourceId = $this->superShare->getNodeId();
148-
$ownerNode = $this->ownerUserFolder->getFirstNodeById($sourceId);
149-
if (!$ownerNode) {
148+
$ownerNodes = $this->ownerUserFolder->getById($sourceId);
149+
150+
if (count($ownerNodes) === 0) {
150151
$this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]);
151152
$this->cache = new FailedCache();
152153
$this->rootPath = '';
153154
} else {
154-
$this->nonMaskedStorage = $ownerNode->getStorage();
155-
if ($this->nonMaskedStorage instanceof Wrapper && $this->nonMaskedStorage->isWrapperOf($this)) {
155+
foreach ($ownerNodes as $ownerNode) {
156+
$nonMaskedStorage = $ownerNode->getStorage();
157+
158+
// check if potential source node would lead to a recursive share setup
159+
if ($nonMaskedStorage instanceof Wrapper && $nonMaskedStorage->isWrapperOf($this)) {
160+
continue;
161+
}
162+
$this->nonMaskedStorage = $nonMaskedStorage;
163+
$this->sourcePath = $ownerNode->getPath();
164+
$this->rootPath = $ownerNode->getInternalPath();
165+
$this->cache = null;
166+
break;
167+
}
168+
if (!$this->nonMaskedStorage) {
169+
// all potential source nodes would have been recursive
156170
throw new \Exception('recursive share detected');
157171
}
158-
$this->sourcePath = $ownerNode->getPath();
159-
$this->rootPath = $ownerNode->getInternalPath();
160172
$this->storage = new PermissionsMask([
161173
'storage' => $this->nonMaskedStorage,
162174
'mask' => $this->superShare->getPermissions(),

0 commit comments

Comments
 (0)