Merge branch 'Sergey-Kirpa-cleanup-backups-after-saving'

This commit is contained in:
Ad Schellevis 2019-03-20 09:28:49 +01:00
commit e87cee8608
2 changed files with 24 additions and 28 deletions

View File

@ -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;

View File

@ -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();
}
/**