Skip to content

Commit

Permalink
fix: try to find non-recursive share source
Browse files Browse the repository at this point in the history
instead of always picking the first one, try to find one that won't blow up

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and GretaD committed Aug 19, 2024
1 parent 6ac4f32 commit f3d8b1f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,29 @@ private function init() {
$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(),
Expand Down

0 comments on commit f3d8b1f

Please sign in to comment.