From ef787b91a2efaa159ffacdc3da4eff75208605c3 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 21 Sep 2015 12:11:18 +0200 Subject: [PATCH] (config) prevent backup collisions (start using microtime) --- src/opnsense/mvc/app/library/OPNsense/Core/Config.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index a9332eff9..7abbf6436 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -396,14 +396,17 @@ class Config extends Singleton public function backup() { $target_dir = dirname($this->config_file)."/backup/"; - $target_filename = "config-".time().".xml"; + $target_filename = "config-".microtime(true).".xml"; if (!file_exists($target_dir)) { // create backup directory if it's missing mkdir($target_dir); } - copy($this->config_file, $target_dir.$target_filename); - + // The new target backup filename shouldn't exists, because of the use of microtime. + // But if for some reason a script keeps calling this backup very often, it shouldn't crash. + if (!file_exists($target_dir . $target_filename)) { + copy($this->config_file, $target_dir . $target_filename); + } } /**