Guard FileCache against an existing but not writeable runtime path

fixes 
This commit is contained in:
Eric Lippmann 2015-11-26 12:02:55 +01:00
parent 6f7e0890d8
commit 045e4a99b5
1 changed files with 10 additions and 13 deletions
library/Icinga/Web

View File

@ -41,21 +41,18 @@ class FileCache
protected function __construct($name)
{
$this->name = $name;
$tmpdir = sys_get_temp_dir();
$basedir = $tmpdir . '/FileCache_' . $name;
if (file_exists($basedir) && is_writeable($basedir)) {
$this->basedir = $basedir;
$this->enabled = true;
} elseif (file_exists($tmpdir) && is_writeable($tmpdir)) {
if (mkdir($basedir, '0750', true)) {
$tmpDir = sys_get_temp_dir();
$runtimePath = $tmpDir . '/FileCache_' . $name;
if (is_dir($runtimePath)) {
// Don't combine the following if with the above because else mkdir may fail w/ file exists if the runtime
// path exists and is not writeable
if (is_writeable($runtimePath)) {
$this->basedir = $runtimePath;
$this->enabled = true;
$this->basedir = $basedir;
}
} elseif (is_dir($tmpDir) && is_writeable($tmpDir) && mkdir($runtimePath, '0750', true)) {
$this->basedir = $runtimePath;
$this->enabled = true;
}
}