Skip to content

Commit

Permalink
Merge pull request #5 from cernbox/cernbox-prod-8.2.2-quota-display-fix
Browse files Browse the repository at this point in the history
[Patch] Fix for quota stats display in personal page
  • Loading branch information
NadirRoGue committed Apr 25, 2016
2 parents ec022b3 + dc6581a commit 83224af
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/private/files/objectstore/eosparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
19 changes: 19 additions & 0 deletions lib/private/files/objectstore/eosutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
}
3 changes: 3 additions & 0 deletions lib/private/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 83224af

Please sign in to comment.