Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\ICacheFactory;
Expand All @@ -32,6 +33,7 @@ public function __construct(
protected LoggerInterface $logger,
protected IEventDispatcher $eventDispatcher,
protected ICacheFactory $cacheFactory,
protected IMountManager $mountManager,
) {
}

Expand All @@ -58,12 +60,18 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {

$superShares = $this->buildSuperShares($shares, $user);

$otherMounts = $this->mountManager->getAll();
$mounts = [];
$view = new View('/' . $user->getUID() . '/files');
$ownerViews = [];
$sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID());
/** @var CappedMemoryCache<bool> $folderExistCache */
$foldersExistCache = new CappedMemoryCache();

$validShareCache = $this->cacheFactory->createLocal('share-valid-mountpoint-max');
$maxValidatedShare = $validShareCache->get($user->getUID()) ?? 0;
$newMaxValidatedShare = $maxValidatedShare;

foreach ($superShares as $share) {
try {
/** @var IShare $parentShare */
Expand All @@ -80,9 +88,10 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
if (!isset($ownerViews[$owner])) {
$ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files');
}
$shareId = (int)$parentShare->getId();
$mount = new SharedMount(
'\OCA\Files_Sharing\SharedStorage',
$mounts,
array_merge($mounts, $otherMounts),
[
'user' => $user->getUID(),
// parent share
Expand All @@ -97,9 +106,11 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$foldersExistCache,
$this->eventDispatcher,
$user,
$this->cacheFactory->createLocal('share-valid-mountpoint')
($shareId <= $maxValidatedShare),
);

$newMaxValidatedShare = max($shareId, $newMaxValidatedShare);

$event = new ShareMountedEvent($mount);
$this->eventDispatcher->dispatchTyped($event);

Expand All @@ -118,6 +129,8 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
}
}

$validShareCache->set($user->getUID(), $newMaxValidatedShare, 24 * 60 * 60);

// array_filter removes the null values from the array
return array_values(array_filter($mounts));
}
Expand Down
21 changes: 9 additions & 12 deletions apps/files_sharing/lib/SharedMount.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\Storage\IStorageFactory;
use OCP\ICache;
use OCP\IUser;
use OCP\Server;
use OCP\Share\Events\VerifyMountPointEvent;
Expand Down Expand Up @@ -47,13 +46,19 @@ public function __construct(
CappedMemoryCache $folderExistCache,
private IEventDispatcher $eventDispatcher,
private IUser $user,
private ICache $cache,
bool $alreadyVerified,
) {
$this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares'];

$newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
$absMountPoint = '/' . $user->getUID() . '/files' . $newMountPoint;
$absMountPoint = '/' . $user->getUID() . '/files/' . trim($this->superShare->getTarget(), '/') . '/';

// after the mountpoint is verified for the first time, only new mountpoints (e.g. groupfolders can overwrite the target)
if (!$alreadyVerified || isset($mountpoints[$absMountPoint])) {
$newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
$absMountPoint = '/' . $user->getUID() . '/files/' . trim($newMountPoint, '/') . '/';
}

parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class);
}

Expand All @@ -70,12 +75,6 @@ private function verifyMountPoint(
array $mountpoints,
CappedMemoryCache $folderExistCache,
) {
$cacheKey = $this->user->getUID() . '/' . $share->getId() . '/' . $share->getTarget();
$cached = $this->cache->get($cacheKey);
if ($cached !== null) {
return $cached;
}

$mountPoint = basename($share->getTarget());
$parent = dirname($share->getTarget());

Expand Down Expand Up @@ -104,8 +103,6 @@ private function verifyMountPoint(
$this->updateFileTarget($newMountPoint, $share);
}

$this->cache->set($cacheKey, $newMountPoint, 60 * 60);

return $newMountPoint;
}

Expand Down
4 changes: 3 additions & 1 deletion apps/files_sharing/tests/MountProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCA\Files_Sharing\MountProvider;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorageFactory;
use OCP\ICacheFactory;
use OCP\IConfig;
Expand Down Expand Up @@ -55,8 +56,9 @@ protected function setUp(): void {
$cacheFactory = $this->createMock(ICacheFactory::class);
$cacheFactory->method('createLocal')
->willReturn(new NullCache());
$mountManager = $this->createMock(IMountManager::class);

$this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher, $cacheFactory);
$this->provider = new MountProvider($this->config, $this->shareManager, $this->logger, $eventDispatcher, $cacheFactory, $mountManager);
}

private function makeMockShareAttributes($attrs) {
Expand Down
Loading