Refactor Storage::recommendUmask() into Storage::getServerUID()

This commit is contained in:
Kijin Sung 2017-01-26 21:29:01 +09:00
parent 5f83192e5d
commit 30cdf63b77

View file

@ -772,7 +772,7 @@ class Storage
/**
* Determine the best umask for this installation of Rhymix.
*
* @return int
* @return string
*/
public static function recommendUmask()
{
@ -786,27 +786,7 @@ class Storage
$file_uid = fileowner(__FILE__);
// Get the UID of the current PHP process.
if (function_exists('posix_geteuid'))
{
$php_uid = posix_geteuid();
}
else
{
$testfile = \RX_BASEDIR . 'files/cache/uidcheck';
if (self::exists($testfile))
{
self::delete($testfile);
}
if (self::write($testfile, 'TEST'))
{
$php_uid = fileowner($testfile);
self::delete($testfile);
}
else
{
$php_uid = -1;
}
}
$php_uid = self::getServerUID();
// If both UIDs are the same, set the umask to 0022.
if ($file_uid == $php_uid)
@ -820,4 +800,36 @@ class Storage
return '0000';
}
}
/**
* Get the UID of the server process.
*
* @return int|false
*/
public static function getServerUID()
{
if (function_exists('posix_geteuid'))
{
return posix_geteuid();
}
else
{
$testfile = \RX_BASEDIR . 'files/cache/uidcheck_' . time();
if (self::exists($testfile))
{
self::delete($testfile);
}
if (self::write($testfile, 'TEST'))
{
$uid = fileowner($testfile);
self::delete($testfile);
return $uid;
}
else
{
return false;
}
}
}
}