2727use OCP \Constants ;
2828use OCP \Files \IRootFolder ;
2929use OCP \Files \NotFoundException ;
30+ use OCP \Files \Folder ;
31+ use OCP \Files \File ;
3032use OCP \IUser ;
33+ use Psr \Log \LoggerInterface ;
3134
3235class LazyUserFolder extends LazyFolder {
3336 private IRootFolder $ root ;
@@ -38,14 +41,22 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
3841 $ this ->root = $ rootFolder ;
3942 $ this ->user = $ user ;
4043 $ this ->path = '/ ' . $ user ->getUID () . '/files ' ;
41- parent ::__construct (function () use ($ user ) {
44+ parent ::__construct (function () use ($ user ): Folder {
4245 try {
43- return $ this ->root ->get ('/ ' . $ user ->getUID () . '/files ' );
46+ $ node = $ this ->root ->get ($ this ->path );
47+ if ($ node instanceof File) {
48+ $ e = new \RuntimeException ();
49+ \OCP \Server::get (LoggerInterface::class)->error ('User root storage is not a folder: ' . $ this ->path , [
50+ 'exception ' => $ e ,
51+ ]);
52+ throw $ e ;
53+ }
54+ return $ node ;
4455 } catch (NotFoundException $ e ) {
4556 if (!$ this ->root ->nodeExists ('/ ' . $ user ->getUID ())) {
4657 $ this ->root ->newFolder ('/ ' . $ user ->getUID ());
4758 }
48- return $ this ->root ->newFolder (' / ' . $ user -> getUID () . ' /files ' );
59+ return $ this ->root ->newFolder ($ this -> path );
4960 }
5061 }, [
5162 'path ' => $ this ->path ,
@@ -56,7 +67,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
5667 }
5768
5869 public function get ($ path ) {
59- return $ this ->root ->get (' / ' . $ this ->user -> getUID () . ' /files/ ' . ltrim ($ path , '/ ' ));
70+ return $ this ->root ->get ($ this ->path . ltrim ($ path , '/ ' ));
6071 }
6172
6273 /**
0 commit comments