From 0332929034f79e5379fc26731f25843e16e5ff48 Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Tue, 6 Jan 2026 21:59:29 +0100 Subject: [PATCH] Don't reload config if saving from a getter Without this there's race conditions Signed-off-by: Pablo Zmdl --- php/src/Data/ConfigurationManager.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 93645e65..72febdde 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -59,7 +59,7 @@ class ConfigurationManager $this->GetConfig(); if(!isset($this->config['secrets'][$secretId])) { $this->config['secrets'][$secretId] = bin2hex(random_bytes(24)); - $this->save(); + $this->save(false); } if ($secretId === 'BORGBACKUP_PASSWORD' && !file_exists(DataConst::GetBackupSecretFile())) { @@ -604,7 +604,7 @@ class ConfigurationManager /** * @throws InvalidSettingConfigurationException */ - public function save() : void { + public function save(bool $reload = true) : void { if(!is_dir(DataConst::GetDataDirectory())) { throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not exist! Something was set up falsely!"); } @@ -617,7 +617,9 @@ class ConfigurationManager file_put_contents(DataConst::GetConfigFile(), $content); // Force reloading the config after it was written. It's not clear to me if keeping the config loaded // might cause race conditions, e.g. in case multiple processes write to the file, so better safe than sorry. - $this->config = []; + if ($reload) { + $this->config = []; + } } private function GetEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string { @@ -636,7 +638,7 @@ class ConfigurationManager } if ($envVariableOutput !== $config[$configName]) { $this->config[$configName] = $envVariableOutput; - $this->save(); + $this->save(false); } } return $envVariableOutput;