legacy: Deploy files with proper permissions
So we can use the same logic as for icingaweb2 configs.
This commit is contained in:
parent
2de62be74d
commit
93e1a88e10
|
@ -19,6 +19,9 @@ class LegacyDeploymentApi implements DeploymentApiInterface
|
||||||
protected $deploymentPath;
|
protected $deploymentPath;
|
||||||
protected $activationScript;
|
protected $activationScript;
|
||||||
|
|
||||||
|
const DIR_MODE = 0775;
|
||||||
|
const FILE_MODE = 0664;
|
||||||
|
|
||||||
public function __construct(Db $db)
|
public function __construct(Db $db)
|
||||||
{
|
{
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
@ -266,28 +269,17 @@ class LegacyDeploymentApi implements DeploymentApiInterface
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
throw new IcingaException('Stage "%s" does already exist at: ', $stage, $path);
|
throw new IcingaException('Stage "%s" does already exist at: ', $stage, $path);
|
||||||
} else {
|
} else {
|
||||||
try {
|
$this->mkdir($path);
|
||||||
mkdir($path);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
throw new IcingaException('Could not create stage "%s" at: %s - %s', $stage, $path, $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($files as $file => $content) {
|
foreach ($files as $file => $content) {
|
||||||
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
|
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
|
||||||
$relativeDir = dirname($file);
|
$this->mkdir(dirname($fullPath), true);
|
||||||
if ($relativeDir !== '') {
|
|
||||||
$fullDir = $path . DIRECTORY_SEPARATOR . $relativeDir;
|
|
||||||
if (! file_exists($fullDir)) {
|
|
||||||
if (! @mkdir($fullDir, 0755, true)) {
|
|
||||||
throw new IcingaException('Could not create directory %s', $fullDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$fh = @fopen($fullPath, 'w');
|
$fh = @fopen($fullPath, 'w');
|
||||||
if ($fh === null) {
|
if ($fh === null) {
|
||||||
throw new IcingaException('Could not open file "%s" for writing.', $fullPath);
|
throw new IcingaException('Could not open file "%s" for writing.', $fullPath);
|
||||||
}
|
}
|
||||||
|
chmod($fullPath, self::FILE_MODE);
|
||||||
|
|
||||||
fwrite($fh, $content);
|
fwrite($fh, $content);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
|
@ -452,4 +444,20 @@ class LegacyDeploymentApi implements DeploymentApiInterface
|
||||||
|
|
||||||
rmdir($dir);
|
rmdir($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function mkdir($path, $recursive = false)
|
||||||
|
{
|
||||||
|
if (! file_exists($path)) {
|
||||||
|
if ($recursive) {
|
||||||
|
$this->mkdir(dirname($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mkdir($path);
|
||||||
|
chmod($path, self::DIR_MODE);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new IcingaException('Could not create path "%s": %s', $path, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue