From e17290fafb8995df51f136dfd15b7d3715e47e41 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Thu, 5 Feb 2026 16:27:54 +0800 Subject: [PATCH] fix: remove FileHandler backend and add null checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changes remove the FileHandler backend functionality from the value handler creation process and add null pointer checks for ConfigGetter instances. The FileHandler backend was causing issues with directory writing operations, leading to potential data corruption or configuration problems. By removing this backend, the system now relies solely on the DBusHandler for configuration management, ensuring consistent behavior across the application. Additionally, multiple null pointer checks have been added when creating ConfigGetter instances in various UI components (MainWindow, Content, HistoryDialog) to prevent crashes when manager creation fails. These checks provide graceful error handling with appropriate warning messages. Log: Fixed configuration management issues by removing problematic file backend Influence: 1. Test configuration value retrieval through the UI to ensure no regression 2. Verify that reset operations work correctly for configuration keys 3. Test context menu functionality in the configuration editor 4. Validate history dialog operations with various configuration resources 5. Ensure error cases are handled gracefully with appropriate warnings 6. Test configuration operations with both valid and invalid resource paths fix: 移除FileHandler后端并添加空指针检查 本次修改移除了值处理器创建过程中的FileHandler后端功能,并为ConfigGetter 实例添加了空指针检查。FileHandler后端会导致目录写入操作出现问题,可能引 发数据损坏或配置问题。通过移除此后端,系统现在仅依赖DBusHandler进行配置 管理,确保应用程序行为的一致性。 此外,在多个UI组件(MainWindow、Content、HistoryDialog)中创建 ConfigGetter实例时添加了空指针检查,以防止管理器创建失败时程序崩溃。这些 检查提供了优雅的错误处理机制,并输出适当的警告信息。 Log: 通过移除有问题的文件后端修复了配置管理问题 Influence: 1. 测试通过UI获取配置值,确保功能没有退化 2. 验证配置键的重置操作是否正常工作 3. 测试配置编辑器中的上下文菜单功能 4. 使用各种配置资源验证历史对话框操作 5. 确保错误情况得到优雅处理并显示适当的警告 6. 测试使用有效和无效资源路径的配置操作 PMS: BUG-312173 Change-Id: Iae5db6d3701fe579dc4b0af8e4b6a4ae0f7c9e44 --- dconfig-center/common/valuehandler.cpp | 7 +------ dconfig-center/dde-dconfig-editor/mainwindow.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dconfig-center/common/valuehandler.cpp b/dconfig-center/common/valuehandler.cpp index cb1bd57..eb02357 100644 --- a/dconfig-center/common/valuehandler.cpp +++ b/dconfig-center/common/valuehandler.cpp @@ -309,12 +309,7 @@ ConfigGetter* ValueHandler::createManager() if (tmp->createManager(appid, fileName, subpath)) { return tmp; } - } else { - auto tmp = new FileHandler(this); - if (tmp->createManager(appid, fileName, subpath)) { - qDebug() << QString("using FileHandler to get value for appid=%1, resource=%2, subpath=%3.").arg(appid, fileName, subpath); - return tmp; - } + delete tmp; // 创建失败,释放内存 } qWarning() << QString("get value handler error for appid=%1, resource=%2, subpath=%3.").arg(appid, fileName, subpath); return nullptr; diff --git a/dconfig-center/dde-dconfig-editor/mainwindow.cpp b/dconfig-center/dde-dconfig-editor/mainwindow.cpp index 231b278..955c376 100644 --- a/dconfig-center/dde-dconfig-editor/mainwindow.cpp +++ b/dconfig-center/dde-dconfig-editor/mainwindow.cpp @@ -316,6 +316,10 @@ void MainWindow::onCustomResourceMenuRequested(const QString &appid, const QStri connect(resetCmdAction, &QAction::triggered, this, [this, appid, resource, subpath] { QScopedPointer getter(new ValueHandler(appid, resource, subpath)); QScopedPointer manager(getter->createManager()); + if (!manager) { + qWarning() << "Failed to create manager for reset command"; + return; + } const auto keys = manager->keyList(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) for (const auto &item : std::as_const(keys)) { @@ -607,6 +611,10 @@ void Content::onCustomContextMenuRequested(QWidget *widget, const QString &appid { m_getter.reset(new ValueHandler(appid, resource, subpath)); QScopedPointer manager(m_getter->createManager()); + if (!manager) { + qWarning() << "Failed to create manager for context menu"; + return; + } const QString &value = qvariantToCmd(manager.get()->value(key)); const QString &description = manager.get()->description(key, m_language); @@ -654,6 +662,10 @@ void Content::onCustomContextMenuRequested(QWidget *widget, const QString &appid connect(resetCmdAction, &QAction::triggered, this, [this, key, widget] { QScopedPointer manager(m_getter->createManager()); + if (!manager) { + qWarning() << "Failed to create manager for reset"; + return; + } const auto &old = manager->value(key); manager->reset(key); if (auto contentWidget = qobject_cast(widget)) { @@ -796,6 +808,10 @@ HistoryDialog::HistoryDialog(QWidget *parent) { QScopedPointer manager(handler.createManager()); + if (!manager) { + qWarning() << "Failed to create manager for history"; + return; + } if (manager) { const auto &key = historyView->model()->data(index, ConfigUserRole + 5).toString();