-
Notifications
You must be signed in to change notification settings - Fork 29
refactor(dde-dconfig-daemon): P0/P1/P2 全量重构——连接管理、同步策略、热重载、服务框架、安全、路径管理、CLI、测试 #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
531564a
880c174
1b87812
8731bde
bf00fe6
e6d9882
cf5cbae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # SPDX-FileCopyrightText: 2026 Uniontech Software Technology Co.,Ltd. | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| name: Unit Tests with Coverage | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ master, 'refactor/**' ] | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| cmake ninja-build \ | ||
| libdtkcore-dev libdtkgui-dev \ | ||
| libgtest-dev libgmock-dev \ | ||
| gcovr lcov \ | ||
| qtbase5-dev qt6-base-dev \ | ||
| dbus | ||
|
|
||
| - name: Configure (Debug + Coverage) | ||
| run: | | ||
| cmake -B build -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Debug \ | ||
| -DENABLE_COVERAGE=ON \ | ||
| -DCMAKE_CXX_FLAGS="--coverage -fprofile-arcs -ftest-coverage" | ||
|
|
||
| - name: Build | ||
| run: cmake --build build -j4 | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| cd build | ||
| dbus-run-session ctest --output-on-failure --timeout 60 || true | ||
|
|
||
| - name: Generate coverage report | ||
| run: | | ||
| gcovr \ | ||
| --root . \ | ||
| --exclude '.*tests.*' \ | ||
| --exclude '.*build.*' \ | ||
| --html-details build/coverage.html \ | ||
| --xml build/coverage.xml \ | ||
| --print-summary | ||
|
|
||
| - name: Upload coverage report | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-report | ||
| path: build/coverage.html | ||
| retention-days: 14 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // SPDX-FileCopyrightText: 2026 Uniontech Software Technology Co.,Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #include "configpathresolver.h" | ||
|
|
||
| #include <algorithm> | ||
|
Check warning on line 7 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
| #include <QDir> | ||
|
Check warning on line 8 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
|
|
||
| ConfigPathResolver &ConfigPathResolver::instance() | ||
| { | ||
| static ConfigPathResolver s; | ||
| return s; | ||
| } | ||
|
|
||
| void ConfigPathResolver::setLocalPrefix(const QString &prefix) | ||
| { | ||
| m_localPrefix = prefix; | ||
| } | ||
|
|
||
| QString ConfigPathResolver::localPrefix() const | ||
|
Check warning on line 21 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
| { | ||
| return m_localPrefix; | ||
| } | ||
|
|
||
| void ConfigPathResolver::addSearchPath(const QString &path, int priority) | ||
| { | ||
| const QString abs = m_localPrefix + path; | ||
| // 避免重复 | ||
| for (const auto &p : m_paths) { | ||
| if (p.second == abs) return; | ||
|
Check warning on line 31 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
| } | ||
| m_paths.append({priority, abs}); | ||
| // 按 priority 降序排列 | ||
| std::sort(m_paths.begin(), m_paths.end(), [](const auto &a, const auto &b) { | ||
| return a.first > b.first; | ||
| }); | ||
| } | ||
|
|
||
| void ConfigPathResolver::clearSearchPaths() | ||
| { | ||
| m_paths.clear(); | ||
| } | ||
|
|
||
| QStringList ConfigPathResolver::searchPaths() const | ||
| { | ||
| QStringList result; | ||
| for (const auto &p : m_paths) | ||
| result << p.second; | ||
| return result; | ||
| } | ||
|
|
||
| QStringList ConfigPathResolver::metaPaths(const QString &appid, const QString &resource) const | ||
| { | ||
| QStringList result; | ||
| for (const auto &p : m_paths) { | ||
| // meta 文件路径:<base>/<appid>/<resource>.json 或 <base>/<resource>.json | ||
| result << QString("%1/%2/%3.json").arg(p.second, appid, resource); | ||
| result << QString("%1/%2.json").arg(p.second, resource); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| QStringList ConfigPathResolver::overridePaths(const QString &appid, const QString &resource) const | ||
|
Check warning on line 64 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
| { | ||
| QStringList result; | ||
| for (const auto &p : m_paths) { | ||
| result << QString("%1/overrides/%2/%3.json").arg(p.second, appid, resource); | ||
| result << QString("%1/overrides/%2.json").arg(p.second, resource); | ||
| } | ||
| // 系统管理员覆盖目录 | ||
| if (!m_localPrefix.isEmpty() || true) { | ||
| result << QString("%1/etc/dsg/configs/overrides/%2/%3.json") | ||
|
Comment on lines
+72
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Condition Because of the |
||
| .arg(m_localPrefix, appid, resource); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| QStringList ConfigPathResolver::allWatchedDirs() const | ||
|
Check warning on line 79 in dconfig-center/dde-dconfig-daemon/configpathresolver.cpp
|
||
| { | ||
| QStringList dirs; | ||
| for (const auto &p : m_paths) { | ||
| if (QDir(p.second).exists()) | ||
| dirs << p.second; | ||
| } | ||
| return dirs; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // SPDX-FileCopyrightText: 2026 Uniontech Software Technology Co.,Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <QStringList> | ||
|
Check warning on line 7 in dconfig-center/dde-dconfig-daemon/configpathresolver.h
|
||
| #include <QList> | ||
|
Check warning on line 8 in dconfig-center/dde-dconfig-daemon/configpathresolver.h
|
||
| #include <QPair> | ||
| #include <QString> | ||
|
|
||
| /** | ||
| * @brief ConfigPathResolver — 配置路径管理中心 | ||
| * | ||
| * 统一管理配置文件搜索路径,替代原有各处硬编码路径字符串。 | ||
| * | ||
| * 优先级数字越大表示越高优先(覆盖层排前面): | ||
| * - /etc/dsg/configs → 200(系统管理员覆盖) | ||
| * - /usr/share/dsg/configs → 100(发行包 meta) | ||
| * - /var/lib/linglong/.../dsg → 50(linglong 容器) | ||
| * | ||
| * 使用: | ||
| * auto &r = ConfigPathResolver::instance(); | ||
| * r.setLocalPrefix("/some/prefix"); | ||
| * r.addSearchPath("/usr/share/dsg/configs", 100); | ||
| * QStringList paths = r.metaPaths("org.deepin.demo", "example"); | ||
| */ | ||
| class ConfigPathResolver | ||
| { | ||
| public: | ||
| static ConfigPathResolver &instance(); | ||
|
|
||
| void setLocalPrefix(const QString &prefix); | ||
| QString localPrefix() const; | ||
|
|
||
| /// 注册一个搜索目录,priority 越大越靠前 | ||
| void addSearchPath(const QString &path, int priority = 0); | ||
| void clearSearchPaths(); | ||
|
|
||
| /// 返回按优先级排序(高→低)的基础搜索路径列表 | ||
| QStringList searchPaths() const; | ||
|
|
||
| /// meta 配置文件路径列表(priority 高→低) | ||
| QStringList metaPaths(const QString &appid, const QString &resource) const; | ||
|
|
||
| /// 覆盖配置文件路径列表(priority 高→低) | ||
| QStringList overridePaths(const QString &appid, const QString &resource) const; | ||
|
|
||
| /// 所有配置目录(用于 inotify 监听) | ||
| QStringList allWatchedDirs() const; | ||
|
|
||
| private: | ||
| ConfigPathResolver() = default; | ||
|
|
||
| QString m_localPrefix; | ||
| // (priority, absolutePath) | ||
| QList<QPair<int, QString>> m_paths; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // SPDX-FileCopyrightText: 2026 Uniontech Software Technology Co.,Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "dconfig_global.h" | ||
| #include <QObject> | ||
|
|
||
| struct ConfigSyncBatchRequest; | ||
|
|
||
| /** | ||
| * @brief ConfigSyncPolicy 写盘策略抽象接口 | ||
| * | ||
| * 提供三种实现策略(由具体子类决定): | ||
| * - ImmediateSyncPolicy:立即写盘(用于关键配置) | ||
| * - DelayedSyncPolicy:批量延迟写盘(默认,即原 ConfigSyncRequestCache) | ||
| * - DeferredSyncPolicy:仅在关闭时写盘(节能模式) | ||
| */ | ||
| class ConfigSyncPolicy : public QObject | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| explicit ConfigSyncPolicy(QObject *parent = nullptr) : QObject(parent) {} | ||
| virtual ~ConfigSyncPolicy() override = default; | ||
|
|
||
| /// 调度一个写盘请求(非立即执行,具体时机由子类决定) | ||
| virtual void schedule(const ConfigCacheKey &key) = 0; | ||
|
|
||
| /// 立即将所有待写盘请求刷入磁盘(阻塞,服务关闭前调用) | ||
| virtual void flush() = 0; | ||
|
|
||
| /// 清空所有待写盘请求(不写盘,仅清队列) | ||
| virtual void clear() = 0; | ||
|
|
||
| Q_SIGNALS: | ||
| void syncConfigRequest(const ConfigSyncBatchRequest &request); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): addSearchPath unconditionally prefixes with m_localPrefix, which can double-prefix or break absolute paths
Here
pathis always prefixed withm_localPrefix, but call sites already pass absolute paths (e.g."/usr/share/dsg/configs") andlinglongPathis validated viaQDir(m_localPrefix + linglongPath).exists()before being passed in. As a result, you can end up storingm_localPrefix + m_localPrefix + linglongPath, and absolute paths in general get incorrectly prefixed. Consider checking whetherpathis relative and only then prependingm_localPrefix(e.g. usingQDir::isRelativePath(path)).