Skip to content

Commit 8e0880e

Browse files
committed
fix: properly remove mount with moved child-shares
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 0ff1b88 commit 8e0880e

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

apps/files_sharing/lib/ShareRecipientUpdater.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use OCP\Files\Config\IUserMountCache;
1313
use OCP\Files\Storage\IStorageFactory;
1414
use OCP\IUser;
15+
use OCP\Share\Exceptions\ShareNotFound;
16+
use OCP\Share\IManager;
1517
use OCP\Share\IShare;
1618

1719
class ShareRecipientUpdater {
@@ -22,6 +24,7 @@ public function __construct(
2224
private readonly MountProvider $shareMountProvider,
2325
private readonly ShareTargetValidator $shareTargetValidator,
2426
private readonly IStorageFactory $storageFactory,
27+
private readonly IManager $shareManager,
2528
) {
2629
}
2730

@@ -85,7 +88,12 @@ private function getMountPointFromTarget(IUser $user, string $target): string {
8588
* Process a single deleted share for a user
8689
*/
8790
public function updateForDeletedShare(IUser $user, IShare $share): void {
88-
$this->userMountCache->removeMount($this->getMountPointFromTarget($user, $share->getTarget()), $user);
91+
try {
92+
$userShare = $this->shareManager->getShareById($share->getFullId(), $user->getUID());
93+
$this->userMountCache->removeMount($this->getMountPointFromTarget($user, $userShare->getTarget()), $user);
94+
} catch (ShareNotFound) {
95+
// user doesn't actually have access to the share
96+
}
8997
}
9098

9199
/**

apps/files_sharing/tests/ShareRecipientUpdaterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCP\Files\Node;
1818
use OCP\Files\Storage\IStorageFactory;
1919
use OCP\IUser;
20+
use OCP\Share\IManager;
2021
use OCP\Share\IShare;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use Test\Traits\UserTrait;
@@ -29,6 +30,7 @@ class ShareRecipientUpdaterTest extends \Test\TestCase {
2930
private ShareTargetValidator&MockObject $shareTargetValidator;
3031
private IStorageFactory&MockObject $storageFactory;
3132
private ShareRecipientUpdater $updater;
33+
private IManager $shareManager;
3234

3335
protected function setUp(): void {
3436
parent::setUp();
@@ -37,12 +39,14 @@ protected function setUp(): void {
3739
$this->shareMountProvider = $this->createMock(MountProvider::class);
3840
$this->shareTargetValidator = $this->createMock(ShareTargetValidator::class);
3941
$this->storageFactory = $this->createMock(IStorageFactory::class);
42+
$this->shareManager = $this->createMock(IManager::class);
4043

4144
$this->updater = new ShareRecipientUpdater(
4245
$this->userMountCache,
4346
$this->shareMountProvider,
4447
$this->shareTargetValidator,
4548
$this->storageFactory,
49+
$this->shareManager,
4650
);
4751
}
4852

@@ -192,8 +196,14 @@ public function testDeletedShare() {
192196
->willReturn('/target');
193197
$share->method('getNodeId')
194198
->willReturn(111);
199+
$share->method('getFullId')
200+
->willReturn('id');
195201
$user1 = $this->createUser('user1', '');
196202

203+
$this->shareManager->method('getShareById')
204+
->with('id')
205+
->willReturn($share);
206+
197207
$this->shareTargetValidator->expects($this->never())
198208
->method('verifyMountPoint');
199209

0 commit comments

Comments
 (0)