Skip to content

feat: add subpaths and cacheSubpaths for dconfig override subpath support - #602

Open
18202781743 wants to merge 1 commit into
masterfrom
agent/developer/cb163ff66d48
Open

18202781743 wants to merge 1 commit into
masterfrom
agent/developer/cb163ff66d48

Conversation

@18202781743

@18202781743 18202781743 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

概述

为 DConfigFile 添加 subpaths 和 cacheSubpaths 接口,支持获取 dconfig override subpath 列表。

关联 issue: DDE-647

变更内容

  • DConfigFile::subpaths():非虚实例方法,聚合 meta 的 override 目录 + global cache 目录扫描子目录,结果去重
  • DConfigFile::cacheSubpaths():非虚静态方法,通过 static_cast<const DConfigCacheImpl*> 调用 getCacheDir() 扫描子目录
  • DConfigMeta / DConfigCache 基类不新增虚函数,vtable 布局不变,保证 ABI 兼容

变更文件

 include/global/dconfigfile.h |  5 ++-
 src/dconfigfile.cpp          | 95 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 98 insertions(+), 2 deletions(-)

审核

代码审核通过(98/100),4 个维度全部达标。

Summary by Sourcery

Expose available descendant configuration subpaths across local files, overrides, caches, and D-Bus backends.

New Features:

  • Add subpath discovery to DConfig and expose it as a property and D-Bus interface with change notifications.
  • Discover nested override and cache subpaths while filtering by matching configuration files and returning unique sorted paths.

Enhancements:

  • Preserve ABI compatibility by adding default non-pure virtual subpath APIs without changing existing base-class vtable requirements.

Tests:

  • Add coverage for nested, filtered, deduplicated, and relative override and cache subpaths across file-backed and D-Bus-backed configurations.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose subpath discovery through DConfig properties, methods, and signals, add the DConfigMeta and DConfigCache interfaces, and publish the matching D-Bus property and signal.

  • include/global/dconfig.h L36, L75-79
  • include/global/dconfigfile.h L1, L101, L124-125
  • src/dbus/org.desktopspec.ConfigManager.Manager.xml L4, L12, L52

Implementation

Scan override and cache directories for safe, matching descendant paths, and provide the base-class defaults for cache discovery.

  • src/dconfigfile.cpp L362-406, L1315-1322, L1721-1734 (+3 small edits)

Aggregate metadata and cache subpaths in the file backend, forward the D-Bus property and change signal, and implement DConfig::subpaths().

  • src/dconfig.cpp L238-251, L421-425, L949-972 (+1 small edits)

Tests

Cover nested override and cache subpath discovery, relative paths, matching-file filtering, and exclusion of unrelated resources.

  • tests/ut_dconfig.cpp L65-78
  • tests/ut_dconfigfile.cpp L9, L333-394

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 9 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="include/global/dconfigfile.h" line_range="101" />
<code_context>
     virtual QStringList allOverrideDirs(const bool useAppId, const QString &prefix = QString()) const = 0;

     virtual QVariant value(const QString &key) const = 0;
+    virtual QStringList subpaths(const QString &localPrefix = QString()) const;
     static QStringList genericMetaDirs(const QString &localPrefix = QString());
     static QStringList applicationMetaDirs(const QString &localPrefix, const QString &appId);
</code_context>
<issue_to_address>
**Existing plugins crash on subpaths calls**

When a consumer uses a subclass of either exported base class that was compiled against the old headers, `subpaths()` is dispatched through a vtable slot the subclass does not define, so the call can crash or corrupt the caller.

Expose these methods through an ABI-safe mechanism rather than adding virtual slots to the exported base classes.

Also at `include/global/dconfigfile.h:125-126`.
</issue_to_address>

