diff --git a/lib/private/files/objectstore/eosparser.php b/lib/private/files/objectstore/eosparser.php index 0312961bb18d..6583456ef2fc 100644 --- a/lib/private/files/objectstore/eosparser.php +++ b/lib/private/files/objectstore/eosparser.php @@ -174,4 +174,33 @@ public static function parseMember($line_to_parse) { } + public static function parseQuota($cmdResult) + { + $line = $cmdResult; + if(is_array($cmdResult)) + { + $line = $cmdResult[0]; + } + + $line = explode(' ', $line); + $data = []; + foreach($line as $token) + { + $parts = explode('=', $token); + $data[$parts[0]] = $parts[1]; + } + + $used = intval($data['usedlogicalbytes']); + $total = intval($data['maxlogialbytes']); + + return + [ + 'free' => $total - $used, + 'used' => $data['usedlogicalbytes'], + 'total' => $data['maxlogicalbytes'], + 'relative' => $data['percentageusedbytes'], + 'usedfiles' => $data['usedfiles'], + 'maxfiles' => $data['maxfiles'], + ]; + } } diff --git a/lib/private/files/objectstore/eosutil.php b/lib/private/files/objectstore/eosutil.php index 38cc639cf66d..1dc14bdf5f78 100644 --- a/lib/private/files/objectstore/eosutil.php +++ b/lib/private/files/objectstore/eosutil.php @@ -991,4 +991,23 @@ public static function getFolderContents($eosPath, $additionalParameterCallback return $result; } + + public static function getUserQuota() + { + $userId = \OC::$server->getUserSession()->getUser()->getUID(); + list($uid, $gid) = self::getUidAndGid($userId); + $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); + + return $parsed; + } + + return [ 'free' => 0, 'used' => 0, 'total' => 0, 'relative' => 0, 'owner' => $userId, 'ownerDisplayName' => \OC_User::getDisplayName($userId)]; + } } diff --git a/lib/private/helper.php b/lib/private/helper.php index abfabff2f4b2..fc601b1a6d75 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -841,6 +841,9 @@ public static function findBinaryPath($program) { * @throws \OCP\Files\NotFoundException */ public static function getStorageInfo($path, $rootInfo = null) { + /** CERNBOX QUOTA PATCH */ + return \OC\Files\ObjectStore\EosUtil::getUserQuota(); + // return storage info without adding mount points $includeExtStorage = \OC_Config::getValue('quota_include_external_storage', false);