Skip to content

Commit

Permalink
Merge pull request #40312 from nextcloud/bugfix/noid/non-existing-nod…
Browse files Browse the repository at this point in the history
…e-parent
  • Loading branch information
juliusknorr authored Sep 13, 2023
2 parents 165c54d + 7f958e8 commit 1137b7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/lib/Files/Node/NodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 1137b7a

Please sign in to comment.