Fix syncing zones.d from etc/ to var/lib in a recursive manner

Missing mkdir -p basically. Introducing Utility::MkDirP() which still
requires Win32 implementation.

refs #6328
This commit is contained in:
Michael Friedrich 2014-06-12 22:51:48 +02:00
parent 9e026959db
commit 2acf6a063e
4 changed files with 34 additions and 3 deletions

View File

@ -23,6 +23,7 @@
#include "base/logger_fwd.hpp"
#include "base/exception.hpp"
#include "base/socket.hpp"
#include "base/utility.hpp"
#include <mmatch.h>
#include <boost/lexical_cast.hpp>
#include <boost/foreach.hpp>
@ -670,6 +671,31 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const boo
return true;
}
int Utility::MkDirP(const String& path, int flags)
{
#ifdef _WIN32
/* TODO */
return 0;
#else /* _WIN32 */
if (path.IsEmpty()) {
errno = EINVAL;
return 1;
}
if (path.GetLength() == 1 && path[0] == '.')
return 0;
String dir = DirName(path);
MkDirP(dir, flags);
return mkdir(dir.CStr(), flags);
#endif /* _WIN32 */
}
#ifndef _WIN32
void Utility::SetNonBlocking(int fd)
{

View File

@ -81,6 +81,7 @@ public:
static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
static bool GlobRecursive(const String& path, const String& pattern, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
static int MkDirP(const String& path, int flags);
static void QueueAsyncCallback(const boost::function<void (void)>& callback);

View File

@ -35,10 +35,12 @@ bool ApiListener::IsConfigMaster(const Zone::Ptr& zone) const
return Utility::PathExists(path);
}
void ApiListener::ConfigGlobHandler(const Dictionary::Ptr& config, const String& path, const String& file)
void ApiListener::ConfigGlobHandler(Dictionary::Ptr& config, const String& path, const String& file)
{
CONTEXT("Creating config update for file '" + file + "'");
Log(LogNotice, "ApiListener", "Creating config update for file '" + file + "'");
std::ifstream fp(file.CStr());
if (!fp)
return;
@ -50,7 +52,7 @@ void ApiListener::ConfigGlobHandler(const Dictionary::Ptr& config, const String&
Dictionary::Ptr ApiListener::LoadConfigDir(const String& dir)
{
Dictionary::Ptr config = make_shared<Dictionary>();
Utility::GlobRecursive(dir, "*.conf", boost::bind(&ApiListener::ConfigGlobHandler, config, dir, _1), GlobFile);
Utility::GlobRecursive(dir, "*.conf", boost::bind(&ApiListener::ConfigGlobHandler, boost::ref(config), dir, _1), GlobFile);
return config;
}
@ -74,6 +76,8 @@ bool ApiListener::UpdateConfigDir(const Dictionary::Ptr& oldConfig, const Dictio
String path = configDir + "/" + kv.first;
Log(LogInformation, "ApiListener", "Updating configuration file: " + path);
//TODO mkdir -p?
Utility::MkDirP(path, 0755);
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
fp << kv.second;
fp.close();

View File

@ -110,7 +110,7 @@ private:
void SyncZoneDir(const Zone::Ptr& zone) const;
bool IsConfigMaster(const Zone::Ptr& zone) const;
static void ConfigGlobHandler(const Dictionary::Ptr& config, const String& path, const String& file);
static void ConfigGlobHandler(Dictionary::Ptr& config, const String& path, const String& file);
void SendConfigUpdate(const ApiClient::Ptr& aclient);
};