Skip to content

Commit 09fef8f

Browse files
Merge pull request #47417 from nextcloud/fix/files/create-mountpoint-parents
2 parents 2d2a510 + ebfbe99 commit 09fef8f

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/private/Files/View.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,15 @@ public function getDirectoryContent($directory, $mimetype_filter = '', ?\OCP\Fil
14961496
if ($pos = strpos($relativePath, '/')) {
14971497
//mountpoint inside subfolder add size to the correct folder
14981498
$entryName = substr($relativePath, 0, $pos);
1499+
1500+
// Create parent folders if the mountpoint is inside a subfolder that doesn't exist yet
1501+
if (!isset($files[$entryName]) && $this->mkdir($path . '/' . $entryName) !== false) {
1502+
$info = $this->getFileInfo($path . '/' . $entryName);
1503+
if ($info !== false) {
1504+
$files[$entryName] = $info;
1505+
}
1506+
}
1507+
14991508
if (isset($files[$entryName])) {
15001509
$files[$entryName]->addSubEntry($rootEntry, $mountPoint);
15011510
}

tests/lib/Files/ViewTest.php

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

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

0 commit comments

Comments
 (0)