]> git.mxchange.org Git - friendica.git/commitdiff
Config fixing
authorPhilipp <admin@philipp.info>
Fri, 6 Jan 2023 00:10:57 +0000 (01:10 +0100)
committerPhilipp <admin@philipp.info>
Fri, 6 Jan 2023 00:10:57 +0000 (01:10 +0100)
- unlock/close the `node.config.php` in every circumstances

src/Core/Config/Util/ConfigFileManager.php

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