Repository navigation
feat: enumerate recursive DConfig meta and cache subpaths - #605
18202781743 wants to merge 2 commits into
Conversation
…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
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideAPIRename the public DConfigCache method from subpathList() to subpaths().
ImplementationAdd a shared recursive subpath collector and use it to enumerate matching cache and meta override directories, returning sorted, deduplicated relative paths.
TestsCover nested override and cache subpaths, including deduplication, filtering, and both global and user caches.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| virtual void setCachePathPrefix(const QString &prefix) = 0; | ||
|
|
||
| virtual QStringList subpathList(const QString &localPrefix = QString()) const; | ||
| virtual QStringList subpaths(const QString &localPrefix = QString()) const; |
There was a problem hiding this comment.
🟡 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.| if (dirPath.isEmpty()) | ||
| continue; | ||
| const QDir root(dirPath); | ||
| QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); |
There was a problem hiding this comment.
🟡 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.| if (dirPath.isEmpty()) | ||
| continue; | ||
| const QDir root(dirPath); | ||
| QDirIterator subdirs(root.absolutePath(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); |
There was a problem hiding this comment.
🟡 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).39f323e to
e0085d7
Compare
补充 #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:
Enhancements:
Documentation:
Tests: