]> granicus.if.org Git - icinga2/commitdiff
Implement timestamps for zone configs.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 15 May 2014 12:27:50 +0000 (14:27 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 15 May 2014 13:08:45 +0000 (15:08 +0200)
Fixes #6191

lib/remote/apilistener-sync.cpp

index 78ae5cf060e0084352e980c42205ddf75b0c4901..84a1aa815a6eda38118d3362135253012fa54634 100644 (file)
@@ -21,6 +21,7 @@
 #include "remote/apifunction.h"
 #include "base/dynamictype.h"
 #include "base/logger_fwd.h"
+#include "base/convert.h"
 #include <boost/foreach.hpp>
 #include <fstream>
 
@@ -57,6 +58,14 @@ bool ApiListener::UpdateConfigDir(const Dictionary::Ptr& oldConfig, const Dictio
 {
        bool configChange = false;
 
+       if (oldConfig->Contains(".timestamp") && newConfig->Contains(".timestamp")) {
+               double oldTS = Convert::ToDouble(oldConfig->Get(".timestamp"));
+               double newTS = Convert::ToDouble(newConfig->Get(".timestamp"));
+
+               /* skip update if our config is newer */
+               if (oldTS <= newTS)
+                       return false;
+       }
 
        BOOST_FOREACH(const Dictionary::Pair& kv, newConfig) {
                if (oldConfig->Get(kv.first) != kv.second) {
@@ -80,6 +89,13 @@ bool ApiListener::UpdateConfigDir(const Dictionary::Ptr& oldConfig, const Dictio
                }
        }
 
+       String tsPath = configDir + "/.timestamp";
+       if (!Utility::PathExists(tsPath)) {
+               std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc);
+               fp << Utility::GetTime();
+               fp.close();
+       }
+
        return configChange;
 }