88 */
99namespace OC \Files \Node ;
1010
11+ use OC \Files \View ;
1112use OCP \Constants ;
12- use OCP \Files \File ;
1313use OCP \Files \FileInfo ;
1414use OCP \Files \Folder ;
1515use OCP \Files \IRootFolder ;
16+ use OCP \Files \IUserFolder ;
1617use OCP \Files \Mount \IMountManager ;
17- use OCP \Files \NotFoundException ;
18+ use OCP \ICacheFactory ;
19+ use OCP \IConfig ;
1820use OCP \IUser ;
21+ use OCP \Server ;
1922use Psr \Log \LoggerInterface ;
2023
21- class LazyUserFolder extends LazyFolder {
24+ class LazyUserFolder extends LazyFolder implements IUserFolder {
2225 private IUser $ user ;
2326 private string $ path ;
2427 private IMountManager $ mountManager ;
@@ -27,23 +30,30 @@ public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager
2730 $ this ->user = $ user ;
2831 $ this ->mountManager = $ mountManager ;
2932 $ this ->path = '/ ' . $ user ->getUID () . '/files ' ;
30- parent ::__construct ($ rootFolder , function () use ($ user ): Folder {
31- try {
32- $ node = $ this ->getRootFolder ()->get ($ this ->path );
33- if ($ node instanceof File) {
34- $ e = new \RuntimeException ();
35- \OCP \Server::get (LoggerInterface::class)->error ('User root storage is not a folder: ' . $ this ->path , [
36- 'exception ' => $ e ,
37- ]);
38- throw $ e ;
39- }
40- return $ node ;
41- } catch (NotFoundException $ e ) {
42- if (!$ this ->getRootFolder ()->nodeExists ('/ ' . $ user ->getUID ())) {
43- $ this ->getRootFolder ()->newFolder ('/ ' . $ user ->getUID ());
44- }
45- return $ this ->getRootFolder ()->newFolder ($ this ->path );
33+ parent ::__construct ($ rootFolder , function () use ($ user ): UserFolder {
34+ $ root = $ this ->getRootFolder ();
35+ if (!$ root ->nodeExists ('/ ' . $ user ->getUID ())) {
36+ $ parent = $ root ->newFolder ('/ ' . $ user ->getUID ());
37+ } else {
38+ $ parent = $ root ->get ('/ ' . $ user ->getUID ());
4639 }
40+ if (!($ parent instanceof Folder)) {
41+ $ e = new \RuntimeException ();
42+ \OCP \Server::get (LoggerInterface::class)->error ('User root storage is not a folder: ' . $ this ->path , [
43+ 'exception ' => $ e ,
44+ ]);
45+ throw $ e ;
46+ }
47+ $ realFolder = $ root ->newFolder ('/ ' . $ user ->getUID () . '/files ' );
48+ return new UserFolder (
49+ $ root ,
50+ new View ($ parent ->getPath ()),
51+ $ realFolder ->getPath (),
52+ $ parent ,
53+ Server::get (IConfig::class),
54+ $ user ,
55+ Server::get (ICacheFactory::class),
56+ );
4757 }, [
4858 'path ' => $ this ->path ,
4959 // Sharing user root folder is not allowed
@@ -63,4 +73,8 @@ public function getMountPoint() {
6373 }
6474 return $ mountPoint ;
6575 }
76+
77+ public function getUserQuota (bool $ useCache = true ): array {
78+ return $ this ->__call (__FUNCTION__ , func_get_args ());
79+ }
6680}
0 commit comments