Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files): Create non-existent parents of mountpoints #47417

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,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']);
}
}
Loading