Skip to content
Closed
Prev Previous commit
fix: Use getRelativePath method to check if node is inside folder
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>

[skip ci]
  • Loading branch information
come-nc authored and backportbot[bot] committed Dec 3, 2024
commit 99b254bf312e292957495f157ea1e7977cf623f9
3 changes: 2 additions & 1 deletion lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,8 @@ protected function promoteReshares(IShare $share): void {
/* Ignore share of non-existing node */
continue;
}
if (str_starts_with($path, $node->getPath() . '/') || ($path === $node->getPath())) {
if ($node->getRelativePath($path) !== null) {
/* If relative path is not null it means the shared node is the same or in a subfolder */
$reshareRecords[] = $share;
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use DateTimeZone;
use OC\Files\Mount\MoveableMount;
use OC\Files\Utils\PathHelper;
use OC\KnownUser\KnownUserService;
use OC\Share20\DefaultShareProvider;
use OC\Share20\Exception;
Expand Down Expand Up @@ -213,6 +214,14 @@ private function createManagerMock() {
]);
}

private function createFolderMock(string $folderPath): MockObject&Folder {
$folder = $this->createMock(Folder::class);
$folder->method('getPath')->willReturn($folderPath);
$folder->method('getRelativePath')->willReturnCallback(
fn (string $path): ?string => PathHelper::getRelativePath($folderPath, $path)
);
return $folder;
}

public function testDeleteNoShareId() {
$this->expectException(\InvalidArgumentException::class);
Expand Down