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

[stable28] fix(files): Create non-existent parents of mountpoints #47749

Merged
merged 1 commit into from
Sep 5, 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 @@ -1527,6 +1527,15 @@ public function getDirectoryContent($directory, $mimetype_filter = '', \OCP\File
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 @@ -2742,4 +2742,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