/**
* Config extension
*/
public const CONFIG_EXT = '.conf';
/**
* Write config data to file in Bacula format.
*
* @access public
* @param string $source config file path
* @param array $config config data
* @return bool true if config written successfully, otherwise false
*/
public function write($source, $config)
{
$ts = date("YmdHis");
$dir_name = dirname($source);
$base_name = basename($source,self::CONFIG_EXT);
$bk_file_name = $dir_name . DIRECTORY_SEPARATOR . $base_name . '_' . $ts . self::CONFIG_EXT;
$orig_umask = umask(0);
$bk_ok = copy($source,$bk_file_name);
umask(0077);
$content = $this->prepareConfig($config);
$result = file_put_contents($source, $content);
// if nothing write delete backup file
if (is_int($result)) {
if ($bk_ok) {
chgrp($bk_file_name,filegroup($source));
chmod($bk_file_name,fileperms($source));
}
} else {
if ($bk_ok) {
delete($bk_file_name);
}
}
umask($orig_umask);
return is_int($result);
}