2626
2727namespace OC \Files \Node ;
2828
29+ use OC \Files \Filesystem ;
2930use OC \Files \Utils \PathHelper ;
3031use OCP \Files \Folder ;
3132use OCP \Constants ;
33+ use OCP \Files \IRootFolder ;
3234use OCP \Files \Mount \IMountPoint ;
35+ use OCP \Files \NotPermittedException ;
3336
3437/**
3538 * Class LazyFolder
4144 */
4245class LazyFolder implements Folder {
4346 /** @var \Closure(): Folder */
44- private $ folderClosure ;
45-
46- /** @var LazyFolder | null */
47- protected $ folder = null ;
48-
47+ private \Closure $ folderClosure ;
48+ protected ?Folder $ folder = null ;
49+ protected IRootFolder $ rootFolder ;
4950 protected array $ data ;
5051
5152 /**
52- * LazyFolder constructor.
53- *
53+ * @param IRootFolder $rootFolder
5454 * @param \Closure(): Folder $folderClosure
55+ * @param array $data
5556 */
56- public function __construct (\Closure $ folderClosure , array $ data = []) {
57+ public function __construct (IRootFolder $ rootFolder , \Closure $ folderClosure , array $ data = []) {
58+ $ this ->rootFolder = $ rootFolder ;
5759 $ this ->folderClosure = $ folderClosure ;
5860 $ this ->data = $ data ;
5961 }
6062
63+ protected function getRootFolder (): IRootFolder {
64+ return $ this ->rootFolder ;
65+ }
66+
67+ protected function getRealFolder (): Folder {
68+ if ($ this ->folder === null ) {
69+ $ this ->folder = call_user_func ($ this ->folderClosure );
70+ }
71+ return $ this ->folder ;
72+ }
73+
6174 /**
6275 * Magic method to first get the real rootFolder and then
6376 * call $method with $args on it
@@ -67,11 +80,7 @@ public function __construct(\Closure $folderClosure, array $data = []) {
6780 * @return mixed
6881 */
6982 public function __call ($ method , $ args ) {
70- if ($ this ->folder === null ) {
71- $ this ->folder = call_user_func ($ this ->folderClosure );
72- }
73-
74- return call_user_func_array ([$ this ->folder , $ method ], $ args );
83+ return call_user_func_array ([$ this ->getRealFolder (), $ method ], $ args );
7584 }
7685
7786 /**
@@ -148,7 +157,7 @@ public function unMount($mount) {
148157 * @inheritDoc
149158 */
150159 public function get ($ path ) {
151- return $ this ->__call ( __FUNCTION__ , func_get_args ( ));
160+ return $ this ->getRootFolder ()-> get ( $ this -> getFullPath ( $ path ));
152161 }
153162
154163 /**
@@ -207,6 +216,9 @@ public function getInternalPath() {
207216 * @inheritDoc
208217 */
209218 public function getId () {
219+ if (isset ($ this ->data ['fileid ' ])) {
220+ return $ this ->data ['fileid ' ];
221+ }
210222 return $ this ->__call (__FUNCTION__ , func_get_args ());
211223 }
212224
@@ -221,20 +233,29 @@ public function stat() {
221233 * @inheritDoc
222234 */
223235 public function getMTime () {
236+ if (isset ($ this ->data ['mtime ' ])) {
237+ return $ this ->data ['mtime ' ];
238+ }
224239 return $ this ->__call (__FUNCTION__ , func_get_args ());
225240 }
226241
227242 /**
228243 * @inheritDoc
229244 */
230245 public function getSize ($ includeMounts = true ): int |float {
246+ if (isset ($ this ->data ['size ' ])) {
247+ return $ this ->data ['size ' ];
248+ }
231249 return $ this ->__call (__FUNCTION__ , func_get_args ());
232250 }
233251
234252 /**
235253 * @inheritDoc
236254 */
237255 public function getEtag () {
256+ if (isset ($ this ->data ['etag ' ])) {
257+ return $ this ->data ['etag ' ];
258+ }
238259 return $ this ->__call (__FUNCTION__ , func_get_args ());
239260 }
240261
@@ -299,6 +320,12 @@ public function getParent() {
299320 * @inheritDoc
300321 */
301322 public function getName () {
323+ if (isset ($ this ->data ['path ' ])) {
324+ return basename ($ this ->data ['path ' ]);
325+ }
326+ if (isset ($ this ->data ['name ' ])) {
327+ return $ this ->data ['name ' ];
328+ }
302329 return $ this ->__call (__FUNCTION__ , func_get_args ());
303330 }
304331
@@ -390,6 +417,13 @@ public function getExtension(): string {
390417 * @inheritDoc
391418 */
392419 public function getFullPath ($ path ) {
420+ if (isset ($ this ->data ['path ' ])) {
421+ $ path = PathHelper::normalizePath ($ path );
422+ if (!Filesystem::isValidPath ($ path )) {
423+ throw new NotPermittedException ('Invalid path " ' . $ path . '" ' );
424+ }
425+ return $ this ->data ['path ' ] . $ path ;
426+ }
393427 return $ this ->__call (__FUNCTION__ , func_get_args ());
394428 }
395429
@@ -533,4 +567,11 @@ public function getUploadTime(): int {
533567 public function getRelativePath ($ path ) {
534568 return PathHelper::getRelativePath ($ this ->getPath (), $ path );
535569 }
570+
571+ public function getParentId (): int {
572+ if (isset ($ this ->data ['parent ' ])) {
573+ return $ this ->data ['parent ' ];
574+ }
575+ return $ this ->__call (__FUNCTION__ , func_get_args ());
576+ }
536577}
0 commit comments