Skip to content

Commit

Permalink
invalidate mount cache after share rename
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 24, 2022
1 parent 719679d commit b065ea3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
4 changes: 3 additions & 1 deletion apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
],
$loader,
$view,
$foldersExistCache
$foldersExistCache,
$this->eventDispatcher,
$user
);

$event = new ShareMountedEvent($mount);
Expand Down
42 changes: 23 additions & 19 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -51,33 +53,35 @@ class SharedMount extends MountPoint implements MoveableMount {
*/
private $recipientView;

/**
* @var string
*/
private $user;
private IUser $user;

/** @var \OCP\Share\IShare */
private $superShare;

/** @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);
}

Expand All @@ -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)) {
Expand All @@ -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(
Expand Down Expand Up @@ -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));
}


Expand Down

0 comments on commit b065ea3

Please sign in to comment.