Skip to content

feat: enumerate recursive DConfig meta and cache subpaths - #605

Closed
18202781743 wants to merge 2 commits into
linuxdeepin:agent/developer/cb163ff66d48from
18202781743:recursive-config-subpaths
Closed

18202781743 wants to merge 2 commits into
linuxdeepin:agent/developer/cb163ff66d48from
18202781743:recursive-config-subpaths

Conversation

@18202781743

@18202781743 18202781743 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

补充 #602。将 DConfigCache::subpathList() 改名为 subpaths(),并与 DConfigMeta::subpaths() 共用递归遍历。缓存按当前配置文件名匹配,override 按 *.json 匹配。两者都返回排序去重的相对子路径。

新增回归用例覆盖深层目录、跨目录去重、全局及用户缓存,以及其他配置的缓存文件。Qt 6 本地集成分支的 26 个 DConfigFile 测试全部通过。

Summary by Sourcery

Support recursive, deduplicated subpath discovery for configuration metadata and matching cache files.

New Features:

  • Add recursive subpath enumeration for configuration metadata overrides and caches, returning sorted, unique relative paths.
  • Rename the cache subpath API from subpathList() to subpaths().

Enhancements:

  • Unify metadata and cache subpath traversal while filtering metadata by JSON overrides and caches by the active configuration file.

Documentation:

  • Update DConfigMeta::subpaths() documentation to describe recursive traversal and sorted unique results.

Tests:

  • Add regression coverage for nested overrides, duplicate paths across roots, global and user caches, and unrelated cache files.

…pport

添加 subpaths() 虚函数支持 dconfig override subpath 获取

1. 在 DConfigMeta 虚函数表末尾新增 subpaths() 虚函数,保证 ABI 兼容
2. 在 DConfigCache 虚函数表末尾新增 subpaths() 虚函数(原 subpathList 重命名),保证 ABI 兼容
3. DConfigCacheImpl 实现 subpaths(),扫描 cache 目录获取一层子 subpath
4. DConfigMeta 实现 subpaths(),扫描 allOverrideDirs 获取一层子 subpath
5. 更新 SPDX 版权年份至 2026

PMS: https://pms.uniontech.com/task-view-398893.html
Log: 添加 subpaths() 虚函数,支持获取 dconfig override 的 subpath 列表
Influence: dtkcore DConfigMeta/DConfigCache 新增 subpaths() 接口
1. Rename DConfigCache::subpathList to subpaths in the public API
2. Add a shared collectSubpaths template helper that walks directory
trees recursively and returns sorted unique relative paths prefixed
with "/"
3. Change DConfigMeta::subpaths to scan all override dirs
recursively instead of only one level, so nested override directories
containing .json files are enumerated
4. Change DConfigCache implementation to use the helper and only include
nested dirs containing the matching config file (configKey.fileName
+ FILE_SUFFIX)
5. Add unit tests covering nested overrides, duplicates, non-matching
files, and cache subpaths for both global and user caches

Influence:
1. Verify subpaths() returns nested override directories
containing .json files
2. Verify results are sorted, deduplicated, and prefixed with "/"
3. Verify directories with non-matching files (e.g. .txt) are excluded
4. Verify cache subpaths only include dirs containing the exact config
file
5. Verify behavior for both global and user caches with custom prefixes
6. Verify empty or non-existent roots return an empty list
7. Confirm all callers of the renamed subpathList API still compile

refactor: 重命名 subpathList 并支持嵌套子路径

1. 将公共 API DConfigCache::subpathList 重命名为 subpaths
2. 新增共享模板辅助函数 collectSubpaths,递归遍历目录树并返回以 "/" 为前
缀、排序去重后的相对路径
3. 修改 DConfigMeta::subpaths 以递归扫描所有覆盖目录,不再仅扫描一层,从
而枚举包含 .json 文件的嵌套覆盖目录
4. 修改 DConfigCache 实现以使用该辅助函数,仅包含含匹配配置文件
(configKey.fileName + FILE_SUFFIX)的嵌套目录
5. 新增单元测试,覆盖嵌套覆盖、重复项、不匹配文件以及全局和用户缓存的子
路径场景

Influence:
1. 验证 subpaths() 返回包含 .json 文件的嵌套覆盖目录
2. 验证结果已排序、去重并以 "/" 为前缀
3. 验证包含不匹配文件(如 .txt)的目录被排除
4. 验证缓存子路径仅包含含精确配置文件的目录
5. 验证全局和用户缓存在自定义前缀下的行为
6. 验证空或不存在的根目录返回空列表
7. 确认所有调用重命名后 subpathList API 的地方仍能编译

Log: Renamed subpathList to subpaths and added support for enumerating
 nested DConfig meta and cache subpaths
PMS: TASK-398893
@18202781743
18202781743 requested review from BLumia and mhduiy November 25, 2026 08:55
@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 25, 2026

Copy link
Copy Markdown

Reviewer's Guide

API

Rename the public DConfigCache method from subpathList() to subpaths().

  • include/global/dconfigfile.h L124

Implementation

Add a shared recursive subpath collector and use it to enumerate matching cache and meta override directories, returning sorted, deduplicated relative paths.

  • src/dconfigfile.cpp L362-384, L1291-1296, L1700-1711

Tests

Cover nested override and cache subpaths, including deduplication, filtering, and both global and user caches.

  • tests/ut_dconfigfile.cpp L332-364

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 3 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="124" />
<code_context>
     virtual void setCachePathPrefix(const QString &prefix) = 0;

