-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: perform share mount validation on share instead of on mount #57295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+463
−400
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d71c679
feat: perform share mount validation on share instead of on mount
icewind1991 43a9335
fix: attempt to make share conflict resolution more resilient to fals…
icewind1991 94f3346
test: adjust tests
icewind1991 b431506
perf: only update shares for users once
icewind1991 34fc215
fix: adjust SharesUpdatedListener to event change
icewind1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Robin Appelman <robin@icewind.nl> | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Files_Sharing\Listener; | ||
|
|
||
| use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent; | ||
| use OCA\Files_Sharing\MountProvider; | ||
| use OCA\Files_Sharing\ShareTargetValidator; | ||
| use OCP\Cache\CappedMemoryCache; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
| use OCP\Files\Config\ICachedMountInfo; | ||
| use OCP\Files\Config\IUserMountCache; | ||
| use OCP\Files\Events\Node\FilesystemTornDownEvent; | ||
| use OCP\Group\Events\UserAddedEvent; | ||
| use OCP\Group\Events\UserRemovedEvent; | ||
| use OCP\IUser; | ||
| use OCP\Share\Events\BeforeShareDeletedEvent; | ||
| use OCP\Share\Events\ShareCreatedEvent; | ||
| use OCP\Share\IManager; | ||
|
|
||
| /** | ||
| * Listen to various events that can change what shares a user has access to | ||
| * | ||
| * @template-implements IEventListener<UserAddedEvent|UserRemovedEvent|ShareCreatedEvent|BeforeShareDeletedEvent|UserShareAccessUpdatedEvent|FilesystemTornDownEvent> | ||
| */ | ||
| class SharesUpdatedListener implements IEventListener { | ||
| private CappedMemoryCache $updatedUsers; | ||
|
|
||
| public function __construct( | ||
| private readonly IManager $shareManager, | ||
| private readonly IUserMountCache $userMountCache, | ||
| private readonly MountProvider $shareMountProvider, | ||
| private readonly ShareTargetValidator $shareTargetValidator, | ||
| ) { | ||
| $this->updatedUsers = new CappedMemoryCache(); | ||
| } | ||
| public function handle(Event $event): void { | ||
| if ($event instanceof FilesystemTornDownEvent) { | ||
| $this->updatedUsers = new CappedMemoryCache(); | ||
| } | ||
| if ($event instanceof UserShareAccessUpdatedEvent) { | ||
| foreach ($event->getUsers() as $user) { | ||
| $this->updateForUser($user); | ||
| } | ||
| } | ||
| if ($event instanceof UserAddedEvent || $event instanceof UserRemovedEvent) { | ||
| $this->updateForUser($event->getUser()); | ||
| } | ||
| if ($event instanceof ShareCreatedEvent || $event instanceof BeforeShareDeletedEvent) { | ||
| foreach ($this->shareManager->getUsersForShare($event->getShare()) as $user) { | ||
| $this->updateForUser($user); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private function updateForUser(IUser $user): void { | ||
| if (isset($this->updatedUsers[$user->getUID()])) { | ||
| return; | ||
| } | ||
| $this->updatedUsers[$user->getUID()] = true; | ||
|
|
||
| $cachedMounts = $this->userMountCache->getMountsForUser($user); | ||
| $mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts); | ||
| $mountsByPath = array_combine($mountPoints, $cachedMounts); | ||
|
|
||
| $shares = $this->shareMountProvider->getSuperSharesForUser($user); | ||
|
|
||
| foreach ($shares as &$share) { | ||
| [$parentShare, $groupedShares] = $share; | ||
| $mountPoint = '/' . $user->getUID() . '/files/' . trim($parentShare->getTarget(), '/') . '/'; | ||
| $mountKey = $parentShare->getNodeId() . '::' . $mountPoint; | ||
| if (!isset($cachedMounts[$mountKey])) { | ||
| $this->shareTargetValidator->verifyMountPoint($user, $parentShare, $mountsByPath, $groupedShares); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right that
getSuperSharesForUser()andverifyMountPoint()could take a lot of time?As this been tested on
next.perftesting? Like adding a user, or a group to a talk conversation for example?I am wondering if we should find a way to put that into a background job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is work that was previously done on-mount, so while it can be expensive yes, it's moving the expense from "read" (with some caching) to "write" time.
Putting it in a background job would mean that we can end up mounting the share before we did the conflict resolution. (Unless we do the work to block mounting the share until then)