From 4c6150b254b24c11a9a08fabaf28b6817c8263f2 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 26 Oct 2018 16:29:46 +0200 Subject: [PATCH] Improve checksum logic and logging --- lib/remote/apilistener-filesync.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/remote/apilistener-filesync.cpp b/lib/remote/apilistener-filesync.cpp index 12d718a2d..845be35ee 100644 --- a/lib/remote/apilistener-filesync.cpp +++ b/lib/remote/apilistener-filesync.cpp @@ -398,13 +398,14 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const D { ObjectLock olock(newConfig); for (const Dictionary::Pair& kv : newConfig) { + /* Store the relative config file path for later validation and activation. + * IMPORTANT: Store this prior to any filters. */ + relativePaths.push_back(zoneName + "/" + kv.first); + /* Ignore same config content. This is an expensive comparison. */ if (productionConfig->Get(kv.first) == kv.second) continue; - /* Store the relative config file path for later validation and activation. */ - relativePaths.push_back(zoneName + "/" + kv.first); - String path = stageConfigZoneDir + "/" + kv.first; Log(LogInformation, "ApiListener") @@ -608,9 +609,11 @@ bool ApiListener::CheckConfigChange(const ConfigDirInformation& oldConfig, const Dictionary::Ptr oldChecksums = oldConfig.Checksums; Dictionary::Ptr newChecksums = newConfig.Checksums; - Log(LogCritical, "Comparing old: '") + Log(LogCritical, "ApiListener") + << "Comparing old (" << oldChecksums->GetLength() << "): '" << JsonEncode(oldChecksums) - << "' to new '" << JsonEncode(newChecksums) << "'."; + << "' to new (" << newChecksums->GetLength() << "): '" + << JsonEncode(newChecksums) << "'."; /* Different length means that either one or the other side added or removed something. */ if (oldChecksums->GetLength() != newChecksums->GetLength()) @@ -620,6 +623,7 @@ bool ApiListener::CheckConfigChange(const ConfigDirInformation& oldConfig, const ObjectLock olock(oldChecksums); for (const Dictionary::Pair& kv : oldChecksums) { String path = kv.first; + String oldChecksum = kv.second; /* Only use configuration files for checksum calculation. */ //if (!Utility::Match("*.conf", path)) // continue; @@ -631,11 +635,17 @@ bool ApiListener::CheckConfigChange(const ConfigDirInformation& oldConfig, const continue; Log(LogCritical, "ApiListener") - << "Checking " << path << " for checksum: " << kv.second; + << "Checking " << path << " for checksum: " << oldChecksum; /* Check whether our key exists in the new checksums, and they have an equal value. */ - if (newChecksums->Get(path) != kv.second) + String newChecksum = newChecksums->Get(path); + + if (newChecksums->Get(path) != kv.second) { + Log(LogCritical, "ApiListener") + << "Path '" << path << "' doesn't match old checksum '" + << newChecksum << "' with new checksum '" << oldChecksum << "'."; return true; + } } return false;