This commit is contained in:
Alexander Aleksandrovič Klimov 2026-02-03 15:23:52 +01:00 committed by GitHub
commit bb423e7fa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 14 deletions

View file

@ -36,7 +36,9 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
l_StatsNS = new Namespace(true);
globalNS->Set("StatsFunctions", l_StatsNS, true);
globalNS->Set("Internal", new Namespace(), true);
Namespace::Ptr intNS = new Namespace();
intNS->Set("modified_attributes", new Dictionary(), true);
globalNS->Set("Internal", intNS, true);
}, InitializePriority::CreateNamespaces);
INITIALIZE_ONCE_WITH_PRIORITY([]() {

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

@ -191,6 +191,20 @@ ConfigObject::Ptr ConfigItem::Commit(bool discard)
m_Scope->CopyTo(frame.Locals);
try {
m_Expression->Evaluate(frame, &debugHints);
Dictionary::Ptr allMods (Namespace::Ptr(ScriptGlobal::Get("Internal"))->Get("modified_attributes"));
Dictionary::Ptr typeMods (allMods->Get(type->GetName()));
if (typeMods) {
Function::Ptr objMods (typeMods->Get(m_Name));
if (objMods) {
objMods->Invoke({dobj});
ObjectLock oLock(typeMods);
typeMods->Remove(m_Name);
}
}
} catch (const std::exception& ex) {
if (m_IgnoreOnError) {
Log(LogNotice, "ConfigObject")
@ -594,11 +608,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");
@ -646,7 +677,9 @@ bool ConfigItem::ActivateItems(const std::vector<ConfigItem::Ptr>& newItems, boo
{
if (withModAttrs) {
/* restore modified attributes */
if (Utility::PathExists(Configuration::ModAttrPath)) {
if (Utility::PathExists(Configuration::ModAttrPath) &&
!Dictionary::Ptr(Namespace::Ptr(ScriptGlobal::Get("Internal"))->Get("modified_attributes"))->GetLength()
) {
std::unique_ptr<Expression> expression = ConfigCompiler::CompileFile(Configuration::ModAttrPath);
if (expression) {

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);

View file

@ -135,15 +135,11 @@ static void PersistModAttrHelper(AtomicFile& fp, ConfigObject::Ptr& previousObje
ConfigWriter::EmitRaw(fp, "\n}\n\n");
}
ConfigWriter::EmitRaw(fp, "var obj = ");
Array::Ptr args1 = new Array({
object->GetReflectionType()->GetName(),
object->GetName()
});
ConfigWriter::EmitFunctionCall(fp, "get_object", args1);
ConfigWriter::EmitRaw(fp, "\nif (obj) {\n");
ConfigWriter::EmitRaw(fp, "Internal.modified_attributes[");
ConfigWriter::EmitValue(fp, 0, object->GetReflectionType()->GetName());
ConfigWriter::EmitRaw(fp, "][");
ConfigWriter::EmitValue(fp, 0, object->GetName());
ConfigWriter::EmitRaw(fp, "] = obj => {\n");
}
ConfigWriter::EmitRaw(fp, "\tobj.");