Config fixing

- unlock/close the `node.config.php` in every circumstances
This commit is contained in:
Philipp 2023-01-06 01:10:57 +01:00
parent 5aa8e8adf1
commit e14050491a
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432

View File

@ -182,15 +182,17 @@ class ConfigFileManager
$content = '<?php return [];'; $content = '<?php return [];';
$configStream = fopen($filename, 'r'); $configStream = fopen($filename, 'r');
try {
if (flock($configStream, LOCK_SH)) { if (flock($configStream, LOCK_SH)) {
$content = fread($configStream, filesize($filename)); $content = fread($configStream, filesize($filename));
if (!$content) { if (!$content) {
throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename)); throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
} }
flock($configStream, LOCK_UN);
} }
} finally {
flock($configStream, LOCK_UN);
fclose($configStream); fclose($configStream);
}
$dataArray = eval('?>' . $content); $dataArray = eval('?>' . $content);
@ -250,12 +252,12 @@ class ConfigFileManager
clearstatcache(true, $filename); clearstatcache(true, $filename);
if (!ftruncate($configStream, 0) || if (!ftruncate($configStream, 0) ||
!fwrite($configStream, $encodedData) || !fwrite($configStream, $encodedData) ||
!fflush($configStream) || !fflush($configStream)) {
!flock($configStream, LOCK_UN)) {
throw new ConfigFileException(sprintf('Cannot modify locked file %s', $filename)); throw new ConfigFileException(sprintf('Cannot modify locked file %s', $filename));
} }
} }
} finally { } finally {
flock($configStream, LOCK_UN);
fclose($configStream); fclose($configStream);
} }
} }