Skip to content

Commit 279ede5

Browse files
committed
fix(files): consider all shares of the target when moving mount points
Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
1 parent 27e9d2a commit 279ede5

2 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎lib/private/Files/View.php‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,32 +1893,29 @@ private function targetIsNotShared(string $user, string $targetPath): bool {
18931893
$providers = [
18941894
IShare::TYPE_USER,
18951895
IShare::TYPE_GROUP,
1896+
IShare::TYPE_LINK,
18961897
IShare::TYPE_EMAIL,
18971898
IShare::TYPE_CIRCLE,
18981899
IShare::TYPE_ROOM,
18991900
IShare::TYPE_DECK,
19001901
];
19011902
$shareManager = Server::get(IManager::class);
1902-
/** @var IShare[] $shares */
1903-
$shares = array_merge(...array_map(function (int $type) use ($shareManager, $user) {
1904-
return $shareManager->getSharesBy($user, $type);
1905-
}, $providers));
1903+
$rootFolder = Server::get(IRootFolder::class);
1904+
$userFolderPath = '/' . $user . '/files';
19061905

1907-
foreach ($shares as $share) {
1906+
for ($path = $targetPath; str_starts_with($path, $userFolderPath . '/'); $path = dirname($path)) {
19081907
try {
1909-
$sharedPath = $share->getNode()->getPath();
1910-
} catch (NotFoundException $e) {
1911-
// node is not found, ignoring
1912-
$this->logger->debug(
1913-
'Could not find the node linked to a share',
1914-
['app' => 'files', 'exception' => $e]);
1908+
$node = $rootFolder->get($path);
1909+
} catch (NotFoundException) {
19151910
continue;
19161911
}
1917-
if ($targetPath === $sharedPath || str_starts_with($targetPath, $sharedPath . '/')) {
1918-
$this->logger->debug(
1919-
'It is not allowed to move one mount point into a shared folder',
1920-
['app' => 'files']);
1921-
return false;
1912+
foreach ($providers as $type) {
1913+
if ($shareManager->getSharesBy($user, $type, $node, false, 1) !== []) {
1914+
$this->logger->debug(
1915+
'It is not allowed to move one mount point into a shared folder',
1916+
['app' => 'files']);
1917+
return false;
1918+
}
19221919
}
19231920
}
19241921

‎tests/lib/Files/ViewTest.php‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\Files\InvalidPathException;
3333
use OCP\Files\IRootFolder;
3434
use OCP\Files\Mount\IMountManager;
35+
use OCP\Files\Node;
3536
use OCP\Files\NotFoundException;
3637
use OCP\Files\Storage\IStorage;
3738
use OCP\Files\Storage\IStorageFactory;
@@ -1782,6 +1783,46 @@ public function testMoveMountPointIntoSharedFolder(): void {
17821783
$userObject->delete();
17831784
}
17841785

1786+
public function testMoveMountPointIntoLinkSharedFolder(): void {
1787+
self::loginAsUser(self::$user);
1788+
1789+
[$mount1] = $this->createTestMovableMountPoints([
1790+
self::$user . '/files/mount1',
1791+
]);
1792+
$mount1->expects($this->never())
1793+
->method('moveMount');
1794+
1795+
$view = new View('/' . self::$user . '/files/');
1796+
$userFolder = Server::get(IRootFolder::class)->getUserFolder(self::$user);
1797+
$shareManager = Server::get(IShareManager::class);
1798+
$shares = [];
1799+
// More links than a single page of shares, created before the shared target
1800+
for ($i = 0; $i <= 50; $i++) {
1801+
$view->mkdir('other' . $i);
1802+
$shares[] = $this->createLinkShare($shareManager, $userFolder->get('other' . $i));
1803+
}
1804+
$view->mkdir('linkdir');
1805+
$shares[] = $this->createLinkShare($shareManager, $userFolder->get('linkdir'));
1806+
1807+
try {
1808+
$this->expectException(ForbiddenException::class);
1809+
$view->rename('mount1', 'linkdir/mount1');
1810+
} finally {
1811+
foreach ($shares as $share) {
1812+
$shareManager->deleteShare($share);
1813+
}
1814+
}
1815+
}
1816+
1817+
private function createLinkShare(IShareManager $shareManager, Node $node): IShare {
1818+
$share = $shareManager->newShare();
1819+
$share->setSharedBy(self::$user)
1820+
->setShareType(IShare::TYPE_LINK)
1821+
->setPermissions(Constants::PERMISSION_READ)
1822+
->setNode($node);
1823+
return $shareManager->createShare($share);
1824+
}
1825+
17851826
public static function basicOperationProviderForLocks(): array {
17861827
return [
17871828
// --- write hook ----

0 commit comments

Comments
 (0)