]> git.mxchange.org Git - friendica.git/commitdiff
Fix loading empty node.config.php
authorPhilipp <admin@philipp.info>
Sun, 8 Jan 2023 01:04:25 +0000 (02:04 +0100)
committerPhilipp <admin@philipp.info>
Sun, 8 Jan 2023 01:49:56 +0000 (02:49 +0100)
src/Core/Config/Util/ConfigFileManager.php
tests/src/Core/Config/Cache/ConfigFileManagerTest.php

index f3627cf477881c2b3bcd70d4b79fa5541afeab12..fff240bb301e800e3178697dfd3846a0170ab3a0 100644 (file)
@@ -177,7 +177,7 @@ class ConfigFileManager
        {
                $filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
 
-               if (file_exists($filename)) {
+               if (file_exists($filename) && (filesize($filename) > 0)) {
 
                        // The fallback empty return content
                        $content = '<?php return [];';
@@ -188,9 +188,16 @@ class ConfigFileManager
                         *
                         * Any exclusive locking (LOCK_EX) would need to wait until all LOCK_SHs are unlocked
                         */
-                       $configStream = fopen($filename, 'r');
+                       if (($configStream = @fopen($filename, 'r')) === false) {
+                               throw new ConfigFileException(sprintf('Cannot open file "%s" in mode r', $filename));
+                       }
+
                        try {
                                if (flock($configStream, LOCK_SH)) {
+                                       if (($filesize = filesize($filename)) === 0) {
+                                               return;
+                                       }
+
                                        $content = fread($configStream, filesize($filename));
                                        if (!$content) {
                                                throw new ConfigFileException(sprintf('Couldn\'t read file %s', $filename));
index 2adfc27ef7586edc8fdec8537002e223849cc2e7..6c2c41ef65163f2a7a7d7c561a69dfa7dd8662d6 100644 (file)
@@ -511,4 +511,23 @@ class ConfigFileManagerTest extends MockedTest
 
                self::assertNull($configCache->get('system', 'default_timezone'));
        }
+
+       /**
+        * Test for empty node.config.php
+        */
+       public function testEmptyFile()
+       {
+               $this->delConfigFile('node.config.php');
+
+               vfsStream::newFile('node.config.php')
+                                ->at($this->root->getChild('config'))
+                                ->setContent('');
+
+               $configFileManager = (new Config())->createConfigFileManager($this->root->url());
+               $configCache       = new Cache();
+
+               $configFileManager->setupCache($configCache);
+
+               self::assertEquals(1,1);
+       }
 }