Skip to content

Commit

Permalink
Implement timestamps for zone configs.
Browse files Browse the repository at this point in the history
Fixes #6191
  • Loading branch information
gunnarbeutner committed May 15, 2014
1 parent dcbe7e1 commit 14cb049
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/remote/apilistener-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down

0 comments on commit 14cb049

Please sign in to comment.