<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", oldTimestamp) << "' ("
<< oldTimestamp << ").";
+ /* TODO: Deal with recursive directories. */
ObjectLock xlock(oldConfig);
for (const Dictionary::Pair& kv : oldConfig) {
if (!newConfig->Contains(kv.first)) {
bool configChange = false;
std::vector<String> relativePaths;
+ /*
+ * We can and must safely purge the staging directory, as the difference is taken between
+ * runtime production config and newly received configuration.
+ */
+ String apiZonesStageDir = GetApiZonesStageDir();
+ Utility::RemoveDirRecursive(apiZonesStageDir);
+ Utility::MkDirP(apiZonesStageDir, 0700);
+
ObjectLock olock(updateV1);
for (const Dictionary::Pair& kv : updateV1) {
Dictionary::Ptr newConfig = kv.second;
ConfigDirInformation currentConfigInfo = LoadConfigDir(currentConfigDir);
- /* Move the received configuration into our stage directory first. */
+ /* Diff the current production configuration with the received configuration.
+ * If there was a change, collect a signal for later stage validation.
+ */
if (UpdateConfigDir(currentConfigInfo, newConfigInfo, stageConfigDir, zoneName, relativePaths, false))
configChange = true;
}
/* validation went fine, copy stage and reload */
if (pr.ExitStatus == 0) {
Log(LogInformation, "ApiListener")
- << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, copying into '" << GetApiZonesDir() << "' and triggering reload.";
+ << "Config validation for stage '" << GetApiZonesStageDir() << "' was OK, replacing into '" << GetApiZonesDir() << "' and triggering reload.";
+
+ String apiZonesDir = GetApiZonesDir();
+
+ /* Purge production before copying stage. */
+ Utility::RemoveDirRecursive(apiZonesDir);
+ Utility::MkDirP(apiZonesDir, 0700);
+ /* Copy all synced configuration files from stage to production. */
for (const String& path : relativePaths) {
Log(LogNotice, "ApiListener")
<< "Copying file '" << path << "' from config sync staging to production zones directory.";
String stagePath = GetApiZonesStageDir() + path;
String currentPath = GetApiZonesDir() + path;
- Utility::MkDirP(Utility::DirName(currentPath), 0755);
+ Utility::MkDirP(Utility::DirName(currentPath), 0700);
Utility::CopyFile(stagePath, currentPath);
}