diff options
author | Robin Appelman <robin@icewind.nl> | 2023-08-14 21:12:12 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-09-04 18:42:49 +0200 |
commit | 9055fef5eff14b74c1ecf4399ed4031f01edc044 (patch) | |
tree | de903e91ccc6f22de0c9f4e27b8ab169238661c9 /lib | |
parent | e718cbc6617ad83eda9274c59bb66c3b8f147796 (diff) | |
download | nextcloud-server-9055fef5eff14b74c1ecf4399ed4031f01edc044.tar.gz nextcloud-server-9055fef5eff14b74c1ecf4399ed4031f01edc044.zip |
add IFileInfo::getParentId
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/FileInfo.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Node/LazyFolder.php | 7 | ||||
-rw-r--r-- | lib/private/Files/Node/Node.php | 15 | ||||
-rw-r--r-- | lib/public/Files/FileInfo.php | 9 |
4 files changed, 28 insertions, 7 deletions
diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php index d0550913993..c0a5bf1b92b 100644 --- a/lib/private/Files/FileInfo.php +++ b/lib/private/Files/FileInfo.php @@ -412,4 +412,8 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { public function getUploadTime(): int { return (int) $this->data['upload_time']; } + + public function getParentId(): int { + return $this->data['parent'] ?? -1; + } } diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index c307b55b5bc..026a16060c4 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -551,4 +551,11 @@ class LazyFolder implements Folder { public function getRelativePath($path) { return PathHelper::getRelativePath($this->getPath(), $path); } + + public function getParentId(): int { + if (isset($this->data['parent'])) { + return $this->data['parent']; + } + return $this->__call(__FUNCTION__, func_get_args()); + } } diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 0318ae47784..bc96a116da7 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -59,10 +59,7 @@ class Node implements INode { protected ?FileInfo $fileInfo; - /** - * @var Node|null - */ - protected $parent; + protected ?INode $parent; private bool $infoHasSubMountsIncluded; @@ -300,13 +297,13 @@ class Node implements INode { return $this->root; } + // gather the metadata we already know about our parent $parentData = [ 'path' => $newPath, + 'fileid' => $this->getFileInfo()->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); @@ -486,4 +483,8 @@ class Node implements INode { public function getUploadTime(): int { return $this->getFileInfo()->getUploadTime(); } + + public function getParentId(): int { + return $this->fileInfo->getParentId(); + } } diff --git a/lib/public/Files/FileInfo.php b/lib/public/Files/FileInfo.php index 83ae4adef92..da35f7f9028 100644 --- a/lib/public/Files/FileInfo.php +++ b/lib/public/Files/FileInfo.php @@ -299,4 +299,13 @@ interface FileInfo { * @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.0 + */ + public function getParentId(): int; } |