@@ -81,6 +81,7 @@ class OC_Util {
8181 public static $ styles = [];
8282 public static $ headers = [];
8383 private static $ rootMounted = false ;
84+ private static $ rootFsSetup = false ;
8485 private static $ fsSetup = false ;
8586
8687 /** @var array Local cache of version.php */
@@ -186,30 +187,18 @@ private static function initObjectStoreMultibucketRootFS($config) {
186187 * @suppress PhanDeprecatedFunction
187188 * @suppress PhanAccessMethodInternal
188189 */
189- public static function setupFS ( $ user = '' ) {
190+ public static function setupRootFS ( string $ user = '' ) {
190191 //setting up the filesystem twice can only lead to trouble
191- if (self ::$ fsSetup ) {
192+ if (self ::$ rootFsSetup ) {
192193 return false ;
193194 }
194195
195- \OC ::$ server ->getEventLogger ()->start ('setup_fs ' , 'Setup filesystem ' );
196-
197- // If we are not forced to load a specific user we load the one that is logged in
198- if ($ user === null ) {
199- $ user = '' ;
200- } elseif ($ user == "" && \OC ::$ server ->getUserSession ()->isLoggedIn ()) {
201- $ user = OC_User::getUser ();
202- }
196+ \OC ::$ server ->getEventLogger ()->start ('setup_root_fs ' , 'Setup root filesystem ' );
203197
204198 // load all filesystem apps before, so no setup-hook gets lost
205199 OC_App::loadApps (['filesystem ' ]);
206200
207- // the filesystem will finish when $user is not empty,
208- // mark fs setup here to avoid doing the setup from loading
209- // OC_Filesystem
210- if ($ user != '' ) {
211- self ::$ fsSetup = true ;
212- }
201+ self ::$ rootFsSetup = true ;
213202
214203 \OC \Files \Filesystem::initMountManager ();
215204
@@ -277,10 +266,10 @@ public static function setupFS($user = '') {
277266 return new \OC \Files \Storage \Wrapper \PermissionsMask ([
278267 'storage ' => $ storage ,
279268 'mask ' => \OCP \Constants::PERMISSION_ALL & ~(
280- \OCP \Constants::PERMISSION_UPDATE |
281- \OCP \Constants::PERMISSION_CREATE |
282- \OCP \Constants::PERMISSION_DELETE
283- ),
269+ \OCP \Constants::PERMISSION_UPDATE |
270+ \OCP \Constants::PERMISSION_CREATE |
271+ \OCP \Constants::PERMISSION_DELETE
272+ ),
284273 ]);
285274 }
286275 return $ storage ;
@@ -313,19 +302,46 @@ public static function setupFS($user = '') {
313302 $ mountManager ->addMount ($ rootMountProvider );
314303 }
315304
316- if ($ user != '' && !\OC ::$ server ->getUserManager ()->userExists ($ user )) {
317- \OC ::$ server ->getEventLogger ()->end ('setup_fs ' );
305+ \OC ::$ server ->getEventLogger ()->end ('setup_root_fs ' );
306+
307+ return true ;
308+ }
309+
310+ /**
311+ * Setup the file system
312+ *
313+ * @param string|null $user
314+ * @return boolean
315+ * @description configure the initial filesystem based on the configuration
316+ * @suppress PhanDeprecatedFunction
317+ * @suppress PhanAccessMethodInternal
318+ */
319+ public static function setupFS (?string $ user = '' ) {
320+ self ::setupRootFS ($ user ?? '' );
321+
322+ if (self ::$ fsSetup ) {
318323 return false ;
319324 }
320325
321- //if we aren't logged in, there is no use to set up the filesystem
322- if ($ user != "" ) {
323- $ userDir = '/ ' . $ user . '/files ' ;
326+ \OC ::$ server ->getEventLogger ()->start ('setup_fs ' , 'Setup filesystem ' );
327+
328+ // If we are not forced to load a specific user we load the one that is logged in
329+ if ($ user === '' ) {
330+ $ userObject = \OC ::$ server ->get (\OCP \IUserSession::class)->getUser ();
331+ } else {
332+ $ userObject = \OC ::$ server ->get (\OCP \IUserManager::class)->get ($ user );
333+ }
334+
335+ //if we aren't logged in, or the user doesn't exist, there is no use to set up the filesystem
336+ if ($ userObject ) {
337+ self ::$ fsSetup = true ;
338+
339+ $ userDir = '/ ' . $ userObject ->getUID () . '/files ' ;
324340
325341 //jail the user into his "home" directory
326- \OC \Files \Filesystem::init ($ user , $ userDir );
342+ \OC \Files \Filesystem::init ($ userObject , $ userDir );
327343
328- OC_Hook::emit ('OC_Filesystem ' , 'setup ' , ['user ' => $ user , 'user_dir ' => $ userDir ]);
344+ OC_Hook::emit ('OC_Filesystem ' , 'setup ' , ['user ' => $ userObject -> getUID () , 'user_dir ' => $ userDir ]);
329345 }
330346 \OC ::$ server ->getEventLogger ()->end ('setup_fs ' );
331347 return true ;
@@ -484,6 +500,7 @@ public static function tearDownFS() {
484500 \OC \Files \Filesystem::tearDown ();
485501 \OC ::$ server ->getRootFolder ()->clearCache ();
486502 self ::$ fsSetup = false ;
503+ self ::$ rootFsSetup = false ;
487504 self ::$ rootMounted = false ;
488505 }
489506
0 commit comments