Skip to content

Commit

Permalink
add IFileInfo::getParentId
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 14, 2023
1 parent 5bc261b commit dcd9fd9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,8 @@ public function getCreationTime(): int {
public function getUploadTime(): int {
return (int) $this->data['upload_time'];
}

public function getParentId(): int {
return $this->data['parent'] ?? -1;
}
}
11 changes: 4 additions & 7 deletions lib/private/Files/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class Node implements INode {

protected ?FileInfo $fileInfo;

/**
* @var Node|null
*/
protected $parent;
protected ?INode $parent;

private bool $infoHasSubMountsIncluded;

Expand Down Expand Up @@ -300,13 +297,13 @@ public function getParent(): INode|IRootFolder {
return $this->root;
}

// gather the metadata we already know about our parent
$parentData = [
'path' => $newPath,
'fileid' => $this->fileInfo->getParentId(),
];
if ($this->fileInfo instanceof \OC\Files\FileInfo && isset($this->fileInfo['parent'])) {
$parentData['fileid'] = $this->fileInfo['parent'];
}

// and create lazy folder with it instead of always querying
$this->parent = new LazyFolder(function () use ($newPath) {
return $this->root->get($newPath);
}, $parentData);
Expand Down
9 changes: 9 additions & 0 deletions lib/public/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,13 @@ public function getCreationTime(): int;
* @since 18.0.0
*/
public function getUploadTime(): int;

/**
* Get the fileid or the parent folder
* or -1 if this item has no parent folder (because it is the root)
*
* @return int
* @since 28.0.1
*/
public function getParentId(): int;
}

0 comments on commit dcd9fd9

Please sign in to comment.