2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-06-06 08:38:28 -04:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "config/configcompiler.hpp"
|
|
|
|
|
#include "config/configitem.hpp"
|
2014-10-19 08:21:12 -04:00
|
|
|
#include "base/logger.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/utility.hpp"
|
2015-03-18 08:24:31 -04:00
|
|
|
#include "base/loader.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/context.hpp"
|
|
|
|
|
#include "base/exception.hpp"
|
2013-03-16 16:18:53 -04:00
|
|
|
#include <fstream>
|
2012-05-31 03:43:46 -04:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2013-03-16 16:18:53 -04:00
|
|
|
std::vector<String> ConfigCompiler::m_IncludeSearchDirs;
|
2021-02-02 04:16:04 -05:00
|
|
|
std::mutex ConfigCompiler::m_ZoneDirsMutex;
|
2015-07-21 03:32:17 -04:00
|
|
|
std::map<String, std::vector<ZoneFragment> > ConfigCompiler::m_ZoneDirs;
|
2013-02-01 16:44:58 -05:00
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Constructor for the ConfigCompiler class.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the configuration file (or another name that
|
2017-12-19 09:50:05 -05:00
|
|
|
* identifies the source of the configuration text).
|
2012-09-19 06:32:39 -04:00
|
|
|
* @param input Input stream for the configuration file.
|
2014-05-13 08:40:12 -04:00
|
|
|
* @param zone The zone.
|
2012-09-19 06:32:39 -04:00
|
|
|
*/
|
2018-01-04 02:54:18 -05:00
|
|
|
ConfigCompiler::ConfigCompiler(String path, std::istream *input,
|
|
|
|
|
String zone, String package)
|
|
|
|
|
: m_Path(std::move(path)), m_Input(input), m_Zone(std::move(zone)),
|
|
|
|
|
m_Package(std::move(package)), m_Eof(false), m_OpenBraces(0)
|
2012-05-31 03:43:46 -04:00
|
|
|
{
|
|
|
|
|
InitializeScanner();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Destructor for the ConfigCompiler class.
|
|
|
|
|
*/
|
2018-01-03 22:25:35 -05:00
|
|
|
ConfigCompiler::~ConfigCompiler()
|
2012-05-31 03:43:46 -04:00
|
|
|
{
|
|
|
|
|
DestroyScanner();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Reads data from the input stream. Used internally by the lexer.
|
|
|
|
|
*
|
|
|
|
|
* @param buffer Where to store data.
|
|
|
|
|
* @param max_size The maximum number of bytes to read from the stream.
|
|
|
|
|
* @returns The actual number of bytes read.
|
|
|
|
|
*/
|
2012-06-06 08:38:28 -04:00
|
|
|
size_t ConfigCompiler::ReadInput(char *buffer, size_t max_size)
|
2012-05-31 03:43:46 -04:00
|
|
|
{
|
2013-01-23 15:58:19 -05:00
|
|
|
m_Input->read(buffer, max_size);
|
2012-06-15 13:32:41 -04:00
|
|
|
return static_cast<size_t>(m_Input->gcount());
|
2012-05-31 03:43:46 -04:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Retrieves the scanner object.
|
|
|
|
|
*
|
|
|
|
|
* @returns The scanner object.
|
|
|
|
|
*/
|
2018-01-03 22:25:35 -05:00
|
|
|
void *ConfigCompiler::GetScanner() const
|
2012-05-31 03:43:46 -04:00
|
|
|
{
|
|
|
|
|
return m_Scanner;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Retrieves the path for the input file.
|
|
|
|
|
*
|
|
|
|
|
* @returns The path.
|
|
|
|
|
*/
|
2018-01-03 22:25:35 -05:00
|
|
|
const char *ConfigCompiler::GetPath() const
|
2012-07-08 15:18:35 -04:00
|
|
|
{
|
2014-12-14 05:33:45 -05:00
|
|
|
return m_Path.CStr();
|
2012-07-08 15:18:35 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-13 08:40:12 -04:00
|
|
|
void ConfigCompiler::SetZone(const String& zone)
|
|
|
|
|
{
|
|
|
|
|
m_Zone = zone;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
String ConfigCompiler::GetZone() const
|
2014-05-13 08:40:12 -04:00
|
|
|
{
|
|
|
|
|
return m_Zone;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-28 11:58:29 -04:00
|
|
|
void ConfigCompiler::SetPackage(const String& package)
|
2014-11-15 02:20:22 -05:00
|
|
|
{
|
2015-08-28 11:58:29 -04:00
|
|
|
m_Package = package;
|
2015-08-17 10:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
String ConfigCompiler::GetPackage() const
|
2015-08-17 10:08:57 -04:00
|
|
|
{
|
2015-08-28 11:58:29 -04:00
|
|
|
return m_Package;
|
2015-08-17 10:08:57 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
void ConfigCompiler::CollectIncludes(std::vector<std::unique_ptr<Expression> >& expressions,
|
2017-12-19 09:50:05 -05:00
|
|
|
const String& file, const String& zone, const String& package)
|
2015-08-17 10:08:57 -04:00
|
|
|
{
|
2016-07-05 09:40:49 -04:00
|
|
|
try {
|
2017-12-14 23:34:46 -05:00
|
|
|
expressions.emplace_back(CompileFile(file, zone, package));
|
2016-07-05 09:40:49 -04:00
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
|
Log(LogWarning, "ConfigCompiler")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Cannot compile file '"
|
|
|
|
|
<< file << "': " << DiagnosticInformation(ex);
|
2016-07-05 09:40:49 -04:00
|
|
|
}
|
2014-11-15 02:20:22 -05:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
2013-11-29 04:39:48 -05:00
|
|
|
* Handles an include directive.
|
2012-09-19 06:32:39 -04:00
|
|
|
*
|
2015-10-22 03:46:31 -04:00
|
|
|
* @param relativeBath The path this include is relative to.
|
|
|
|
|
* @param path The path from the include directive.
|
2013-02-01 16:44:58 -05:00
|
|
|
* @param search Whether to search global include dirs.
|
2013-02-02 19:41:00 -05:00
|
|
|
* @param debuginfo Debug information.
|
2012-09-19 06:32:39 -04:00
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::HandleInclude(const String& relativeBase, const String& path,
|
2017-12-19 09:50:05 -05:00
|
|
|
bool search, const String& zone, const String& package, const DebugInfo& debuginfo)
|
2012-06-01 10:49:33 -04:00
|
|
|
{
|
2015-10-22 03:46:31 -04:00
|
|
|
String upath;
|
2013-02-04 06:43:16 -05:00
|
|
|
|
2017-04-24 09:39:21 -04:00
|
|
|
if (search || (IsAbsolutePath(path)))
|
2015-10-22 03:46:31 -04:00
|
|
|
upath = path;
|
2013-02-04 06:43:16 -05:00
|
|
|
else
|
2015-10-22 03:46:31 -04:00
|
|
|
upath = relativeBase + "/" + path;
|
2013-02-02 08:28:11 -05:00
|
|
|
|
2015-10-22 03:46:31 -04:00
|
|
|
String includePath = upath;
|
2013-11-29 04:39:48 -05:00
|
|
|
|
|
|
|
|
if (search) {
|
2016-08-25 00:19:44 -04:00
|
|
|
for (const String& dir : m_IncludeSearchDirs) {
|
2015-10-22 03:46:31 -04:00
|
|
|
String spath = dir + "/" + path;
|
2013-11-29 04:39:48 -05:00
|
|
|
|
2014-05-13 08:40:12 -04:00
|
|
|
if (Utility::PathExists(spath)) {
|
2013-11-29 04:39:48 -05:00
|
|
|
includePath = spath;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
std::vector<std::unique_ptr<Expression> > expressions;
|
2021-01-18 08:29:05 -05:00
|
|
|
auto funcCallback = [&expressions, zone, package](const String& file) { CollectIncludes(expressions, file, zone, package); };
|
2013-11-29 04:39:48 -05:00
|
|
|
|
2021-01-18 08:29:05 -05:00
|
|
|
if (!Utility::Glob(includePath, funcCallback, GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
|
2013-11-29 04:39:48 -05:00
|
|
|
std::ostringstream msgbuf;
|
2015-10-22 03:46:31 -04:00
|
|
|
msgbuf << "Include file '" + path + "' does not exist";
|
2015-02-07 15:50:14 -05:00
|
|
|
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
|
2013-11-29 04:39:48 -05:00
|
|
|
}
|
2014-11-15 02:20:22 -05:00
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<DictExpression> expr{new DictExpression(std::move(expressions))};
|
2014-12-10 05:30:42 -05:00
|
|
|
expr->MakeInline();
|
2023-03-29 11:05:22 -04:00
|
|
|
return expr;
|
2013-11-29 04:39:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles recursive includes.
|
|
|
|
|
*
|
2015-10-22 03:46:31 -04:00
|
|
|
* @param relativeBase The path this include is relative to.
|
2014-11-15 02:20:22 -05:00
|
|
|
* @param path The directory path.
|
2013-11-29 04:39:48 -05:00
|
|
|
* @param pattern The file pattern.
|
|
|
|
|
* @param debuginfo Debug information.
|
|
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::HandleIncludeRecursive(const String& relativeBase, const String& path,
|
2017-12-19 09:50:05 -05:00
|
|
|
const String& pattern, const String& zone, const String& package, const DebugInfo&)
|
2013-11-29 04:39:48 -05:00
|
|
|
{
|
2014-11-15 02:20:22 -05:00
|
|
|
String ppath;
|
2013-11-29 04:39:48 -05:00
|
|
|
|
2017-04-24 09:39:21 -04:00
|
|
|
if (IsAbsolutePath(path))
|
2014-11-15 02:20:22 -05:00
|
|
|
ppath = path;
|
2013-11-29 04:39:48 -05:00
|
|
|
else
|
2015-10-22 03:46:31 -04:00
|
|
|
ppath = relativeBase + "/" + path;
|
2013-11-29 04:39:48 -05:00
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
std::vector<std::unique_ptr<Expression> > expressions;
|
2021-01-18 08:29:05 -05:00
|
|
|
Utility::GlobRecursive(ppath, pattern, [&expressions, zone, package](const String& file) {
|
|
|
|
|
CollectIncludes(expressions, file, zone, package);
|
|
|
|
|
}, GlobFile);
|
2016-06-22 11:01:36 -04:00
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<DictExpression> dict{new DictExpression(std::move(expressions))};
|
2016-06-22 11:01:36 -04:00
|
|
|
dict->MakeInline();
|
2023-03-29 11:05:22 -04:00
|
|
|
return dict;
|
2012-06-01 10:49:33 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
void ConfigCompiler::HandleIncludeZone(const String& relativeBase, const String& tag, const String& path, const String& pattern, const String& package, std::vector<std::unique_ptr<Expression> >& expressions)
|
2015-07-21 03:32:17 -04:00
|
|
|
{
|
|
|
|
|
String zoneName = Utility::BaseName(path);
|
|
|
|
|
|
|
|
|
|
String ppath;
|
|
|
|
|
|
2017-04-24 09:39:21 -04:00
|
|
|
if (IsAbsolutePath(path))
|
2015-07-21 03:32:17 -04:00
|
|
|
ppath = path;
|
|
|
|
|
else
|
2015-10-22 03:46:31 -04:00
|
|
|
ppath = relativeBase + "/" + path;
|
2015-07-21 03:32:17 -04:00
|
|
|
|
2015-07-26 11:46:47 -04:00
|
|
|
RegisterZoneDir(tag, ppath, zoneName);
|
2015-07-21 03:32:17 -04:00
|
|
|
|
2021-01-18 08:29:05 -05:00
|
|
|
Utility::GlobRecursive(ppath, pattern, [&expressions, zoneName, package](const String& file) {
|
|
|
|
|
CollectIncludes(expressions, file, zoneName, package);
|
|
|
|
|
}, GlobFile);
|
2015-07-21 03:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles zone includes.
|
|
|
|
|
*
|
2015-10-22 03:46:31 -04:00
|
|
|
* @param relativeBase The path this include is relative to.
|
2015-07-21 03:32:17 -04:00
|
|
|
* @param tag The tag name.
|
|
|
|
|
* @param path The directory path.
|
|
|
|
|
* @param pattern The file pattern.
|
|
|
|
|
* @param debuginfo Debug information.
|
|
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::HandleIncludeZones(const String& relativeBase, const String& tag,
|
2017-12-19 09:50:05 -05:00
|
|
|
const String& path, const String& pattern, const String& package, const DebugInfo&)
|
2015-07-21 03:32:17 -04:00
|
|
|
{
|
|
|
|
|
String ppath;
|
2015-12-11 10:58:43 -05:00
|
|
|
String newRelativeBase = relativeBase;
|
2015-07-21 03:32:17 -04:00
|
|
|
|
2017-04-24 09:39:21 -04:00
|
|
|
if (IsAbsolutePath(path))
|
2015-07-21 03:32:17 -04:00
|
|
|
ppath = path;
|
2015-12-11 10:58:43 -05:00
|
|
|
else {
|
2015-10-22 03:46:31 -04:00
|
|
|
ppath = relativeBase + "/" + path;
|
2015-12-11 10:58:43 -05:00
|
|
|
newRelativeBase = ".";
|
|
|
|
|
}
|
2015-07-21 03:32:17 -04:00
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
std::vector<std::unique_ptr<Expression> > expressions;
|
2021-01-18 08:29:05 -05:00
|
|
|
Utility::Glob(ppath + "/*", [newRelativeBase, tag, pattern, package, &expressions](const String& path) {
|
|
|
|
|
HandleIncludeZone(newRelativeBase, tag, path, pattern, package, expressions);
|
|
|
|
|
}, GlobDirectory);
|
|
|
|
|
|
2017-12-14 23:34:46 -05:00
|
|
|
return std::unique_ptr<Expression>(new DictExpression(std::move(expressions)));
|
2015-07-21 03:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Compiles a stream.
|
|
|
|
|
*
|
|
|
|
|
* @param path A name identifying the stream.
|
|
|
|
|
* @param stream The input stream.
|
|
|
|
|
* @returns Configuration items.
|
|
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::CompileStream(const String& path,
|
2017-12-19 09:50:05 -05:00
|
|
|
std::istream *stream, const String& zone, const String& package)
|
2012-06-06 08:38:28 -04:00
|
|
|
{
|
2022-11-24 06:40:36 -05:00
|
|
|
CONTEXT("Compiling configuration stream with name '" << path << "'");
|
2013-11-19 01:49:41 -05:00
|
|
|
|
2013-03-16 16:18:53 -04:00
|
|
|
stream->exceptions(std::istream::badbit);
|
2013-01-23 03:57:06 -05:00
|
|
|
|
2015-08-28 11:58:29 -04:00
|
|
|
ConfigCompiler ctx(path, stream, zone, package);
|
2014-11-27 02:04:07 -05:00
|
|
|
|
2015-08-24 05:04:26 -04:00
|
|
|
try {
|
|
|
|
|
return ctx.Compile();
|
|
|
|
|
} catch (const ScriptError& ex) {
|
2017-12-14 23:34:46 -05:00
|
|
|
return std::unique_ptr<Expression>(new ThrowExpression(MakeLiteral(ex.what()), ex.IsIncompleteExpression(), ex.GetDebugInfo()));
|
2015-08-24 05:04:26 -04:00
|
|
|
} catch (const std::exception& ex) {
|
2017-12-14 23:34:46 -05:00
|
|
|
return std::unique_ptr<Expression>(new ThrowExpression(MakeLiteral(DiagnosticInformation(ex)), false));
|
2015-03-18 06:12:14 -04:00
|
|
|
}
|
2012-06-06 08:38:28 -04:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Compiles a file.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path.
|
|
|
|
|
* @returns Configuration items.
|
|
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::CompileFile(const String& path, const String& zone,
|
2017-12-19 09:50:05 -05:00
|
|
|
const String& package)
|
2012-06-06 08:38:28 -04:00
|
|
|
{
|
2022-11-24 06:40:36 -05:00
|
|
|
CONTEXT("Compiling configuration file '" << path << "'");
|
2013-11-19 01:49:41 -05:00
|
|
|
|
2015-08-24 05:04:26 -04:00
|
|
|
std::ifstream stream(path.CStr(), std::ifstream::in);
|
2012-07-02 04:29:32 -04:00
|
|
|
|
2015-08-24 05:04:26 -04:00
|
|
|
if (!stream)
|
2014-04-29 18:23:20 -04:00
|
|
|
BOOST_THROW_EXCEPTION(posix_error()
|
|
|
|
|
<< boost::errinfo_api_function("std::ifstream::open")
|
|
|
|
|
<< boost::errinfo_errno(errno)
|
|
|
|
|
<< boost::errinfo_file_name(path));
|
2012-07-02 05:04:20 -04:00
|
|
|
|
2016-07-05 09:43:48 -04:00
|
|
|
Log(LogNotice, "ConfigCompiler")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Compiling config file: " << path;
|
2012-07-02 04:29:32 -04:00
|
|
|
|
2015-08-28 11:58:29 -04:00
|
|
|
return CompileStream(path, &stream, zone, package);
|
2012-06-06 08:38:28 -04:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 06:32:39 -04:00
|
|
|
/**
|
|
|
|
|
* Compiles a snippet of text.
|
|
|
|
|
*
|
|
|
|
|
* @param path A name identifying the text.
|
|
|
|
|
* @param text The text.
|
|
|
|
|
* @returns Configuration items.
|
|
|
|
|
*/
|
2017-12-14 23:34:46 -05:00
|
|
|
std::unique_ptr<Expression> ConfigCompiler::CompileText(const String& path, const String& text,
|
2017-12-19 09:50:05 -05:00
|
|
|
const String& zone, const String& package)
|
2012-06-06 08:38:28 -04:00
|
|
|
{
|
2015-08-24 05:04:26 -04:00
|
|
|
std::stringstream stream(text);
|
2015-08-28 11:58:29 -04:00
|
|
|
return CompileStream(path, &stream, zone, package);
|
2013-02-01 18:28:00 -05:00
|
|
|
}
|
|
|
|
|
|
2013-02-01 16:44:58 -05:00
|
|
|
/**
|
|
|
|
|
* Adds a directory to the list of include search dirs.
|
|
|
|
|
*
|
|
|
|
|
* @param dir The new dir.
|
|
|
|
|
*/
|
|
|
|
|
void ConfigCompiler::AddIncludeSearchDir(const String& dir)
|
|
|
|
|
{
|
2014-10-19 11:52:17 -04:00
|
|
|
Log(LogInformation, "ConfigCompiler")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Adding include search dir: " << dir;
|
2013-02-02 17:22:27 -05:00
|
|
|
|
2013-02-01 16:44:58 -05:00
|
|
|
m_IncludeSearchDirs.push_back(dir);
|
|
|
|
|
}
|
2014-11-09 07:06:25 -05:00
|
|
|
|
2015-07-21 03:32:17 -04:00
|
|
|
std::vector<ZoneFragment> ConfigCompiler::GetZoneDirs(const String& zone)
|
|
|
|
|
{
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_ZoneDirsMutex);
|
2016-08-27 02:33:15 -04:00
|
|
|
auto it = m_ZoneDirs.find(zone);
|
2015-07-21 03:32:17 -04:00
|
|
|
if (it == m_ZoneDirs.end())
|
|
|
|
|
return std::vector<ZoneFragment>();
|
|
|
|
|
else
|
2015-07-26 11:46:47 -04:00
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConfigCompiler::RegisterZoneDir(const String& tag, const String& ppath, const String& zoneName)
|
|
|
|
|
{
|
|
|
|
|
ZoneFragment zf;
|
|
|
|
|
zf.Tag = tag;
|
|
|
|
|
zf.Path = ppath;
|
2015-08-24 08:14:44 -04:00
|
|
|
|
2021-02-02 04:16:04 -05:00
|
|
|
std::unique_lock<std::mutex> lock(m_ZoneDirsMutex);
|
2015-07-26 11:46:47 -04:00
|
|
|
m_ZoneDirs[zoneName].push_back(zf);
|
2015-07-21 03:32:17 -04:00
|
|
|
}
|
2015-07-26 11:46:47 -04:00
|
|
|
|
2015-12-11 13:54:17 -05:00
|
|
|
bool ConfigCompiler::HasZoneConfigAuthority(const String& zoneName)
|
|
|
|
|
{
|
|
|
|
|
std::vector<ZoneFragment> zoneDirs = m_ZoneDirs[zoneName];
|
|
|
|
|
|
|
|
|
|
bool empty = zoneDirs.empty();
|
|
|
|
|
|
|
|
|
|
if (!empty) {
|
|
|
|
|
std::vector<String> paths;
|
2018-01-04 02:54:18 -05:00
|
|
|
paths.reserve(zoneDirs.size());
|
2019-02-15 06:24:49 -05:00
|
|
|
|
|
|
|
|
for (const ZoneFragment& zf : zoneDirs) {
|
2015-12-11 13:54:17 -05:00
|
|
|
paths.push_back(zf.Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log(LogNotice, "ConfigCompiler")
|
2017-12-19 09:50:05 -05:00
|
|
|
<< "Registered authoritative config directories for zone '" << zoneName << "': " << Utility::NaturalJoin(paths);
|
2015-12-11 13:54:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !empty;
|
|
|
|
|
}
|
2017-04-26 23:31:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ConfigCompiler::IsAbsolutePath(const String& path)
|
|
|
|
|
{
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
return (path.GetLength() > 0 && path[0] == '/');
|
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
return !PathIsRelative(path.CStr());
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 08:17:27 -04:00
|
|
|
void ConfigCompiler::AddImport(const Expression::Ptr& import)
|
2018-08-07 07:55:41 -04:00
|
|
|
{
|
|
|
|
|
m_Imports.push_back(import);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 08:17:27 -04:00
|
|
|
std::vector<Expression::Ptr> ConfigCompiler::GetImports() const
|
2018-08-07 07:55:41 -04:00
|
|
|
{
|
|
|
|
|
return m_Imports;
|
|
|
|
|
}
|