Skip to content

Commit 4dfc5f6

Browse files
authored
Merge pull request #47749 from nextcloud/backport/47417/stable28
[stable28] fix(files): Create non-existent parents of mountpoints
2 parents f99f750 + e77ac5c commit 4dfc5f6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/private/Files/View.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,15 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
15271527
if ($pos = strpos($relativePath, '/')) {
15281528
//mountpoint inside subfolder add size to the correct folder
15291529
$entryName = substr($relativePath, 0, $pos);
1530+
1531+
// Create parent folders if the mountpoint is inside a subfolder that doesn't exist yet
1532+
if (!isset($files[$entryName]) && $this->mkdir($path . '/' . $entryName) !== false) {
1533+
$info = $this->getFileInfo($path . '/' . $entryName);
1534+
if ($info !== false) {
1535+
$files[$entryName] = $info;
1536+
}
1537+
}
1538+
15301539
if (isset($files[$entryName])) {
15311540
$files[$entryName]->addSubEntry($rootEntry, $mountPoint);
15321541
}

tests/lib/Files/ViewTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,4 +2742,35 @@ public function testFopenGone() {
27422742

27432743
$this->assertFalse($cache->inCache('foo.txt'));
27442744
}
2745+
2746+
public function testMountpointParentsCreated() {
2747+
$storage1 = $this->getTestStorage();
2748+
Filesystem::mount($storage1, [], '/');
2749+
2750+
$storage2 = $this->getTestStorage();
2751+
Filesystem::mount($storage2, [], '/A/B/C');
2752+
2753+
$rootView = new View('');
2754+
2755+
$folderData = $rootView->getDirectoryContent('/');
2756+
$this->assertCount(4, $folderData);
2757+
$this->assertEquals('folder', $folderData[0]['name']);
2758+
$this->assertEquals('foo.png', $folderData[1]['name']);
2759+
$this->assertEquals('foo.txt', $folderData[2]['name']);
2760+
$this->assertEquals('A', $folderData[3]['name']);
2761+
2762+
$folderData = $rootView->getDirectoryContent('/A');
2763+
$this->assertCount(1, $folderData);
2764+
$this->assertEquals('B', $folderData[0]['name']);
2765+
2766+
$folderData = $rootView->getDirectoryContent('/A/B');
2767+
$this->assertCount(1, $folderData);
2768+
$this->assertEquals('C', $folderData[0]['name']);
2769+
2770+
$folderData = $rootView->getDirectoryContent('/A/B/C');
2771+
$this->assertCount(3, $folderData);
2772+
$this->assertEquals('folder', $folderData[0]['name']);
2773+
$this->assertEquals('foo.png', $folderData[1]['name']);
2774+
$this->assertEquals('foo.txt', $folderData[2]['name']);
2775+
}
27452776
}

0 commit comments

Comments
 (0)