From 74b0139dffca433aac2a3c19bcead22e3f379431 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 25 Sep 2023 18:25:53 +0200 Subject: [PATCH] WIP: enh(IMountManager): Add method to get MountPoint from CachedMountInfo Signed-off-by: Jonas --- apps/workflowengine/lib/Entity/File.php | 17 ++++++++++++++--- lib/private/Files/Mount/Manager.php | 18 ++++++++++++++++++ lib/public/Files/Mount/IMountManager.php | 12 ++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/apps/workflowengine/lib/Entity/File.php b/apps/workflowengine/lib/Entity/File.php index 0f47928eb222a..215e6f349e264 100644 --- a/apps/workflowengine/lib/Entity/File.php +++ b/apps/workflowengine/lib/Entity/File.php @@ -31,6 +31,7 @@ use OCP\EventDispatcher\GenericEvent; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountManager; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IL10N; @@ -74,6 +75,8 @@ class File implements IEntity, IDisplayText, IUrl, IIcon, IContextPortation { private $userManager; /** @var UserMountCache */ private $userMountCache; + /** @var IMountManager */ + private $mountManager; public function __construct( IL10N $l10n, @@ -82,7 +85,8 @@ public function __construct( IUserSession $userSession, ISystemTagManager $tagManager, IUserManager $userManager, - UserMountCache $userMountCache + UserMountCache $userMountCache, + IMountManager $mountManager ) { $this->l10n = $l10n; $this->urlGenerator = $urlGenerator; @@ -91,6 +95,7 @@ public function __construct( $this->tagManager = $tagManager; $this->userManager = $userManager; $this->userMountCache = $userMountCache; + $this->mountManager = $mountManager; } public function getName(): string { @@ -143,12 +148,18 @@ public function isLegitimatedForUserId(string $uid): bool { $fileId = $node->getId(); } - $mounts = $this->userMountCache->getMountsForFileId($fileId, $uid); - foreach ($mounts as $mount) { + $mountInfos = $this->userMountCache->getMountsForFileId($fileId, $uid); + foreach ($mountInfos as $mountInfo) { + $mount = $this->mountManager->getMountFromMountInfo($mountInfo); + if (!empty($mount->getStorage()->getCache()->get($fileId))) { + return true; + } + /* $userFolder = $this->root->getUserFolder($uid); if (!empty($userFolder->getById($fileId))) { return true; } + */ } return false; } catch (NotFoundException $e) { diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index 805cce658a678..6fafd47723fed 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -33,6 +33,7 @@ use OC\Files\Filesystem; use OC\Files\SetupManager; use OC\Files\SetupManagerFactory; +use OCP\Files\Config\ICachedMountInfo; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; @@ -226,4 +227,21 @@ public function getMountsByMountProvider(string $path, array $mountProviders) { }); } } + + /** + * Return the mount matching a cached mount info (or mount file info) + * + * @param ICachedMountInfo $info + * + * @return IMountPoint + * @throws NotFoundException + */ + public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint { + foreach ($this->mounts as $mount) { + if ($mount->getStorageRootId() === $info->getRootId()) { + return $mount; + } + } + throw new NotFoundException("No mount for mount info with rootId " . (string)$info->getRootId()); + } } diff --git a/lib/public/Files/Mount/IMountManager.php b/lib/public/Files/Mount/IMountManager.php index a55e5758199d0..21e5327ce7425 100644 --- a/lib/public/Files/Mount/IMountManager.php +++ b/lib/public/Files/Mount/IMountManager.php @@ -26,6 +26,8 @@ */ namespace OCP\Files\Mount; +use OCP\Files\Config\ICachedMountInfo; + /** * Interface IMountManager * @@ -106,4 +108,14 @@ public function getAll(): array; * @since 8.2.0 */ public function findByNumericId(int $id): array; + + /** + * Return the mount matching a cached mount info (or mount file info) + * + * @param ICachedMountInfo $info + * + * @return IMountPoint + * @since 28.0.0 + */ + public function getMountFromMountInfo(ICachedMountInfo $info): IMountPoint; }