### Comment 2
<location path="src/dconfigfile.cpp" line_range="374" />
<code_context>
+        const QDir root(base.filePath(subpath.mid(1)));
+        if (!root.exists() || !isPathInDirectory(root.canonicalPath(), base.canonicalPath()))
+            continue;
+        QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+        while (subdirs.hasNext()) {
+            const QDir subdir(subdirs.next());
</code_context>
<issue_to_address>
**External directories appear as subpaths**

When a descendant directory under an override or cache root is a symlink to an external directory containing a matching file, `collectSubpaths()` checks containment only for the scan root, then `matchesDirectory()` accepts the symlinked descendant and reports the external directory as an in-root subpath.

Check each discovered directory’s canonical path is within the scan root before passing it to `matchesDirectory()`.
</issue_to_address>

### Comment 3
<location path="src/dconfigfile.cpp" line_range="391" />
<code_context>
+static QStringList overrideSubpaths(const DConfigMeta &meta, const QString &localPrefix, const QString &subpath)
+{
+    bool useAppId = false;
+    if (meta.metaPath(localPrefix, &useAppId).isEmpty())
+        return {};
+
</code_context>
<issue_to_address>
**Invalid identifiers escape scan directories**

When a caller constructs a DConfigFile or cache using attacker-controlled app ID or filename values and invokes either subpaths API, `DConfigMeta::subpaths` and `DConfigCache::subpaths` use the stored app ID and filename to construct scan paths without applying the identifier checks performed by `DConfigMetaImpl::load`. When callers pass attacker-controlled identifiers containing path separators, the new APIs scan outside the intended configuration directories and return matching subpath names.

Validate the app ID and filename before either subpaths implementation constructs or scans paths, and return an empty list for invalid identifiers.

Also at `src/dconfigfile.cpp:1314`.
</issue_to_address>

### Comment 4
<location path="src/dconfig.cpp" line_range="241" />
<code_context>
+    QStringList subpaths() const
+    {
+        const auto prefix = localPrefix();
+        auto paths = configFile->meta()->subpaths(prefix);
+        for (auto cache : {configFile->globalCache(), configCache.data()}) {
+            for (const auto &path : cache->subpaths(prefix)) {
</code_context>
<issue_to_address>
**Generic fallback paths are omitted**

When generic fallback supplies a value or cached value for a descendant path absent from the app-specific sources, `FileBackend::subpaths()` scans only the app-specific configuration and caches, so callers do not see paths that `FileBackend::value()` can serve from the generic configuration or cache.

Include the generic configuration and generic cache when collecting paths.

Also at `src/dconfig.cpp:242-248`.
</issue_to_address>

### Comment 5
<location path="include/global/dconfigfile.h" line_range="101" />
<code_context>
     virtual QStringList allOverrideDirs(const bool useAppId, const QString &prefix = QString()) const = 0;

     virtual QVariant value(const QString &key) const = 0;
+    virtual QStringList subpaths(const QString &localPrefix = QString()) const;
     static QStringList genericMetaDirs(const QString &localPrefix = QString());
     static QStringList applicationMetaDirs(const QString &localPrefix, const QString &appId);
</code_context>
<issue_to_address>
**Promised file-level APIs do not compile**

When a caller uses the described `DConfigFile::subpaths()` or `DConfigFile::cacheSubpaths()` APIs, `DConfigFile` declares neither method, so callers cannot compile against the promised file-level APIs.

Declare and implement the promised file-level subpaths APIs, including the cache-specific API.

Also at `include/global/dconfigfile.h:126`.
</issue_to_address>

### Comment 6
<location path="src/dbus/org.desktopspec.ConfigManager.Manager.xml" line_range="12" />
<code_context>
 <interface name='org.desktopspec.ConfigManager.Manager'>
     <property access="read" type="s" name="version"/>
     <property access="read" type="as" name="keyList"/>
+    <property access="read" type="as" name="subpaths"/>
     <method name='value'>
       <arg type='s' name='key' direction='in'/>
</code_context>
<issue_to_address>
**Older managers hide subpaths**

When a new client is deployed while its D-Bus ConfigManager is still running an older interface, an older ConfigManager does not expose the new property, so the D-Bus proxy cannot retrieve the list and `DBusBackend::subpaths()` returns no subpaths; this backend does not fall back to file discovery.

Negotiate property support and provide a fallback or compatible empty-result behavior during mixed-version deployment.

Also at `src/dconfig.cpp:423`.
</issue_to_address>

### Comment 7
<location path="src/dconfigfile.cpp" line_range="1318" />
<code_context>
+    {
+        const QString filename = configKey.fileName + FILE_SUFFIX;
+        return collectSubpaths({getCacheDir(localPrefix)}, configKey.subpath, [&filename](const QDir &dir) {
+            return QFileInfo(dir.filePath(filename)).isFile();
+        });
+    }
</code_context>
<issue_to_address>
**Failed saves appear as available paths**

When a cache write fails after the cache file has been created or truncated, `DConfigCacheImpl::save()` clears `cacheChanged` before opening and writing the cache file. If a write fails after creating or truncating the file, `subpaths()` still accepts that partial file via `QFileInfo::isFile()`, and a later save has no dirty flag to retry; callers see a path whose cache data is incomplete.

Write cache files atomically and retain `cacheChanged` until the write succeeds; only advertise cache files that were successfully committed.
</issue_to_address>

### Comment 8
<location path="src/dconfigfile.cpp" line_range="1314-1320" />
<code_context>
         cachePrefix = prefix;
     }

+    QStringList subpaths(const QString &localPrefix = QString()) const override
+    {
+        const QString filename = configKey.fileName + FILE_SUFFIX;
+        return collectSubpaths({getCacheDir(localPrefix)}, configKey.subpath, [&filename](const QDir &dir) {
+            return QFileInfo(dir.filePath(filename)).isFile();
+        });
+    }
+
     DConfigKey configKey;
</code_context>
<issue_to_address>
**Concurrent prefix changes race with scans**

When one caller changes a cache's path prefix while another calls `subpaths()` on that cache, `DConfigCacheImpl::subpaths()` calls `getCacheDir()`, which reads `cachePrefix`, while `setCachePathPrefix()` can assign to that same `QString` without synchronization. Concurrent calls therefore have a data race and can produce an invalid cache directory or an incorrect subpath list.

Synchronize prefix updates and reads, or take a synchronized snapshot of the prefix before deriving the cache directory.
</issue_to_address>

### Comment 9
<location path="src/dconfigfile.cpp" line_range="385" />
<code_context>
+        }
+    }
+
+    return result;
+}
+
</code_context>
<issue_to_address>
**Direct subpaths results are unsorted**

When a direct metadata or cache query finds multiple matching descendant paths, `collectSubpaths()` returns paths in filesystem traversal order, so direct `DConfigMeta::subpaths()` and `DConfigCache::subpaths()` callers receive results that can vary instead of the documented sorted order.

Sort the results returned by `collectSubpaths()`.

Also at `src/dconfigfile.cpp:984-987`, `src/dconfigfile.cpp:1320`, `src/dconfigfile.cpp:1731`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread include/global/dconfigfile.h Resolved
Comment thread src/dconfigfile.cpp Resolved
Comment thread src/dconfigfile.cpp Resolved
Comment thread src/dconfig.cpp Resolved
Comment thread include/global/dconfigfile.h Resolved
Comment thread src/dconfigfile.cpp Resolved
Comment thread src/dconfigfile.cpp Resolved
Comment thread src/dconfigfile.cpp Resolved
1. Add subpaths() method and subpathsChanged signal to DConfig class
2. Introduce subpaths property in DConfig for QML/property access
3. Add virtual subpaths methods to DConfigMeta and DConfigCache base
classes
4. Implement path scanning logic in dconfigfile.cpp to collect nested
override and cache subpaths with security check (isPathInDirectory)
5. Wire D-Bus Manager XML to expose subpaths property and
subpathsChanged signal
6. Connect D-Bus subpathsChanged signal to DConfig signal in backend
7. Support filtering descendants relative to current subpath in both
file and cache backends
8. Add unit tests for meta overrides, cache subpaths, nested paths, and
cross-resource exclusion
9. Update copyright year in dconfigfile.h

Influence:
1. Test that DConfig::subpaths returns empty for configurations without
descendants
2. Verify subpaths() lists nested override directories relative to
current subpath with leading slash
3. Verify subpathsChanged signal fires when D-Bus backend reports new
list
4. Test QML property access via "subpaths" property
5. Test cache subpaths containing only matching config filename
6. Verify that resources not matching the config filename are excluded
7. Test cross-directory security: ensure canonical paths outside root
are rejected
8. Test subpaths for global and user caches separately
9. Verify behavior for missing subpaths and inactive/disabled backends

feat: 为 DConfig 添加 subpaths 接口

1. 在 DConfig 类中新增 subpaths() 方法与 subpathsChanged 信号
2. 为 DConfig 引入 subpaths 属性以支持 QML/属性访问
3. 在 DConfigMeta 与 DConfigCache 基类中新增虚函数 subpaths
4. 在 dconfigfile.cpp 中实现路径扫描逻辑,收集嵌套的 override 与缓存子路
径,并加入安全校验(isPathInDirectory)
5. 更新 D-Bus Manager XML,暴露 subpaths 属性与 subpathsChanged 信号
6. 在 backend 中将 D-Bus 的 subpathsChanged 信号连接到 DConfig 信号
7. 文件与缓存后端均支持相对当前子路径筛选后代路径
8. 新增单元测试,覆盖 meta override、缓存子路径、嵌套路径及跨资源排除
9. 更新 dconfigfile.h 的版权年份

Influence:
1. 测试无后代配置时 DConfig::subpaths 返回空列表
2. 验证 subpaths() 以斜杠开头列出相对于当前子路径的嵌套 override 目录
3. 验证 D-Bus 后端上报新列表时 subpathsChanged 信号被触发
4. 测试通过 "subpaths" 属性进行 QML 属性访问
5. 测试缓存子路径仅包含匹配配置文件名的条目
6. 验证不匹配配置文件名的资源被排除
7. 测试跨目录安全:确保根目录之外的规范路径被拒绝
8. 分别测试全局缓存与用户缓存的 subpaths
9. 验证缺失子路径及后端禁用时的行为

Log: Added subpaths API and subpathsChanged signal to DConfig for
 discovering nested configuration paths
PMS: TASK-398893
@18202781743
18202781743 force-pushed the agent/developer/cb163ff66d48 branch from e0085d7 to ac4edce Compare November 27, 2026 09:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants