From 01fb3a4f442362cd637a244a002c4f0c058bde7e Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 9 Mar 2020 15:16:22 +0100 Subject: [PATCH] MVC / config: synchronize backup timestamps with revisions. A minor change, previously we requested microtime() twice which always lead to a small difference in revision and backup. If we sync these two timestamps, it's easier to find the previous sitation updated.time matches /conf/backup/config-[updated.time].xml --- .../mvc/app/library/OPNsense/Core/Config.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index fbe869c9c..19ab1e71c 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -406,7 +406,7 @@ class Config extends Singleton * @param array|null $revision revision tag (associative array) * @param \SimpleXMLElement|null pass trough xml node */ - private function updateRevision($revision, $node = null) + private function updateRevision($revision, $node = null, $timestamp = null) { // if revision info is not provided, create a default. if (!is_array($revision)) { @@ -430,7 +430,7 @@ class Config extends Singleton } // always set timestamp - $revision['time'] = microtime(true); + $revision['time'] = empty($timestamp) ? microtime(true) : $timestamp; if ($node == null) { if (isset($this->simplexml->revision)) { @@ -456,11 +456,13 @@ class Config extends Singleton /** * backup current (running) config + * @return float timestamp */ public function backup() { + $timestamp = microtime(true); $target_dir = dirname($this->config_file) . "/backup/"; - $target_filename = "config-" . microtime(true) . ".xml"; + $target_filename = "config-" . $timestamp . ".xml"; if (!file_exists($target_dir)) { // create backup directory if it is missing @@ -471,6 +473,7 @@ class Config extends Singleton if (!file_exists($target_dir . $target_filename)) { copy($this->config_file, $target_dir . $target_filename); } + return $timestamp; } /** @@ -575,11 +578,13 @@ class Config extends Singleton $this->checkvalid(); if ($backup) { - $this->backup(); + $timestamp = $this->backup(); + } else { + $timestamp = microtime(true); } - // update revision information ROOT.revision tag - $this->updateRevision($revision); + // update revision information ROOT.revision tag, align timestamp to backup output + $this->updateRevision($revision, null, $timestamp); // serialize to text $xml_text = $this->__toString();