28
28
use OCP \Files \IRootFolder ;
29
29
use OCP \Files \Mount \IMountManager ;
30
30
use OCP \Files \NotFoundException ;
31
+ use OCP \Files \Folder ;
32
+ use OCP \Files \File ;
31
33
use OCP \IUser ;
34
+ use Psr \Log \LoggerInterface ;
32
35
33
36
class LazyUserFolder extends LazyFolder {
34
37
private IRootFolder $ root ;
@@ -41,14 +44,22 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager
41
44
$ this ->user = $ user ;
42
45
$ this ->mountManager = $ mountManager ;
43
46
$ this ->path = '/ ' . $ user ->getUID () . '/files ' ;
44
- parent ::__construct (function () use ($ user ) {
47
+ parent ::__construct (function () use ($ user ): Folder {
45
48
try {
46
- return $ this ->root ->get ('/ ' . $ user ->getUID () . '/files ' );
49
+ $ node = $ this ->root ->get ($ this ->path );
50
+ if ($ node instanceof File) {
51
+ $ e = new \RuntimeException ();
52
+ \OCP \Server::get (LoggerInterface::class)->error ('User root storage is not a folder: ' . $ this ->path , [
53
+ 'exception ' => $ e ,
54
+ ]);
55
+ throw $ e ;
56
+ }
57
+ return $ node ;
47
58
} catch (NotFoundException $ e ) {
48
59
if (!$ this ->root ->nodeExists ('/ ' . $ user ->getUID ())) {
49
60
$ this ->root ->newFolder ('/ ' . $ user ->getUID ());
50
61
}
51
- return $ this ->root ->newFolder (' / ' . $ user -> getUID () . ' /files ' );
62
+ return $ this ->root ->newFolder ($ this -> path );
52
63
}
53
64
}, [
54
65
'path ' => $ this ->path ,
@@ -59,7 +70,7 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager
59
70
}
60
71
61
72
public function get ($ path ) {
62
- return $ this ->root ->get ('/ ' . $ this ->user ->getUID () . '/files/ ' . ltrim ($ path , '/ ' ));
73
+ return $ this ->root ->get ('/ ' . $ this ->user ->getUID () . '/files ' . ltrim ($ path , '/ ' ));
63
74
}
64
75
65
76
/**
0 commit comments