Skip to content

Commit

Permalink
Merge pull request #47749 from nextcloud/backport/47417/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(files): Create non-existent parents of mountpoints
  • Loading branch information
blizzz authored Sep 5, 2024
2 parents f99f750 + e77ac5c commit 4dfc5f6
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 @@ -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']);
}
}

0 comments on commit 4dfc5f6

Please sign in to comment.