diff --git a/lib/private/files/objectstore/eosutil.php b/lib/private/files/objectstore/eosutil.php index 90203f94f954..a654c79ba670 100644 --- a/lib/private/files/objectstore/eosutil.php +++ b/lib/private/files/objectstore/eosutil.php @@ -994,22 +994,46 @@ public static function getFolderContents($eosPath, $additionalParameterCallback return $result; } - public static function getUserQuota() + const STAT_FILE_NOT_EXIST = 14; + const STAT_FILE_EXIST = 0; + + public static function statFile($eosPath) { - $userId = \OC::$server->getUserSession()->getUser()->getUID(); - list($uid, $gid) = self::getUidAndGid($userId); + $eosPathEscaped = escapeshellarg($eosPath); + $cmd = "eos -r 0 0 stat $eosPathEscaped"; + list($result, $errorCode) = EosCmd::exec($cmd); + return $errorCode; + } + + public static function getUserQuota($userName = false) + { + if(!$userName) + { + $userInstance = \OC::$server->getUserSession()->getUser(); + if($userInstance) + { + $userName = $userInstance->getUID(); + } + } + + if(!$userName) + { + return [ 'free' => -1, 'used' => 0, 'total' => 0, 'relative' => 0, 'owner' => '', 'ownerDisplayName' => '']; + } + + list($uid, $gid) = self::getUidAndGid($userName); $eosPrefix = self::getEosPrefix(); $cmd = "eos -r $uid $gid quota $eosPrefix -m"; list($result, $errorCode) = EosCmd::exec($cmd); if($errorCode === 0) { $parsed = EosParser::parseQuota($result); - $parsed['owner'] = $userId; - $parsed['ownerDisplayName'] = \OC_User::getDisplayName($userId); + $parsed['owner'] = $userName; + $parsed['ownerDisplayName'] = \OC_User::getDisplayName($userName); return $parsed; } - return [ 'free' => 0, 'used' => 0, 'total' => 0, 'relative' => 0, 'owner' => $userId, 'ownerDisplayName' => \OC_User::getDisplayName($userId)]; + return [ 'free' => -1, 'used' => 0, 'total' => 0, 'relative' => 0, 'owner' => $userName, 'ownerDisplayName' => \OC_User::getDisplayName($userName)]; } } diff --git a/lib/private/user/cernboxsession.php b/lib/private/user/cernboxsession.php index f4a9ac6a9308..29bfae3b957e 100644 --- a/lib/private/user/cernboxsession.php +++ b/lib/private/user/cernboxsession.php @@ -73,13 +73,26 @@ public function setUpNewUser($uid) // HUGO check user has valid homedir if not we create it $homedir = \OC\Files\ObjectStore\EosUtil::getEosPrefix() . substr($uid, 0, 1) . "/" . $uid . "/"; //$meta = \OC\Files\ObjectStore\EosUtil::getFileByEosPath($homedir); - $meta = \OC\Files\ObjectStore\EosUtil::getFolderContents($homedir, function(array &$data) use ($uid) + + $errorCode = -1; + do { - $data['storage'] = 'object::user:' . $uid; - }); - - if($meta) { // path exists so we let the user access the system + $errorCode = \OC\Files\ObjectStore\EosUtil::statFile($homedir); + if($errorCode != \OC\Files\ObjectStore\EosUtil::STAT_FILE_EXIST) + { + usleep(500000); // Half a second delay between request (microseconds) + } + } + while($errorCode != \OC\Files\ObjectStore\EosUtil::STAT_FILE_EXIST && $errorCode != \OC\Files\ObjectStore\EosUtil::STAT_FILE_NOT_EXIST); + + if($errorCode === \OC\Files\ObjectStore\EosUtil::STAT_FILE_EXIST) { // path exists so we let the user access the system \OCP\Util::writeLog('EOSLOGIN', "user: $uid has a valid homedir that is: $homedir", \OCP\Util::ERROR); + + $meta = \OC\Files\ObjectStore\EosUtil::getFolderContents($homedir, function(array &$data) use ($uid) + { + $data['storage'] = 'object::user:' . $uid; + }); + return true; }