diff options
author | Robin Appelman <robin@icewind.nl> | 2024-03-07 11:59:53 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-05-01 16:46:06 +0200 |
commit | ccd56672e80665a78bb89f9606367ba7797e4b45 (patch) | |
tree | bf7aebf617166ec5bff686e056a4b860a4559923 /apps/files_sharing | |
parent | d82fb01b0a103777e7d999ecc48b8d63cfb7e802 (diff) | |
download | nextcloud-server-ccd56672e80665a78bb89f9606367ba7797e4b45.tar.gz nextcloud-server-ccd56672e80665a78bb89f9606367ba7797e4b45.zip |
refactor: remove non-shallow getSharesInFolder
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/Updater.php | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php index 95a5c9d9166..8d3161ad870 100644 --- a/apps/files_sharing/lib/Updater.php +++ b/apps/files_sharing/lib/Updater.php @@ -26,9 +26,11 @@ */ namespace OCA\Files_Sharing; +use OC\Files\Cache\FileAccess; use OC\Files\Mount\MountPoint; use OCP\Constants; use OCP\Files\Folder; +use OCP\Server; use OCP\Share\IShare; class Updater { @@ -58,20 +60,40 @@ class Updater { if ($userFolder === null) { return; } + $user = $userFolder->getOwner(); + if (!$user) { + throw new \Exception("user folder has no owner"); + } $src = $userFolder->get($path); $shareManager = \OC::$server->getShareManager(); // FIXME: should CIRCLES be included here ?? - $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_USER, $src, false, -1); - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_GROUP, $src, false, -1)); - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1)); + $shares = $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER, $src, false, -1); + $shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP, $src, false, -1)); + $shares = array_merge($shares, $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM, $src, false, -1)); if ($src instanceof Folder) { - $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false); + $cacheAccess = Server::get(FileAccess::class); + + $sourceStorageId = $src->getStorage()->getCache()->getNumericStorageId(); + $sourceInternalPath = $src->getInternalPath(); + $subShares = array_merge( + $shareManager->getSharesBy($user->getUID(), IShare::TYPE_USER), + $shareManager->getSharesBy($user->getUID(), IShare::TYPE_GROUP), + $shareManager->getSharesBy($user->getUID(), IShare::TYPE_ROOM), + ); + $shareSourceIds = array_map(fn (IShare $share) => $share->getNodeId(), $subShares); + $shareSources = $cacheAccess->getByFileIdsInStorage($shareSourceIds, $sourceStorageId); foreach ($subShares as $subShare) { - $shares = array_merge($shares, array_values($subShare)); + $shareCacheEntry = $shareSources[$subShare->getNodeId()] ?? null; + if ( + $shareCacheEntry && + str_starts_with($shareCacheEntry->getPath(), $sourceInternalPath . '/') + ) { + $shares[] = $subShare; + } } } |