Skip to content

Commit f4ddbb2

Browse files
GhassenKefibackportbot[bot]
authored andcommitted
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> [skip ci]
1 parent 9921e8c commit f4ddbb2

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
@@ -1902,32 +1902,29 @@ private function targetIsNotShared(string $user, string $targetPath): bool {
19021902
$providers = [
19031903
IShare::TYPE_USER,
19041904
IShare::TYPE_GROUP,
1905+
IShare::TYPE_LINK,
19051906
IShare::TYPE_EMAIL,
19061907
IShare::TYPE_CIRCLE,
19071908
IShare::TYPE_ROOM,
19081909
IShare::TYPE_DECK,
19091910
];
19101911
$shareManager = Server::get(IManager::class);
1911-
/** @var IShare[] $shares */
1912-
$shares = array_merge(...array_map(function (int $type) use ($shareManager, $user) {
1913-
return $shareManager->getSharesBy($user, $type);
1914-
}, $providers));
1912+
$rootFolder = Server::get(IRootFolder::class);
1913+
$userFolderPath = '/' . $user . '/files';
19151914

1916-
foreach ($shares as $share) {
1915+
for ($path = $targetPath; str_starts_with($path, $userFolderPath . '/'); $path = dirname($path)) {
19171916
try {
1918-
$sharedPath = $share->getNode()->getPath();
1919-
} catch (NotFoundException $e) {
1920-
// node is not found, ignoring
1921-
$this->logger->debug(
1922-
'Could not find the node linked to a share',
1923-
['app' => 'files', 'exception' => $e]);
1917+
$node = $rootFolder->get($path);
1918+
} catch (NotFoundException) {
19241919
continue;
19251920
}
1926-
if ($targetPath === $sharedPath || str_starts_with($targetPath, $sharedPath . '/')) {
1927-
$this->logger->debug(
1928-
'It is not allowed to move one mount point into a shared folder',
1929-
['app' => 'files']);
1930-
return false;
1921+
foreach ($providers as $type) {
1922+
if ($shareManager->getSharesBy($user, $type, $node, false, 1) !== []) {
1923+
$this->logger->debug(
1924+
'It is not allowed to move one mount point into a shared folder',
1925+
['app' => 'files']);
1926+
return false;
1927+
}
19311928
}
19321929
}
19331930

‎tests/lib/Files/ViewTest.php‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\Files\GenericFileException;
3232
use OCP\Files\InvalidPathException;
3333
use OCP\Files\Mount\IMountManager;
34+
use OCP\Files\Node;
3435
use OCP\Files\NotFoundException;
3536
use OCP\Files\Storage\IStorage;
3637
use OCP\Files\Storage\IStorageFactory;
@@ -1790,6 +1791,46 @@ public function testMoveMountPointIntoSharedFolder(): void {
17901791
$userObject->delete();
17911792
}
17921793

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

0 commit comments

Comments
 (0)