-    virtual QStringList subpathList(const QString &localPrefix = QString()) const;
+    virtual QStringList subpaths(const QString &localPrefix = QString()) const;
 };

</code_context>
<issue_to_address>
**Existing consumers break after upgrade**

When a downstream project calls or overrides `subpathList()`, or an application built against the previous library calls its exported symbol after the library is upgraded, removing the public virtual and its exported symbol makes source callers and overrides fail to compile and causes old binaries to fail symbol resolution; existing subclass overrides also no longer provide results through `subpaths()`, which falls back to an empty list.

Retain `subpathList()` as a compatibility virtual and exported symbol, and make `subpaths()` preserve results from existing overrides.
</issue_to_address>

### Comment 2
<location path="src/dconfigfile.cpp" line_range="371" />
<code_context>
+        if (dirPath.isEmpty())
+            continue;
+        const QDir root(dirPath);
+        QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+        while (subdirs.hasNext()) {
+            const QDir subdir(subdirs.next());
</code_context>
<issue_to_address>
**Linked subpaths are omitted**

When a nested override or cache directory with matching files is reachable only through a directory symlink, `QDirIterator` does not follow symlinked directories without `FollowSymlinks`, so `collectSubpaths` never visits the matching files and callers receive incomplete results.

Pass `QDirIterator::FollowSymlinks` when traversing the directories.
</issue_to_address>

### Comment 3
<location path="src/dconfigfile.cpp" line_range="371" />
<code_context>
+        if (dirPath.isEmpty())
+            continue;
+        const QDir root(dirPath);
+        QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+        while (subdirs.hasNext()) {
+            const QDir subdir(subdirs.next());
</code_context>
<issue_to_address>
**Hidden subpaths are omitted**

When a valid subpath directory starts with `.` and contains a matching file, `QDirIterator` receives no `QDir::Hidden` filter, so it skips hidden subdirectories even when they contain matching override or cache files; callers do not see those valid subpaths in the returned list.

Include hidden directories in the recursive iterator (and hidden matching files in the meta file listing if those are intended to count).
</issue_to_address>

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

virtual void setCachePathPrefix(const QString &prefix) = 0;

virtual QStringList subpathList(const QString &localPrefix = QString()) const;
virtual QStringList subpaths(const QString &localPrefix = QString()) const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Existing consumers break after upgrade

When a downstream project calls or overrides subpathList(), or an application built against the previous library calls its exported symbol after the library is upgraded, removing the public virtual and its exported symbol makes source callers and overrides fail to compile and causes old binaries to fail symbol resolution; existing subclass overrides also no longer provide results through subpaths(), which falls back to an empty list.

Retain subpathList() as a compatibility virtual and exported symbol, and make subpaths() preserve results from existing overrides.

Prompt for AI agents
In `include/global/dconfigfile.h` at line 124:

**Existing consumers break after upgrade**

When a downstream project calls or overrides `subpathList()`, or an application built against the previous library calls its exported symbol after the library is upgraded, removing the public virtual and its exported symbol makes source callers and overrides fail to compile and causes old binaries to fail symbol resolution; existing subclass overrides also no longer provide results through `subpaths()`, which falls back to an empty list.

Retain `subpathList()` as a compatibility virtual and exported symbol, and make `subpaths()` preserve results from existing overrides.

Comment thread src/dconfigfile.cpp
if (dirPath.isEmpty())
continue;
const QDir root(dirPath);
QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Linked subpaths are omitted

When a nested override or cache directory with matching files is reachable only through a directory symlink, QDirIterator does not follow symlinked directories without FollowSymlinks, so collectSubpaths never visits the matching files and callers receive incomplete results.

Pass QDirIterator::FollowSymlinks when traversing the directories.

Prompt for AI agents
In `src/dconfigfile.cpp` at line 371:

**Linked subpaths are omitted**

When a nested override or cache directory with matching files is reachable only through a directory symlink, `QDirIterator` does not follow symlinked directories without `FollowSymlinks`, so `collectSubpaths` never visits the matching files and callers receive incomplete results.

Pass `QDirIterator::FollowSymlinks` when traversing the directories.

Comment thread src/dconfigfile.cpp
if (dirPath.isEmpty())
continue;
const QDir root(dirPath);
QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Hidden subpaths are omitted

When a valid subpath directory starts with . and contains a matching file, QDirIterator receives no QDir::Hidden filter, so it skips hidden subdirectories even when they contain matching override or cache files; callers do not see those valid subpaths in the returned list.

Include hidden directories in the recursive iterator (and hidden matching files in the meta file listing if those are intended to count).

Prompt for AI agents
In `src/dconfigfile.cpp` at line 371:

**Hidden subpaths are omitted**

When a valid subpath directory starts with `.` and contains a matching file, `QDirIterator` receives no `QDir::Hidden` filter, so it skips hidden subdirectories even when they contain matching override or cache files; callers do not see those valid subpaths in the returned list.

Include hidden directories in the recursive iterator (and hidden matching files in the meta file listing if those are intended to count).

@18202781743
18202781743 marked this pull request as draft November 25, 2026 09:46
@18202781743
18202781743 force-pushed the agent/developer/cb163ff66d48 branch from 39f323e to e0085d7 Compare November 26, 2026 09:47
@18202781743

Copy link
Copy Markdown
Contributor Author

#602

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