From 3581577aec54c5e845bc521aa813e6f151edaa03 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 3 Feb 2026 16:00:35 +0100 Subject: [PATCH] refactor(mount-provider): Refactor share mount provider - Add more precise types - Remove dead code Signed-off-by: Carl Schwan --- .../lib/Config/ConfigAdapter.php | 6 +-- apps/files_sharing/lib/MountProvider.php | 53 +++++++------------ build/psalm-baseline.xml | 2 - .../Files/Mount/CacheMountProvider.php | 26 +++------ lib/public/Files/Config/IMountProvider.php | 5 +- 5 files changed, 27 insertions(+), 65 deletions(-) diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php index 49c085a8208..6a306c0f117 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/apps/files_external/lib/Config/ConfigAdapter.php @@ -134,11 +134,7 @@ class ConfigAdapter implements IMountProvider, IAuthoritativeMountProvider, IPar }, $storages, $storageConfigs); } - /** - * Get all mountpoints applicable for the user - * - * @return IMountPoint[] - */ + #[Override] public function getMountsForUser(IUser $user, IStorageFactory $loader): array { $this->userStoragesService->setUser($user); $this->userGlobalStoragesService->setUser($user); diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index e9575dbac26..5609d12faad 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -24,34 +24,24 @@ use OCP\IUser; use OCP\Share\IAttributes; use OCP\Share\IManager; use OCP\Share\IShare; +use Override; use Psr\Log\LoggerInterface; use function count; class MountProvider implements IMountProvider, IPartialMountProvider { - /** - * @param IConfig $config - * @param IManager $shareManager - * @param LoggerInterface $logger - */ public function __construct( - protected IConfig $config, - protected IManager $shareManager, - protected LoggerInterface $logger, - protected IEventDispatcher $eventDispatcher, - protected ICacheFactory $cacheFactory, - protected IMountManager $mountManager, + protected readonly IConfig $config, + protected readonly IManager $shareManager, + protected readonly LoggerInterface $logger, + protected readonly IEventDispatcher $eventDispatcher, + protected readonly ICacheFactory $cacheFactory, + protected readonly IMountManager $mountManager, ) { } - /** - * Get all mountpoints applicable for the user and check for shares where we need to update the etags - * - * @param IUser $user - * @param IStorageFactory $loader - * @return IMountPoint[] - */ - public function getMountsForUser(IUser $user, IStorageFactory $loader) { + #[Override] + public function getMountsForUser(IUser $user, IStorageFactory $loader): array { return array_values($this->getMountsFromSuperShares($user, $this->getSuperSharesForUser($user), $loader)); } @@ -77,7 +67,7 @@ class MountProvider implements IMountProvider, IPartialMountProvider { * Groups shares by path (nodeId) and target path * * @param iterable $shares - * @return IShare[][] array of grouped shares, each element in the + * @return list> array of grouped shares, each element in the * array is a group which itself is an array of shares */ private function groupShares(iterable $shares): array { @@ -98,9 +88,9 @@ class MountProvider implements IMountProvider, IPartialMountProvider { $aTime = $a->getShareTime()->getTimestamp(); $bTime = $b->getShareTime()->getTimestamp(); if ($aTime === $bTime) { - return $a->getId() < $b->getId() ? -1 : 1; + return $a->getId() <=> $b->getId(); } - return $aTime < $bTime ? -1 : 1; + return $aTime <=> $bTime; }); $result[] = $tmp2; } @@ -117,7 +107,6 @@ class MountProvider implements IMountProvider, IPartialMountProvider { * possible. * * @param iterable $allShares - * @param IUser $user user * @return list}> Tuple of [superShare, groupedShares] */ private function buildSuperShares(iterable $allShares, IUser $user): array { @@ -205,8 +194,6 @@ class MountProvider implements IMountProvider, IPartialMountProvider { * DB queries to retrieve the same information. * * @param array $shares - * @param IShare $superShare - * @return void */ private function combineNotes( array &$shares, @@ -251,11 +238,8 @@ class MountProvider implements IMountProvider, IPartialMountProvider { } } /** - * @param string $userId * @param list}> $superShares - * @param IStorageFactory $loader - * @param IUser $user - * @return array IMountPoint indexed by mount point + * @return array indexed by mount point * @throws Exception */ public function getMountsFromSuperShares( @@ -266,11 +250,8 @@ class MountProvider implements IMountProvider, IPartialMountProvider { $userId = $user->getUID(); $allMounts = $this->mountManager->getAll(); $mounts = []; - $view = new View('/' . $userId . '/files'); $ownerViews = []; $sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($userId); - /** @var CappedMemoryCache $folderExistCache */ - $foldersExistCache = new CappedMemoryCache(); $validShareCache = $this->cacheFactory->createLocal('share-valid-mountpoint-max'); $maxValidatedShare = $validShareCache->get($userId) ?? 0; @@ -293,7 +274,7 @@ class MountProvider implements IMountProvider, IPartialMountProvider { } $shareId = (int)$parentShare->getId(); $mount = new SharedMount( - '\OCA\Files_Sharing\SharedStorage', + SharedStorage::class, [ 'user' => $userId, // parent share @@ -354,6 +335,7 @@ class MountProvider implements IMountProvider, IPartialMountProvider { } } + #[Override] public function getMountsForPath( string $setupPathHint, bool $forChildren, @@ -394,8 +376,9 @@ class MountProvider implements IMountProvider, IPartialMountProvider { } /** - * @param iterable ...$iterables - * @return iterable + * @template T + * @param iterable ...$iterables + * @return iterable */ private function mergeIterables(...$iterables): iterable { foreach ($iterables as $iterable) { diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 5216a3ef432..2eb56483800 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1627,11 +1627,9 @@ - - diff --git a/lib/private/Files/Mount/CacheMountProvider.php b/lib/private/Files/Mount/CacheMountProvider.php index 27c7eec9da3..5f511701a5e 100644 --- a/lib/private/Files/Mount/CacheMountProvider.php +++ b/lib/private/Files/Mount/CacheMountProvider.php @@ -11,33 +11,19 @@ use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; use OCP\IUser; +use Override; /** * Mount provider for custom cache storages */ class CacheMountProvider implements IMountProvider { - /** - * @var IConfig - */ - private $config; - - /** - * ObjectStoreHomeMountProvider constructor. - * - * @param IConfig $config - */ - public function __construct(IConfig $config) { - $this->config = $config; + public function __construct( + private readonly IConfig $config, + ) { } - /** - * Get the cache mount for a user - * - * @param IUser $user - * @param IStorageFactory $loader - * @return \OCP\Files\Mount\IMountPoint[] - */ - public function getMountsForUser(IUser $user, IStorageFactory $loader) { + #[Override] + public function getMountsForUser(IUser $user, IStorageFactory $loader): array { $cacheBaseDir = $this->config->getSystemValueString('cache_path', ''); if ($cacheBaseDir !== '') { $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); diff --git a/lib/public/Files/Config/IMountProvider.php b/lib/public/Files/Config/IMountProvider.php index b59813a866d..189f9c07e7a 100644 --- a/lib/public/Files/Config/IMountProvider.php +++ b/lib/public/Files/Config/IMountProvider.php @@ -7,6 +7,7 @@ */ namespace OCP\Files\Config; +use OCP\Files\Mount\IMountPoint; use OCP\Files\Storage\IStorageFactory; use OCP\IUser; @@ -18,9 +19,7 @@ interface IMountProvider { /** * Get all mountpoints applicable for the user * - * @param \OCP\IUser $user - * @param \OCP\Files\Storage\IStorageFactory $loader - * @return \OCP\Files\Mount\IMountPoint[] + * @return list * @since 8.0.0 */ public function getMountsForUser(IUser $user, IStorageFactory $loader);