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(); }