mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 17:14:46 +00:00
Merge branch 'Sergey-Kirpa-cleanup-backups-after-saving'
This commit is contained in:
commit
e87cee8608
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user