From d6eb127f7670d6f5cb5a8d95db8e0ed954df957a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 11 Sep 2023 15:00:32 +0200 Subject: [PATCH] improve logic for getting the watcher for a shared external storage with the new-ish lazy mount loading the underlying mount might not be loaded yet, so ask the mount cache instead Signed-off-by: Robin Appelman --- apps/files_sharing/lib/SharedStorage.php | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index c56bcaebb1236..b2d06b71437f8 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -39,13 +39,14 @@ use OC\Files\Storage\Common; use OC\Files\Storage\Home; use OC\User\DisplayNameCache; +use OCA\Files_External\Config\ConfigAdapter; +use OCP\Files\Config\IUserMountCache; use OCP\Files\Folder; use OCP\Files\IHomeStorage; use OCP\Files\Node; use OC\Files\Storage\FailedStorage; use OC\Files\Storage\Wrapper\PermissionsMask; use OC\User\NoUserException; -use OCA\Files_External\Config\ExternalMountPoint; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; use OCP\Files\IRootFolder; @@ -431,21 +432,29 @@ public function getOwner($path): string { } public function getWatcher($path = '', $storage = null): Watcher { - $mountManager = \OC::$server->getMountManager(); + if ($this->watcher) { + return $this->watcher; + } // Get node information $node = $this->getShare()->getNodeCacheEntry(); if ($node) { - $mount = $mountManager->findByNumericId($node->getStorageId()); - // If the share is originating from an external storage - if (count($mount) > 0 && $mount[0] instanceof ExternalMountPoint) { - // Propagate original storage scan - return parent::getWatcher($path, $storage); + /** @var IUserMountCache $userMountCache */ + $userMountCache = \OC::$server->get(IUserMountCache::class); + $mounts = $userMountCache->getMountsForStorageId($node->getStorageId()); + foreach ($mounts as $mount) { + // If the share is originating from an external storage + if ($mount->getMountProvider() === ConfigAdapter::class) { + // Propagate original storage scan + $this->watcher = parent::getWatcher($path, $storage); + return $this->watcher; + } } } // cache updating is handled by the share source - return new NullWatcher(); + $this->watcher = new NullWatcher(); + return $this->watcher; } /**