]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(files): Create non-existent parents of mountpoints 47749/head
authorprovokateurin <kate@provokateurin.de>
Thu, 22 Aug 2024 10:04:31 +0000 (12:04 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Wed, 4 Sep 2024 18:01:36 +0000 (18:01 +0000)
Signed-off-by: provokateurin <kate@provokateurin.de>
lib/private/Files/View.php
tests/lib/Files/ViewTest.php

index 4aaea23e7f11e2209117da3d20f3a3d66c74989c..a4a68b2f4a7187d54f05f0125c045109324b66a3 100644 (file)
@@ -1527,6 +1527,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);
                                                }
index b9dd49d71fe28765ed839c2d3aed5434f442ed73..ad22a7267e615d21aaddf12d4797c63d62f1c22d 100644 (file)
@@ -2742,4 +2742,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']);
+       }
 }