diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 4b916bd9c1b14..9729f79aae3ca 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -297,10 +297,19 @@ public function getParent(): INode|IRootFolder { return $this->root; } + // Manually fetch the parent if the current node doesn't have a file info yet + try { + $fileInfo = $this->getFileInfo(); + } catch (NotFoundException) { + $this->parent = $this->root->get($newPath); + /** @var \OCP\Files\Folder $this->parent */ + return $this->parent; + } + // gather the metadata we already know about our parent $parentData = [ 'path' => $newPath, - 'fileid' => $this->getFileInfo()->getParentId(), + 'fileid' => $fileInfo->getParentId(), ]; // and create lazy folder with it instead of always querying diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index b63d287a1913f..4f782f28a36e9 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -481,8 +481,7 @@ public function testCopySameStorage() { $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar'); $newNode = $this->createTestNode($this->root, $this->view, '/bar/asd'); - $this->root->expects($this->exactly(2)) - ->method('get') + $this->root->method('get') ->willReturnMap([ ['/bar/asd', $newNode], ['/bar', $parentNode]