diff options
author | jim-p <jimp@pfsense.org> | 2010-05-19 16:16:31 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2010-05-19 16:16:31 -0400 |
commit | cd25a2b2eee21ded884a184f8b4f8f0ffeaafefe (patch) | |
tree | 7cd22b323013a6eca62799b142395f1951b4627c /etc/inc | |
parent | eef522258914a223c6490fe9e3aba62566637a9e (diff) | |
download | pfsense-cd25a2b2eee21ded884a184f8b4f8f0ffeaafefe.zip pfsense-cd25a2b2eee21ded884a184f8b4f8f0ffeaafefe.tar.gz |
Refactor this function a little so it will also rebuild the cache if it does not already exist. Fixes missing config history after reboot on NanoBSD.
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/config.lib.inc | 104 |
1 files changed, 55 insertions, 49 deletions
diff --git a/etc/inc/config.lib.inc b/etc/inc/config.lib.inc index d4f4c88..435949f 100644 --- a/etc/inc/config.lib.inc +++ b/etc/inc/config.lib.inc @@ -1137,63 +1137,69 @@ function cleanup_backupcache($revisions = 30, $lock = false) { if (!$lock) $lockkey = lock('config'); - if(file_exists($g['cf_conf_path'] . '/backup/backup.cache')) { - conf_mount_rw(); - $backups = get_backups(); - $newbaks = array(); - $bakfiles = glob($g['cf_conf_path'] . "/backup/config-*"); + + conf_mount_rw(); + + $backups = get_backups(); + if ($backups) { $baktimes = $backups['versions']; - $tocache = array(); unset($backups['versions']); - foreach($bakfiles as $backup) { // Check for backups in the directory not represented in the cache. - if(filesize($backup) == 0) { - unlink($backup); - continue; - } - $tocheck = array_shift(explode('.', array_pop(explode('-', $backup)))); - if(!in_array($tocheck, $baktimes)) { - $i = true; - if($g['booting']) - echo "."; - $newxml = parse_xml_config($backup, $g['xml_rootobj']); - if($newxml == "-1") { - log_error("The backup cache file $backup is corrupted. Unlinking."); - unlink($backup); - log_error("The backup cache file $backup is corrupted. Unlinking."); - continue; - } - if($newxml['revision']['description'] == "") - $newxml['revision']['description'] = "Unknown"; - $tocache[$tocheck] = array('description' => $newxml['revision']['description']); - } - } - foreach($backups as $checkbak) { + } else { + $backups = array(); + $baktimes = array(); + } + $newbaks = array(); + $bakfiles = glob($g['cf_conf_path'] . "/backup/config-*"); + $tocache = array(); - if(count(preg_grep('/' . $checkbak['time'] . '/i', $bakfiles)) != 0) { - $newbaks[] = $checkbak; - } else { - $i = true; - if($g['booting']) print " " . $tocheck . "r"; + foreach($bakfiles as $backup) { // Check for backups in the directory not represented in the cache. + if(filesize($backup) == 0) { + unlink($backup); + continue; + } + $tocheck = array_shift(explode('.', array_pop(explode('-', $backup)))); + if(!in_array($tocheck, $baktimes)) { + $i = true; + if($g['booting']) + echo "."; + $newxml = parse_xml_config($backup, $g['xml_rootobj']); + if($newxml == "-1") { + log_error("The backup cache file $backup is corrupted. Unlinking."); + unlink($backup); + log_error("The backup cache file $backup is corrupted. Unlinking."); + continue; } + if($newxml['revision']['description'] == "") + $newxml['revision']['description'] = "Unknown"; + $tocache[$tocheck] = array('description' => $newxml['revision']['description']); } - foreach($newbaks as $todo) $tocache[$todo['time']] = array('description' => $todo['description']); - if(is_int($revisions) and (count($tocache) > $revisions)) { - $toslice = array_slice(array_keys($tocache), 0, $revisions); - foreach($toslice as $sliced) - $newcache[$sliced] = $tocache[$sliced]; - foreach($tocache as $version => $versioninfo) { - if(!in_array($version, array_keys($newcache))) { - unlink_if_exists($g['conf_path'] . '/backup/config-' . $version . '.xml'); - if($g['booting']) print " " . $tocheck . "d"; - } + } + foreach($backups as $checkbak) { + if(count(preg_grep('/' . $checkbak['time'] . '/i', $bakfiles)) != 0) { + $newbaks[] = $checkbak; + } else { + $i = true; + if($g['booting']) print " " . $tocheck . "r"; + } + } + foreach($newbaks as $todo) $tocache[$todo['time']] = array('description' => $todo['description']); + if(is_int($revisions) and (count($tocache) > $revisions)) { + $toslice = array_slice(array_keys($tocache), 0, $revisions); + foreach($toslice as $sliced) + $newcache[$sliced] = $tocache[$sliced]; + foreach($tocache as $version => $versioninfo) { + if(!in_array($version, array_keys($newcache))) { + unlink_if_exists($g['conf_path'] . '/backup/config-' . $version . '.xml'); + if($g['booting']) print " " . $tocheck . "d"; } - $tocache = $newcache; } - $bakout = fopen($g['cf_conf_path'] . '/backup/backup.cache', "w"); - fwrite($bakout, serialize($tocache)); - fclose($bakout); - conf_mount_ro(); + $tocache = $newcache; } + $bakout = fopen($g['cf_conf_path'] . '/backup/backup.cache', "w"); + fwrite($bakout, serialize($tocache)); + fclose($bakout); + conf_mount_ro(); + if($g['booting'] && $i) print "done.\n"; if (!$lock) |