Load modified-attributes.conf before committing config items

refs #5235
This commit is contained in:
Alexander A. Klimov 2020-08-06 17:13:41 +02:00
parent 9c00ae53b3
commit 22640444dd
3 changed files with 21 additions and 3 deletions

View File

@ -254,7 +254,7 @@ bool DaemonUtility::LoadConfigFiles(const std::vector<std::string>& configs,
WorkQueue upq(25000, Configuration::Concurrency);
upq.SetName("DaemonUtility::LoadConfigFiles");
bool result = ConfigItem::CommitItems(ascope.GetContext(), upq, newItems);
bool result = ConfigItem::CommitItems(ascope.GetContext(), upq, newItems, false, true);
if (!result) {
ConfigCompilerContext::GetInstance()->CancelObjectsFile();

View File

@ -592,11 +592,28 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
return true;
}
bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent)
bool ConfigItem::CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems,
bool silent, bool withModAttrs)
{
if (!silent)
Log(LogInformation, "ConfigItem", "Committing config item(s).");
if (withModAttrs) {
/* restore modified attributes */
if (Utility::PathExists(Configuration::ModAttrPath)) {
std::unique_ptr<Expression> expression = ConfigCompiler::CompileFile(Configuration::ModAttrPath);
if (expression) {
try {
ScriptFrame frame(true);
expression->Evaluate(frame);
} catch (const std::exception& ex) {
Log(LogCritical, "config", DiagnosticInformation(ex));
}
}
}
}
if (!CommitNewItems(context, upq, newItems)) {
upq.ReportExceptions("config");

View File

@ -52,7 +52,8 @@ public:
static ConfigItem::Ptr GetByTypeAndName(const Type::Ptr& type,
const String& name);
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems, bool silent = false);
static bool CommitItems(const ActivationContext::Ptr& context, WorkQueue& upq, std::vector<ConfigItem::Ptr>& newItems,
bool silent = false, bool withModAttrs = false);
static bool ActivateItems(const std::vector<ConfigItem::Ptr>& newItems, bool runtimeCreated = false,
bool mainConfigActivation = false, bool withModAttrs = false, const Value& cookie = Empty);