From 991349ab1a726f03bbf21d3203ce87172de07736 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 26 Apr 2022 17:18:16 +0200 Subject: [PATCH] do shallow compare when removing cached mount for user Signed-off-by: Robin Appelman --- lib/private/Files/Config/UserMountCache.php | 25 ++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 666ba9b065b28..1f040ae0d9cdb 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -26,6 +26,7 @@ * along with this program. If not, see * */ + namespace OC\Files\Config; use OC\Cache\CappedMemoryCache; @@ -56,12 +57,7 @@ class UserMountCache implements IUserMountCache { */ private $userManager; - /** - * Cached mount info. - * Map of $userId to ICachedMountInfo. - * - * @var ICache - **/ + /** @var CappedMemoryCache */ private $mountsForUsers; private LoggerInterface $logger; @@ -104,7 +100,9 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC $cachedMounts = $this->getMountsForUser($user); if (is_array($mountProviderClasses)) { - $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses) { + $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ( + $mountProviderClasses + ) { return in_array($mountInfo->getMountProvider(), $mountProviderClasses); }); } @@ -113,7 +111,9 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC }, $cachedMounts); $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); + /** @var ICachedMountInfo[] $addedMounts */ $addedMounts = []; + /** @var ICachedMountInfo[] $removedMounts */ $removedMounts = []; foreach ($newMounts as $rootId => $newMount) { @@ -136,8 +136,13 @@ public function registerMounts(IUser $user, array $mounts, array $mountProviderC } foreach ($removedMounts as $mount) { $this->removeFromCache($mount); - $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); - unset($this->mountsForUsers[$user->getUID()][$index]); + foreach ($this->mountsForUsers[$user->getUID()] as $index => $mountForUser) { + /** @var ICachedMountInfo $mountForUser */ + if ($mount->getRootId() == $mountForUser->getRootId() && $mount->getMountPoint() == $mountForUser->getMountPoint()) { + unset($this->mountsForUsers[$user->getUID()][$index]); + break; + } + } } foreach ($changedMounts as $mount) { $this->updateCachedMount($mount); @@ -313,7 +318,7 @@ private function getCacheInfoFromFileId($fileId): array { $this->cacheInfoCache[$fileId] = [ (int)$row['storage'], (string)$row['path'], - (int)$row['mimetype'] + (int)$row['mimetype'], ]; } else { throw new NotFoundException('File with id "' . $fileId . '" not found');