Skip to content

Commit abbd1fb

Browse files
committed
feat: implement authoritative mount provider for share provider
Signed-off-by: Robin Appelman <[email protected]>
1 parent f92e93a commit abbd1fb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\EventDispatcher\IEventListener;
1616
use OCP\Files\Config\ICachedMountInfo;
1717
use OCP\Files\Config\IUserMountCache;
18+
use OCP\Files\Storage\IStorageFactory;
1819
use OCP\Group\Events\UserAddedEvent;
1920
use OCP\Group\Events\UserRemovedEvent;
2021
use OCP\IUser;
@@ -33,6 +34,7 @@ public function __construct(
3334
private readonly IUserMountCache $userMountCache,
3435
private readonly MountProvider $shareMountProvider,
3536
private readonly ShareTargetValidator $shareTargetValidator,
37+
private readonly IStorageFactory $storageFactory,
3638
) {
3739
}
3840

@@ -49,18 +51,26 @@ public function handle(Event $event): void {
4951

5052
private function updateForUser(IUser $user): void {
5153
$cachedMounts = $this->userMountCache->getMountsForUser($user);
54+
$shareMounts = array_filter($cachedMounts, fn (ICachedMountInfo $mount) => $mount->getMountProvider() === MountProvider::class);
5255
$mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts);
5356
$mountsByPath = array_combine($mountPoints, $cachedMounts);
5457

5558
$shares = $this->shareMountProvider->getSuperSharesForUser($user);
5659

60+
$mountsChanged = count($shares) !== count($shareMounts);
5761
foreach ($shares as &$share) {
5862
[$parentShare, $groupedShares] = $share;
5963
$mountPoint = '/' . $user->getUID() . '/files/' . trim($parentShare->getTarget(), '/') . '/';
6064
$mountKey = $parentShare->getNodeId() . '::' . $mountPoint;
6165
if (!isset($cachedMounts[$mountKey])) {
66+
$mountsChanged = true;
6267
$this->shareTargetValidator->verifyMountPoint($user, $parentShare, $mountsByPath, $groupedShares);
6368
}
6469
}
70+
71+
if ($mountsChanged) {
72+
$newMounts = $this->shareMountProvider->getMountsFromSuperShares($user, $shares, $this->storageFactory);
73+
$this->userMountCache->registerMounts($user, $newMounts, [MountProvider::class]);
74+
}
6575
}
6676
}

apps/files_sharing/lib/MountProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Files_Sharing\Event\ShareMountedEvent;
1414
use OCP\Cache\CappedMemoryCache;
1515
use OCP\EventDispatcher\IEventDispatcher;
16+
use OCP\Files\Config\IAuthoritativeMountProvider;
1617
use OCP\Files\Config\IMountProvider;
1718
use OCP\Files\Mount\IMountManager;
1819
use OCP\Files\Mount\IMountPoint;
@@ -26,7 +27,7 @@
2627
use Psr\Log\LoggerInterface;
2728
use function count;
2829

29-
class MountProvider implements IMountProvider {
30+
class MountProvider implements IMountProvider, IAuthoritativeMountProvider {
3031
/**
3132
* @param IConfig $config
3233
* @param IManager $shareManager

0 commit comments

Comments
 (0)