mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 19:15:22 +00:00
Core/Config - add hasChanged() to detect changes to the config file from other processes in a lightweight mannner. closes https://github.com/opnsense/core/issues/6798
This commit is contained in:
parent
0c2c3b0c79
commit
09cabd9877
@ -69,6 +69,10 @@ class Config extends Singleton
|
||||
*/
|
||||
private $statusIsValid = false;
|
||||
|
||||
/**
|
||||
* @var float current modification time of our known config
|
||||
*/
|
||||
private $mtime = 0;
|
||||
|
||||
/**
|
||||
* return last known status of this configuration (valid or not)
|
||||
@ -430,6 +434,7 @@ class Config extends Singleton
|
||||
}
|
||||
|
||||
$this->simplexml = $this->loadFromStream($this->config_file_handle);
|
||||
$this->mtime = fstat($this->config_file_handle)['mtime'];
|
||||
$this->statusIsValid = true;
|
||||
}
|
||||
|
||||
@ -659,6 +664,14 @@ class Config extends Singleton
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool when config file underneath has changed without our instance being aware of it
|
||||
*/
|
||||
public function hasChanged()
|
||||
{
|
||||
return $this->mtime != fstat($this->config_file_handle)['mtime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* return backup file path if revision exists
|
||||
* @param $revision revision timestamp (e.g. 1583766095.9337)
|
||||
@ -728,6 +741,7 @@ class Config extends Singleton
|
||||
$logger->info("config-event: new_config " . $backup_filename);
|
||||
}
|
||||
flock($this->config_file_handle, LOCK_UN);
|
||||
$this->mtime = fstat($this->config_file_handle)['mtime'];
|
||||
} else {
|
||||
throw new ConfigException("Unable to lock config");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user