Ensure that config master zones.d -> var-api-zones sync removes deleted files

This commit is contained in:
Michael Friedrich 2018-09-28 16:51:20 +02:00
parent 9d53db1401
commit 4e9439f2d8
1 changed files with 13 additions and 6 deletions

View File

@ -167,11 +167,16 @@ bool ApiListener::UpdateConfigDir(const ConfigDirInformation& oldConfigInfo, con
void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
{ {
if (!zone)
return;
ConfigDirInformation newConfigInfo; ConfigDirInformation newConfigInfo;
newConfigInfo.UpdateV1 = new Dictionary(); newConfigInfo.UpdateV1 = new Dictionary();
newConfigInfo.UpdateV2 = new Dictionary(); newConfigInfo.UpdateV2 = new Dictionary();
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zone->GetName())) { String zoneName = zone->GetName();
for (const ZoneFragment& zf : ConfigCompiler::GetZoneDirs(zoneName)) {
ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path); ConfigDirInformation newConfigPart = LoadConfigDir(zf.Path);
{ {
@ -194,17 +199,19 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
if (sumUpdates == 0) if (sumUpdates == 0)
return; return;
String oldDir = Configuration::DataDir + "/api/zones/" + zone->GetName(); String currentDir = Configuration::DataDir + "/api/zones/" + zoneName;
Log(LogInformation, "ApiListener") Log(LogInformation, "ApiListener")
<< "Copying " << sumUpdates << " zone configuration files for zone '" << zone->GetName() << "' to '" << oldDir << "'."; << "Copying " << sumUpdates << " zone configuration files for zone '" << zoneName << "' to '" << currentDir << "'.";
Utility::MkDirP(oldDir, 0700); ConfigDirInformation oldConfigInfo = LoadConfigDir(currentDir);
ConfigDirInformation oldConfigInfo = LoadConfigDir(oldDir); /* Purge files to allow deletion via zones.d. */
Utility::RemoveDirRecursive(currentDir);
Utility::MkDirP(currentDir, 0700);
std::vector<String> relativePaths; std::vector<String> relativePaths;
UpdateConfigDir(oldConfigInfo, newConfigInfo, oldDir, zone->GetName(), relativePaths, true); UpdateConfigDir(oldConfigInfo, newConfigInfo, currentDir, zoneName, relativePaths, true);
} }
void ApiListener::SyncZoneDirs() const void ApiListener::SyncZoneDirs() const