From ac1371a6f4958dfbd10353c5856fb2b9df14e3f3 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 7 Sep 2020 16:41:52 +0200 Subject: [PATCH] Increment /var/lib/icinga2/api/zones/*/.timestamp only on config change refs #8210 --- lib/remote/apilistener-filesync.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 53a7a7873..3ced0027f 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -13,6 +13,7 @@ #include "base/exception.hpp" #include "base/shared.hpp" #include "base/utility.hpp" +#include #include #include #include @@ -61,11 +62,14 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const String zoneName = zone->GetName(); Dictionary::Ptr contents = new Dictionary(); + double ts = 0; // Load registered zone paths, e.g. '_etc', '_api' and user packages. for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zoneName)) { ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path, contents); + Utility::GlobRecursive(zf.Path, "*", [&ts](const String& path) { ts = std::max(ts, Utility::GetModTime(path)); }, GlobFile | GlobDirectory); + // Config files '*.conf'. { ObjectLock olock(newConfigPart.UpdateV1); @@ -89,6 +93,11 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const } } + if (ts == 0) { + // Syncing an empty zone every time hurts less than not syncing it at all. + ts = Utility::GetTime(); + } + size_t sumUpdates = newConfigInfo.UpdateV1->GetLength() + newConfigInfo.UpdateV2->GetLength(); // Return early if there are no updates. @@ -144,7 +153,7 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const if (!Utility::PathExists(tsPath)) { std::ofstream fp(tsPath.CStr(), std::ofstream::out | std::ostream::trunc); - fp << std::fixed << Utility::GetTime(); + fp << std::fixed << ts; fp.close(); }