MCPcopy Create free account
hub / github.com/Icinga/icinga2 / HandleInclude

Method HandleInclude

lib/config/configcompiler.cpp:116–151  ·  view source on GitHub ↗

* Handles an include directive. * * @param relativeBath The path this include is relative to. * @param path The path from the include directive. * @param search Whether to search global include dirs. * @param debuginfo Debug information. */

Source from the content-addressed store, hash-verified

114 * @param debuginfo Debug information.
115 */
116std::unique_ptr<Expression> ConfigCompiler::HandleInclude(const String& relativeBase, const String& path,
117 bool search, const String& zone, const String& package, const DebugInfo& debuginfo)
118{
119 String upath;
120
121 if (search || (IsAbsolutePath(path)))
122 upath = path;
123 else
124 upath = relativeBase + "/" + path;
125
126 String includePath = upath;
127
128 if (search) {
129 for (const String& dir : m_IncludeSearchDirs) {
130 String spath = dir + "/" + path;
131
132 if (Utility::PathExists(spath)) {
133 includePath = spath;
134 break;
135 }
136 }
137 }
138
139 std::vector<std::unique_ptr<Expression> > expressions;
140 auto funcCallback = [&expressions, zone, package](const String& file) { CollectIncludes(expressions, file, zone, package); };
141
142 if (!Utility::Glob(includePath, funcCallback, GlobFile) && includePath.FindFirstOf("*?") == String::NPos) {
143 std::ostringstream msgbuf;
144 msgbuf << "Include file '" + path + "' does not exist";
145 BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debuginfo));
146 }
147
148 std::unique_ptr<DictExpression> expr{new DictExpression(std::move(expressions))};
149 expr->MakeInline();
150 return expr;
151}
152
153/**
154 * Handles recursive includes.

Callers

nothing calls this directly

Calls 4

PathExistsFunction · 0.85
ScriptErrorClass · 0.85
FindFirstOfMethod · 0.80
MakeInlineMethod · 0.80

Tested by

no test coverage detected