27
27
use OCP \Constants ;
28
28
use OCP \Files \IRootFolder ;
29
29
use OCP \Files \NotFoundException ;
30
+ use OCP \Files \Folder ;
31
+ use OCP \Files \File ;
30
32
use OCP \IUser ;
33
+ use Psr \Log \LoggerInterface ;
31
34
32
35
class LazyUserFolder extends LazyFolder {
33
36
private IRootFolder $ root ;
@@ -38,14 +41,22 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
38
41
$ this ->root = $ rootFolder ;
39
42
$ this ->user = $ user ;
40
43
$ this ->path = '/ ' . $ user ->getUID () . '/files ' ;
41
- parent ::__construct (function () use ($ user ) {
44
+ parent ::__construct (function () use ($ user ): Folder {
42
45
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 ;
44
55
} catch (NotFoundException $ e ) {
45
56
if (!$ this ->root ->nodeExists ('/ ' . $ user ->getUID ())) {
46
57
$ this ->root ->newFolder ('/ ' . $ user ->getUID ());
47
58
}
48
- return $ this ->root ->newFolder (' / ' . $ user -> getUID () . ' /files ' );
59
+ return $ this ->root ->newFolder ($ this -> path );
49
60
}
50
61
}, [
51
62
'path ' => $ this ->path ,
@@ -56,7 +67,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user) {
56
67
}
57
68
58
69
public function get ($ path ) {
59
- return $ this ->root ->get (' / ' . $ this ->user -> getUID () . ' /files/ ' . ltrim ($ path , '/ ' ));
70
+ return $ this ->root ->get ($ this ->path . ltrim ($ path , '/ ' ));
60
71
}
61
72
62
73
/**
0 commit comments