mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
Use umask consistently
This commit is contained in:
parent
16a2f2c94a
commit
a15095dd00
2 changed files with 34 additions and 4 deletions
|
|
@ -12,6 +12,11 @@ class Storage
|
|||
*/
|
||||
public static $safe_overwrite = true;
|
||||
|
||||
/**
|
||||
* Cache the umask here.
|
||||
*/
|
||||
protected static $_umask;
|
||||
|
||||
/**
|
||||
* Check if a path really exists.
|
||||
*
|
||||
|
|
@ -271,7 +276,7 @@ class Storage
|
|||
$filename = $original_filename;
|
||||
}
|
||||
|
||||
@chmod($filename, ($perms === null ? (0666 & ~umask()) : $perms));
|
||||
@chmod($filename, ($perms === null ? (0666 & ~self::getUmask()) : $perms));
|
||||
if (function_exists('opcache_invalidate') && substr($filename, -4) === '.php')
|
||||
{
|
||||
@opcache_invalidate($filename, true);
|
||||
|
|
@ -364,7 +369,7 @@ class Storage
|
|||
{
|
||||
if (is_uploaded_file($source))
|
||||
{
|
||||
@chmod($destination, 0666 ^ intval(config('file.umask'), 8));
|
||||
@chmod($destination, 0666 & ~self::getUmask());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -449,7 +454,7 @@ class Storage
|
|||
$dirname = rtrim($dirname, '/\\');
|
||||
if ($mode === null)
|
||||
{
|
||||
$mode = 0777 & ~umask();
|
||||
$mode = 0777 & ~self::getUmask();
|
||||
}
|
||||
return @mkdir($dirname, $mode, true);
|
||||
}
|
||||
|
|
@ -613,4 +618,29 @@ class Storage
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current umask.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getUmask()
|
||||
{
|
||||
if (self::$_umask === null)
|
||||
{
|
||||
self::$_umask = intval(config('file.umask'), 8) ?: 0;
|
||||
}
|
||||
return self::$_umask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current umask.
|
||||
*
|
||||
* @param int $umask
|
||||
* @return void
|
||||
*/
|
||||
public static function setUmask($umask)
|
||||
{
|
||||
self::$_umask = intval($umask);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class StorageTest extends \Codeception\TestCase\Test
|
|||
$this->assertTrue(Rhymix\Framework\Storage::write($testfile, 'foobarbazzjazz'));
|
||||
$this->assertTrue(file_exists($testfile));
|
||||
$this->assertEquals('foobarbazzjazz', file_get_contents($testfile));
|
||||
$this->assertEquals(0666 & ~umask(), fileperms($testfile) & 0777);
|
||||
$this->assertEquals(0666 & ~Rhymix\Framework\Storage::getUmask(), fileperms($testfile) & 0777);
|
||||
|
||||
// Append test
|
||||
$this->assertTrue(Rhymix\Framework\Storage::write($testfile, 'rhymix', 'a', 0666));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue