diff --git a/src/etc/inc/config.inc b/src/etc/inc/config.inc index c4abc84b6..1c4e9fc87 100644 --- a/src/etc/inc/config.inc +++ b/src/etc/inc/config.inc @@ -164,9 +164,6 @@ function write_config($desc = '', $backup = true) configd_run('filter sync load'); } - /* cleanup backups */ - cleanup_backups(); - /* on succesfull save, serialize config back to global */ $config = $cnf->toArray(listtags()); @@ -218,31 +215,6 @@ function security_checks_disabled() return file_exists('/tmp/disable_security_checks'); } -/** - * remove old backups - */ -function cleanup_backups() -{ - global $config; - - if (isset($config['system']['backupcount']) && is_numeric($config['system']['backupcount']) && ($config['system']['backupcount'] >= 0)) { - $revisions = intval($config['system']['backupcount']); - } else { - /* XXX this value used to be left out of the config */ - $revisions = 60; - } - - $cnf = OPNsense\Core\Config::getInstance(); - - $cnt=1; - foreach ($cnf->getBackups() as $filename) { - if ($cnt > $revisions ) { - @unlink($filename); - } - ++$cnt ; - } -} - function &config_read_array() { global $config; diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index 85bedc22b..91a624fe2 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -530,6 +530,27 @@ class Config extends Singleton } } + /** + * remove old backups + */ + private function cleanupBackups() + { + if ($this->statusIsValid && isset($this->simplexml->system->backupcount) + && intval($this->simplexml->system->backupcount) >= 0) { + $revisions = intval($this->simplexml->system->backupcount); + } else { + $revisions = 60; + } + + $cnt = 1; + foreach ($this->getBackups() as $filename) { + if ($cnt > $revisions ) { + @unlink($filename); + } + ++$cnt ; + } + } + /** * save config to filesystem * @param array|null $revision revision tag (associative array) @@ -562,6 +583,9 @@ class Config extends Singleton throw new ConfigException("Unable to lock config"); } } + + /* cleanup backups */ + $this->cleanupBackups(); } /**