diff options
author | provokateurin <kate@provokateurin.de> | 2024-08-22 12:04:31 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2024-08-22 12:04:31 +0200 |
commit | ebfbe99652c88574bf8fdb1de830df5e694cfda9 (patch) | |
tree | 8bb5dcb8ec43195ce7350773a1a568a4216d9dbd | |
parent | 0df3a46db2e023de5bdc3b13522b7b32eaeb125e (diff) | |
download | nextcloud-server-ebfbe99652c88574bf8fdb1de830df5e694cfda9.tar.gz nextcloud-server-ebfbe99652c88574bf8fdb1de830df5e694cfda9.zip |
fix(files): Create non-existent parents of mountpoints
Signed-off-by: provokateurin <kate@provokateurin.de>
-rw-r--r-- | lib/private/Files/View.php | 9 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 31 |
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php index 0e5e433ccb6..09e2ba39c10 100644 --- a/lib/private/Files/View.php +++ b/lib/private/Files/View.php @@ -1496,6 +1496,15 @@ class View { 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); } diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 43a25150eaf..379a8389355 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -2743,4 +2743,35 @@ class ViewTest extends \Test\TestCase { $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']); + } } |