count = 0;
std::vector<int> files;
- Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1));
+ Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1), GlobFile);
std::sort(files.begin(), files.end());
BOOST_FOREACH(int ts, files) {
void ClusterListener::ConfigGlobHandler(const Dictionary::Ptr& config, const String& file, bool basename)
{
+ CONTEXT("Creating config update for file '" + file + "'");
+
Dictionary::Ptr elem = make_shared<Dictionary>();
std::ifstream fp(file.CStr());
if (configFiles) {
ObjectLock olock(configFiles);
BOOST_FOREACH(const String& pattern, configFiles) {
- Utility::Glob(pattern, boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(config), _1, false));
+ Utility::Glob(pattern, boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(config), _1, false), GlobFile);
}
}
}
std::vector<int> files;
- Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1));
+ Utility::Glob(GetClusterDir() + "log/*", boost::bind(&ClusterListener::LogGlobHandler, boost::ref(files), _1), GlobFile);
std::sort(files.begin(), files.end());
BOOST_FOREACH(int ts, files) {
}
Dictionary::Ptr localConfig = make_shared<Dictionary>();
- Utility::Glob(dir + "/*", boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(localConfig), _1, true));
+ Utility::Glob(dir + "/*", boost::bind(&ClusterListener::ConfigGlobHandler, boost::cref(localConfig), _1, true), GlobFile);
bool configChange = false;
void LogTable::CreateLogIndex(const String& path)
{
- Utility::Glob(path + "/icinga.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
- Utility::Glob(path + "/archives/*.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
+ Utility::Glob(path + "/icinga.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
+ Utility::Glob(path + "/archives/*.log", boost::bind(&LogTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
}
void LogTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
void StateHistTable::CreateLogIndex(const String& path)
{
- Utility::Glob(path + "/icinga.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
- Utility::Glob(path + "/archives/*.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)));
+ Utility::Glob(path + "/icinga.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
+ Utility::Glob(path + "/archives/*.log", boost::bind(&StateHistTable::CreateLogIndexFileHandler, _1, boost::ref(m_LogFileIndex)), GlobFile);
}
void StateHistTable::CreateLogIndexFileHandler(const String& path, std::map<unsigned long, String>& index)
#include <sys/wait.h>
#include <glob.h>
#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
typedef int SOCKET;
#define INVALID_SOCKET (-1)
* Calls the specified callback for each file matching the path specification.
*
* @param pathSpec The path specification.
+ * @param callback The callback which is invoked for each matching file.
+ * @param type The file type (a combination of GlobFile and GlobDirectory)
*/
-bool Utility::Glob(const String& pathSpec, const boost::function<void (const String&)>& callback)
+bool Utility::Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type)
{
#ifdef _WIN32
HANDLE handle;
}
do {
+ if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(type & GlobDirectory))
+ continue;
+
+ if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(type & GlobFile))
+ continue;
+
callback(DirName(pathSpec) + "/" + wfd.cFileName);
} while (FindNextFile(handle, &wfd));
size_t left;
char **gp;
for (gp = gr.gl_pathv, left = gr.gl_pathc; left > 0; gp++, left--) {
+ struct stat statbuf;
+
+ if (lstat(*gp, &statbuf) < 0)
+ continue;
+
+ if (!S_ISDIR(statbuf.st_mode) && !S_ISREG(statbuf.st_mode))
+ continue;
+
+ if (S_ISDIR(statbuf.st_mode) && !(type & GlobDirectory))
+ continue;
+
+ if (!S_ISDIR(statbuf.st_mode) && !(type & GlobFile))
+ continue;
+
callback(*gp);
}
# pragma pack(pop)
#endif
+enum GlobType
+{
+ GlobFile = 1,
+ GlobDirectory = 2
+};
+
/**
* Helper functions.
*
static String NewUniqueID(void);
- static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback);
+ static bool Glob(const String& pathSpec, const boost::function<void (const String&)>& callback, int type = GlobFile | GlobDirectory);
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
std::vector<ConfigItem::Ptr> items;
- if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1)) && includePath.FindFirstOf("*?") == String::NPos) {
+ if (!Utility::Glob(includePath, boost::bind(&ConfigCompiler::CompileFile, _1), GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
std::ostringstream msgbuf;
msgbuf << "Include file '" + include + "' does not exist: " << debuginfo;
BOOST_THROW_EXCEPTION(std::invalid_argument(msgbuf.str()));