fix: properly remove mount with moved child-shares

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2026-04-20 20:27:25 +02:00
parent b96a1c82a2
commit 1a48f760dd
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
2 changed files with 19 additions and 1 deletions

View file

@ -12,6 +12,8 @@ use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
class ShareRecipientUpdater {
@ -22,6 +24,7 @@ class ShareRecipientUpdater {
private readonly MountProvider $shareMountProvider,
private readonly ShareTargetValidator $shareTargetValidator,
private readonly IStorageFactory $storageFactory,
private readonly IManager $shareManager,
) {
}
@ -85,7 +88,12 @@ class ShareRecipientUpdater {
* Process a single deleted share for a user
*/
public function updateForDeletedShare(IUser $user, IShare $share): void {
$this->userMountCache->removeMount($this->getMountPointFromTarget($user, $share->getTarget()), $user);
try {
$userShare = $this->shareManager->getShareById($share->getFullId(), $user->getUID());
$this->userMountCache->removeMount($this->getMountPointFromTarget($user, $userShare->getTarget()), $user);
} catch (ShareNotFound) {
// user doesn't actually have access to the share
}
}
/**

View file

@ -17,6 +17,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
use OCP\Share\IManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
@ -29,6 +30,7 @@ class ShareRecipientUpdaterTest extends \Test\TestCase {
private ShareTargetValidator&MockObject $shareTargetValidator;
private IStorageFactory&MockObject $storageFactory;
private ShareRecipientUpdater $updater;
private IManager $shareManager;
protected function setUp(): void {
parent::setUp();
@ -37,12 +39,14 @@ class ShareRecipientUpdaterTest extends \Test\TestCase {
$this->shareMountProvider = $this->createMock(MountProvider::class);
$this->shareTargetValidator = $this->createMock(ShareTargetValidator::class);
$this->storageFactory = $this->createMock(IStorageFactory::class);
$this->shareManager = $this->createMock(IManager::class);
$this->updater = new ShareRecipientUpdater(
$this->userMountCache,
$this->shareMountProvider,
$this->shareTargetValidator,
$this->storageFactory,
$this->shareManager,
);
}
@ -192,8 +196,14 @@ class ShareRecipientUpdaterTest extends \Test\TestCase {
->willReturn('/target');
$share->method('getNodeId')
->willReturn(111);
$share->method('getFullId')
->willReturn('id');
$user1 = $this->createUser('user1', '');
$this->shareManager->method('getShareById')
->with('id')
->willReturn($share);
$this->shareTargetValidator->expects($this->never())
->method('verifyMountPoint');