Skip to content

Commit

Permalink
fix(files): Create non-existent parents of mountpoints
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Sep 4, 2024
1 parent 0f4086c commit 77c3897
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,15 @@ public function getDirectoryContent($directory, $mimetype_filter = '', ?\OCP\Fil
if ($pos = strpos($relativePath, '/')) {
//mountpoint inside subfolder add size to the correct folder
$entryName = substr($relativePath, 0, $pos);

// Create parent folders if the mountpoint is inside a subfolder that doesn't exist yet
if (!isset($files[$entryName]) && $this->mkdir($path . '/' . $entryName) !== false) {
$info = $this->getFileInfo($path . '/' . $entryName);
if ($info !== false) {
$files[$entryName] = $info;
}
}

if (isset($files[$entryName])) {
$files[$entryName]->addSubEntry($rootEntry, $mountPoint);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2743,4 +2743,35 @@ public function testFopenGone() {

$this->assertFalse($cache->inCache('foo.txt'));
}

public function testMountpointParentsCreated() {
$storage1 = $this->getTestStorage();
Filesystem::mount($storage1, [], '/');

$storage2 = $this->getTestStorage();
Filesystem::mount($storage2, [], '/A/B/C');

$rootView = new View('');

$folderData = $rootView->getDirectoryContent('/');
$this->assertCount(4, $folderData);
$this->assertEquals('folder', $folderData[0]['name']);
$this->assertEquals('foo.png', $folderData[1]['name']);
$this->assertEquals('foo.txt', $folderData[2]['name']);
$this->assertEquals('A', $folderData[3]['name']);

$folderData = $rootView->getDirectoryContent('/A');
$this->assertCount(1, $folderData);
$this->assertEquals('B', $folderData[0]['name']);

$folderData = $rootView->getDirectoryContent('/A/B');
$this->assertCount(1, $folderData);
$this->assertEquals('C', $folderData[0]['name']);

$folderData = $rootView->getDirectoryContent('/A/B/C');
$this->assertCount(3, $folderData);
$this->assertEquals('folder', $folderData[0]['name']);
$this->assertEquals('foo.png', $folderData[1]['name']);
$this->assertEquals('foo.txt', $folderData[2]['name']);
}
}

0 comments on commit 77c3897

Please sign in to comment.