From b065ea318d7c81ed612fee5eb924cbf6b14bd49f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 24 Mar 2022 16:18:34 +0100 Subject: [PATCH] invalidate mount cache after share rename Signed-off-by: Robin Appelman --- apps/files_sharing/lib/MountProvider.php | 4 ++- apps/files_sharing/lib/SharedMount.php | 42 +++++++++++++----------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php index 102e5d9655901..27edf5074e1c8 100644 --- a/apps/files_sharing/lib/MountProvider.php +++ b/apps/files_sharing/lib/MountProvider.php @@ -134,7 +134,9 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) { ], $loader, $view, - $foldersExistCache + $foldersExistCache, + $this->eventDispatcher, + $user ); $event = new ShareMountedEvent($mount); diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index c8f5d0f64ae56..60361e25fd023 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -34,7 +34,9 @@ use OC\Files\Mount\MoveableMount; use OC\Files\View; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; use OCP\Share\Events\VerifyMountPointEvent; /** @@ -51,10 +53,7 @@ class SharedMount extends MountPoint implements MoveableMount { */ private $recipientView; - /** - * @var string - */ - private $user; + private IUser $user; /** @var \OCP\Share\IShare */ private $superShare; @@ -62,22 +61,27 @@ class SharedMount extends MountPoint implements MoveableMount { /** @var \OCP\Share\IShare[] */ private $groupedShares; - /** - * @param string $storage - * @param SharedMount[] $mountpoints - * @param array $arguments - * @param IStorageFactory $loader - * @param View $recipientView - */ - public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { - $this->user = $arguments['user']; + private IEventDispatcher $eventDispatcher; + + public function __construct( + $storage, + array $mountpoints, + $arguments, + IStorageFactory $loader, + View $recipientView, + CappedMemoryCache $folderExistCache, + IEventDispatcher $eventDispatcher, + IUser $user + ) { + $this->user = $user; $this->recipientView = $recipientView; + $this->eventDispatcher = $eventDispatcher; $this->superShare = $arguments['superShare']; $this->groupedShares = $arguments['groupedShares']; $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; + $absMountPoint = '/' . $user->getUID() . '/files' . $newMountPoint; parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class); } @@ -93,9 +97,7 @@ private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, $parent = dirname($share->getTarget()); $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); - /** @var IEventDispatcher $dispatcher */ - $dispatcher = \OC::$server->query(IEventDispatcher::class); - $dispatcher->dispatchTyped($event); + $this->eventDispatcher->dispatchTyped($event); $parent = $event->getParent(); if ($folderExistCache->hasKey($parent)) { @@ -105,7 +107,7 @@ private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, $folderExistCache->set($parent, $parentExists); } if (!$parentExists) { - $parent = Helper::getShareFolder($this->recipientView, $this->user); + $parent = Helper::getShareFolder($this->recipientView, $this->user->getUID()); } $newMountPoint = $this->generateUniqueTarget( @@ -133,8 +135,10 @@ private function updateFileTarget($newPath, &$share) { foreach ($this->groupedShares as $tmpShare) { $tmpShare->setTarget($newPath); - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user->getUID()); } + + $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent($this->user)); }