Browse Source

fix: Pass parent to NonExistingFile instances

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Julius Härtl 8 months ago
parent
commit
7f958e81d3
2 changed files with 11 additions and 3 deletions
  1. 10 1
      lib/private/Files/Node/Node.php
  2. 1 2
      tests/lib/Files/Node/NodeTest.php

+ 10 - 1
lib/private/Files/Node/Node.php

@@ -297,10 +297,19 @@ class Node implements INode {
 				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

+ 1 - 2
tests/lib/Files/Node/NodeTest.php

@@ -481,8 +481,7 @@ abstract class NodeTest extends \Test\TestCase {
 		$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]