Compare commits

...

1 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
2be6039bfd aio-interface: cache config by mtime in ConfigurationManager to avoid redundant disk reads
Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe

fix: change configMtime default and reset value from null to 0

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/8a9ca3ac-8713-4235-aaac-a4496863469b

fix: reset config and mtime when file absent or filemtime fails

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe

fix: use null sentinel for configMtime and reset on filemtime failure

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/259ee301-d37b-409f-9a09-0cc7d87437fe

fix: restore missing return statement in getConfig() to fix psalm

Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/28ac9917-d57b-465f-8e98-dbc75c416ace
Co-Authored-By: szaimen <42591237+szaimen@users.noreply.github.com>
2026-04-21 14:18:19 +02:00

View File

@@ -12,6 +12,8 @@ class ConfigurationManager
private array $config = [];
private int $configMtime = 0;
private bool $noWrite = false;
private string $dailyBackupFileCache = '';
@@ -299,13 +301,21 @@ class ConfigurationManager
private function getConfig() : array
{
if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
{
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
if ($configContent === '') {
throw new \RuntimeException("The config file " . DataConst::GetConfigFile() . " is empty. It may have been truncated due to low disk space. Please restore it from a backup.");
$configFile = DataConst::GetConfigFile();
if (file_exists($configFile)) {
$mtime = filemtime($configFile);
if ($mtime !== false && $mtime !== $this->configMtime) {
$configContent = (string)file_get_contents($configFile);
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
if ($configContent === '') {
throw new \RuntimeException("The config file " . DataConst::GetConfigFile() . " is empty. It may have been truncated due to low disk space. Please restore it from a backup.");
}
$this->configMtime = $mtime;
}
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
} else {
$this->config = [];
$this->configMtime = 0;
}
return $this->config;
@@ -720,7 +730,14 @@ class ConfigurationManager
unlink($tempFile);
throw new InvalidSettingConfigurationException("Failed to rename " . $tempFile . " to " . DataConst::GetConfigFile());
}
$this->config = [];
clearstatcache(true, DataConst::GetConfigFile());
$mtime = filemtime(DataConst::GetConfigFile());
if ($mtime !== false) {
$this->configMtime = $mtime;
} else {
$this->config = [];
$this->configMtime = 0;
}
}
private function getEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {