From 47db64e3602dfb8b301b439110fe7ee830434440 Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Sat, 3 Oct 2026 22:40:53 +0800 Subject: [PATCH] fix: demote DConfig warnings when meta file is not installed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Can't acquire config manager" and "DConfig is invalid" were printed at warning level in two expected cases: the config resource's meta file is simply not installed on the system (e.g. an optional component's config accessed unconditionally). The daemon replies with a generic org.freedesktop.DBus.Error.Failed for a missing resource, which cannot be distinguished from real failures by error name. Check the meta path locally with the same lookup logic the daemon uses (DConfigMetaImpl::metaPath via DConfigFile) and demote both messages to debug output when the meta file is missing, keeping the warning level for real backend failures (meta present but the backend could not be created, e.g. dde-dconfig-daemon unavailable). 修复元数据未安装时 DConfig 的告警误报: 配置资源的 meta 文件未安装属预期场景(如可选组件的配置被无条件 读取),此前 "Can't acquire config manager" 与 "DConfig is invalid" 均以 warning 级别打印。daemon 对缺资源返回通用 Failed 错误,无法按 错误名区分。现用与 daemon 同源的 meta 查找(DConfigFile 的 metaPath)在本地判断:meta 未安装降为 qCDebug,meta 在位但后端 创建失败(如 daemon 不可用)保留 qCWarning。 PMS: TASK-394335 --- src/dconfig.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/dconfig.cpp b/src/dconfig.cpp index 346a696a..77046de8 100644 --- a/src/dconfig.cpp +++ b/src/dconfig.cpp @@ -138,6 +138,7 @@ DConfigBackend::~DConfigBackend() } static QString _globalAppId; + class Q_DECL_HIDDEN DConfigPrivate : public DObjectPrivate { public: @@ -154,12 +155,39 @@ class Q_DECL_HIDDEN DConfigPrivate : public DObjectPrivate virtual ~DConfigPrivate() override; +#ifndef D_DISABLE_DCONFIG + // Checks whether the meta file for this config is installed locally, + // using the same lookup logic as dde-dconfig-daemon + // (DConfigMetaImpl::metaPath). Used to distinguish "config resource + // never installed" (expected, debug-level) from real backend failures. + bool metaInstalled() const + { + DConfigFile configFile(appId, name, subpath); + return !configFile.meta()->metaPath().isEmpty(); + } +#endif + inline bool invalid() const { const bool valid = backend && backend->isValid(); - if (!valid) + if (!valid) { +#ifndef D_DISABLE_DCONFIG + // A missing meta file means the config resource was simply never + // installed; demote that expected case to debug output and keep + // the warning for real backend failures (meta present but the + // backend could not be created, e.g. daemon unavailable). + if (metaInstalled()) { + qCWarning(cfLog, "DConfig is invalid of appid=%s name=%s, subpath=%s", + qPrintable(appId), qPrintable(name), qPrintable(subpath)); + } else { + qCDebug(cfLog, "DConfig is invalid of appid=%s name=%s, subpath=%s (meta file not installed)", + qPrintable(appId), qPrintable(name), qPrintable(subpath)); + } +#else qCWarning(cfLog, "DConfig is invalid of appid=%s name=%s, subpath=%s", qPrintable(appId), qPrintable(name), qPrintable(subpath)); +#endif + } return !valid; } @@ -379,7 +407,15 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend const QDBusObjectPath dbus_path = dbus_reply.value(); const auto path = dbus_path.path(); // 显式拷贝,避免其它线程共用systemBus连接而修改dbus数据 if (dbus_reply.isError() || path.isEmpty()) { - qCWarning(cfLog, "Can't acquire config manager. error:\"%s\"", qPrintable(dbus_reply.error().message())); + // The daemon replies with a generic Failed error for a missing + // resource, which cannot be told apart by error name; check the + // meta path locally to keep real failures visible. + if (owner->metaInstalled()) { + qCWarning(cfLog, "Can't acquire config manager. error:\"%s\"", qPrintable(dbus_reply.error().message())); + } else { + qCDebug(cfLog, "Can't acquire config manager. error:\"%s\" (meta file not installed)", + qPrintable(dbus_reply.error().message())); + } return false; } else { qCDebug(cfLog, "dbus path=\"%s\"", qPrintable(path));