Implement timestamps for zone configs.

Fixes #6191
This commit is contained in:
Gunnar Beutner 2014-05-15 14:27:50 +02:00
parent dcbe7e1dfd
commit 14cb049b6a
1 changed files with 16 additions and 0 deletions

View 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;
}