Config fixing
- unlock/close the `node.config.php` in every circumstances
This commit is contained in:
parent
5aa8e8adf1
commit
e14050491a
1 changed files with 10 additions and 8 deletions
|
@ -182,16 +182,18 @@ class ConfigFileManager
|
||||||
$content = '<?php return [];';
|
$content = '<?php return [];';
|
||||||
|
|
||||||
$configStream = fopen($filename, 'r');
|
$configStream = fopen($filename, 'r');
|
||||||
if (flock($configStream, LOCK_SH)) {
|
try {
|
||||||
$content = fread($configStream, filesize($filename));
|
if (flock($configStream, LOCK_SH)) {
|
||||||
if (!$content) {
|
$content = fread($configStream, filesize($filename));
|
||||||
throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
|
if (!$content) {
|
||||||
|
throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
flock($configStream, LOCK_UN);
|
flock($configStream, LOCK_UN);
|
||||||
|
fclose($configStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($configStream);
|
|
||||||
|
|
||||||
$dataArray = eval('?>' . $content);
|
$dataArray = eval('?>' . $content);
|
||||||
|
|
||||||
if (is_array($dataArray)) {
|
if (is_array($dataArray)) {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue