Skip to content

Commit

Permalink
Merge pull request #10 from cernbox/cernbox-prod-8.2.2-home-dir-scrip…
Browse files Browse the repository at this point in the history
…t-trigger-fix

[Patch] Fix for home dir script tirggering when eos cmd fails
  • Loading branch information
NadirRoGue committed May 11, 2016
2 parents 870aab9 + 1a4daed commit 3d9ca2e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
36 changes: 30 additions & 6 deletions lib/private/files/objectstore/eosutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
}
23 changes: 18 additions & 5 deletions lib/private/user/cernboxsession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3d9ca2e

Please sign in to comment.