mirror of
https://github.com/friendica/friendica
synced 2025-04-22 01:10:13 +00:00
Add warning message in case node.config.php isn't writable
This commit is contained in:
parent
308618b559
commit
6e0d16f22b
3 changed files with 35 additions and 2 deletions
|
@ -218,6 +218,22 @@ class ConfigFileManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the node.config.php is writable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function dataIsWritable(): bool
|
||||
{
|
||||
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
return is_writable($filename);
|
||||
} else {
|
||||
return is_writable($this->configDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves overridden config entries back into the data.config.php
|
||||
*
|
||||
|
@ -229,6 +245,11 @@ class ConfigFileManager
|
|||
{
|
||||
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
|
||||
|
||||
// fail at a early stage, if we already know that we cannot save the data
|
||||
if (!$this->dataIsWritable()) {
|
||||
throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename));
|
||||
}
|
||||
|
||||
if (file_exists($filename)) {
|
||||
$fileExists = true;
|
||||
} else {
|
||||
|
@ -238,13 +259,15 @@ class ConfigFileManager
|
|||
/**
|
||||
* Creates a read-write stream
|
||||
*
|
||||
* @see https://www.php.net/manual/en/function.fopen.php
|
||||
* @see https://www.php.net/manual/en/function.fopen.php
|
||||
* @note Open the file for reading and writing. If the file does not exist, it is created.
|
||||
* If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails
|
||||
* (as is the case with 'x'). The file pointer is positioned on the beginning of the file.
|
||||
*
|
||||
*/
|
||||
$configStream = fopen($filename, 'c+');
|
||||
if (($configStream = @fopen($filename, 'c+')) !== false) {
|
||||
throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename));
|
||||
}
|
||||
|
||||
try {
|
||||
// We do want an exclusive lock, so we wait until every LOCK_SH (config reading) is unlocked
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue