aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Node/LazyFolder.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Node/LazyFolder.php')
-rw-r--r--lib/private/Files/Node/LazyFolder.php78
1 files changed, 64 insertions, 14 deletions
diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php
index d495d6f4c57..393b3bbeb06 100644
--- a/lib/private/Files/Node/LazyFolder.php
+++ b/lib/private/Files/Node/LazyFolder.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
+ * @author Maxence Lange <maxence@artificial-owl.com>
* @author Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
@@ -26,10 +27,13 @@ declare(strict_types=1);
namespace OC\Files\Node;
+use OC\Files\Filesystem;
use OC\Files\Utils\PathHelper;
use OCP\Files\Folder;
use OCP\Constants;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
+use OCP\Files\NotPermittedException;
/**
* Class LazyFolder
@@ -41,23 +45,33 @@ use OCP\Files\Mount\IMountPoint;
*/
class LazyFolder implements Folder {
/** @var \Closure(): Folder */
- private $folderClosure;
-
- /** @var LazyFolder | null */
- protected $folder = null;
-
+ private \Closure $folderClosure;
+ protected ?Folder $folder = null;
+ protected IRootFolder $rootFolder;
protected array $data;
/**
- * LazyFolder constructor.
- *
+ * @param IRootFolder $rootFolder
* @param \Closure(): Folder $folderClosure
+ * @param array $data
*/
- public function __construct(\Closure $folderClosure, array $data = []) {
+ public function __construct(IRootFolder $rootFolder, \Closure $folderClosure, array $data = []) {
+ $this->rootFolder = $rootFolder;
$this->folderClosure = $folderClosure;
$this->data = $data;
}
+ protected function getRootFolder(): IRootFolder {
+ return $this->rootFolder;
+ }
+
+ protected function getRealFolder(): Folder {
+ if ($this->folder === null) {
+ $this->folder = call_user_func($this->folderClosure);
+ }
+ return $this->folder;
+ }
+
/**
* Magic method to first get the real rootFolder and then
* call $method with $args on it
@@ -67,11 +81,7 @@ class LazyFolder implements Folder {
* @return mixed
*/
public function __call($method, $args) {
- if ($this->folder === null) {
- $this->folder = call_user_func($this->folderClosure);
- }
-
- return call_user_func_array([$this->folder, $method], $args);
+ return call_user_func_array([$this->getRealFolder(), $method], $args);
}
/**
@@ -148,7 +158,7 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function get($path) {
- return $this->__call(__FUNCTION__, func_get_args());
+ return $this->getRootFolder()->get($this->getFullPath($path));
}
/**
@@ -207,6 +217,9 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getId() {
+ if (isset($this->data['fileid'])) {
+ return $this->data['fileid'];
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -221,6 +234,9 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getMTime() {
+ if (isset($this->data['mtime'])) {
+ return $this->data['mtime'];
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -228,6 +244,9 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getSize($includeMounts = true): int|float {
+ if (isset($this->data['size'])) {
+ return $this->data['size'];
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -235,6 +254,9 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getEtag() {
+ if (isset($this->data['etag'])) {
+ return $this->data['etag'];
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -299,6 +321,12 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getName() {
+ if (isset($this->data['path'])) {
+ return basename($this->data['path']);
+ }
+ if (isset($this->data['name'])) {
+ return $this->data['name'];
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -390,6 +418,13 @@ class LazyFolder implements Folder {
* @inheritDoc
*/
public function getFullPath($path) {
+ if (isset($this->data['path'])) {
+ $path = PathHelper::normalizePath($path);
+ if (!Filesystem::isValidPath($path)) {
+ throw new NotPermittedException('Invalid path "' . $path . '"');
+ }
+ return $this->data['path'] . $path;
+ }
return $this->__call(__FUNCTION__, func_get_args());
}
@@ -533,4 +568,19 @@ 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());
+ }
+
+ /**
+ * @inheritDoc
+ * @return array<string, int|string|bool|float|string[]|int[]>
+ */
+ public function getMetadata(): array {
+ return $this->data['metadata'] ?? $this->__call(__FUNCTION__, func_get_args());
+ }
}