Skip to content

fix: handle missing subdirectories in override file loading - #604

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Nov 25, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
  1. Replace direct cd() call with a loop that walks up the path hierarchy
    until an existing directory is found
  2. Use QDir::cleanPath to normalize the subpath before processing
  3. Truncate the path at the last slash when cd fails, allowing fallback
    to parent directories
  4. Add test cases covering missing subpaths, partial existence, and
    inheritance behavior

Previously, if the configured subpath did not exist on disk, cd() would
fail silently and the override file search would not traverse parent
directories. This caused override files at parent levels to be missed
when a deeper subpath was configured but not yet created.

Influence:

  1. Test override file loading with a completely non-existent subpath,
    verify parent override is still applied
  2. Test with partially existing subpath hierarchies (e.g. parent exists
    but child does not)
  3. Verify that when an existing leaf directory has no override files,
    parent overrides are inherited
  4. Test that override files at the exact leaf level take precedence over
    parent overrides
  5. Verify behavior with deeply nested subpaths containing multiple
    missing levels
  6. Confirm normal operation is unchanged when all subdirectories exist

fix: 修复覆盖文件加载时子目录不存在的问题

  1. 将直接调用 cd() 替换为循环向上遍历路径层级直到找到存在的目录
  2. 使用 QDir::cleanPath 在处理前规范化子路径
  3. 当 cd 失败时在最后一个斜杠处截断路径,允许回退到父目录
  4. 添加测试用例覆盖子路径缺失、部分存在及继承行为

此前,当配置的子路径在磁盘上不存在时,cd() 会静默失败,覆盖文件搜索不会
遍历父目录。这导致当配置了更深的子路径但尚未创建时,父级的覆盖文件会被
遗漏。

Influence:

  1. 测试子路径完全不存在时的覆盖文件加载,验证父级覆盖仍被应用
  2. 测试子路径层级部分存在的情况(如父目录存在但子目录不存在)
  3. 验证当存在的叶子目录没有覆盖文件时,父级覆盖会被继承
  4. 测试叶子层级的覆盖文件优先于父级覆盖
  5. 验证包含多个缺失层级的深层嵌套子路径的行为
  6. 确认所有子目录都存在时正常操作不受影响

PMS: TASK-399295

Summary by Sourcery

Fix override file loading so missing subdirectories fall back to the deepest existing directory and continue inheriting parent overrides.

Bug Fixes:

  • Ensure override files are discovered through existing parent directories when configured subpaths are missing or only partially present.

Enhancements:

  • Normalize configured subpaths and preserve leaf-to-parent override precedence and inheritance behavior.

Tests:

  • Add coverage for missing, partially existing, deeply nested, and existing override subpaths, including inheritance and leaf-level precedence.

@18202781743
18202781743 requested review from BLumia and mhduiy November 25, 2026 07:21
@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Normalize the configured subpath and fall back to the deepest existing directory so override loading can continue through parent directories when parts of the path are missing.

  • src/dconfigfile.cpp L987-990

Tests

Add coverage for missing and partially existing subpaths, parent override inheritance, and leaf-level override precedence.

  • 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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

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 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 1 issue

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

## Individual Comments

### Comment 1
<location path="src/dconfigfile.cpp" line_range="990" />
<code_context>
+            // Start at the deepest existing subdirectory before walking back up.
+            QString subpath = QDir::cleanPath(configKey.subpath);
+            while (subpath.size() > 1 && !target_dir.cd(subpath.mid(1)))
+                subpath.truncate(subpath.lastIndexOf(QLatin1Char('/')));

             do {
</code_context>
<issue_to_address>
**Partial paths follow symlinks**

When a configured subpath has an existing symlink component pointing outside the override directory, followed by a missing component, `target_dir.cd()` follows an existing symlink component, so fallback can scan override files outside the configured override directory and apply them to the config.

Before scanning a fallback directory, verify its resolved canonical path remains inside the canonical override base, or reject symlink components.
</issue_to_address>

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

Comment thread src/dconfigfile.cpp Resolved
1. Replace direct cd() call with cleanPath and a walk-back loop that
attempts to enter the deepest existing subdirectory
2. Truncate the subpath at the last slash when cd() fails until a valid
directory is found or only root remains
3. This prevents silent failure to load override files when the
configured subpath or intermediate directories do not exist on disk
4. Add unit tests covering missing subpaths, deeply nested non-existent
paths, existing leaf directories without overrides, and leaf override
precedence

Influence:
1. Test override loading when the configured subpath does not exist
at all
2. Verify that parent directory overrides are correctly inherited for
missing nested subpaths
3. Test behavior when the leaf directory exists but contains no override
files
4. Verify that a leaf-level override takes precedence over parent
overrides
5. Confirm no regression in existing fileOverride and
fileOverrideNoExistItem tests
6. Test with paths containing redundant separators or dot segments via
QDir::cleanPath

fix: 修复配置覆盖搜索中缺失子路径的处理

1. 用 cleanPath 和回退循环替代直接 cd() 调用,尝试进入最深的已存在子目录
2. 当 cd() 失败时截断子路径到最后一个斜杠,直到找到有效目录或仅剩根目录
3. 避免配置的子路径或中间目录在磁盘上不存在时静默无法加载覆盖文件
4. 新增单元测试覆盖缺失子路径、深层不存在的路径、存在但无覆盖文件的叶子
目录以及叶子覆盖优先级

Influence:
1. 测试配置子路径完全不存在时的覆盖加载
2. 验证缺失嵌套子路径时能正确继承父目录覆盖
3. 测试叶子目录存在但不包含覆盖文件时的行为
4. 验证叶子级覆盖优先于父级覆盖
5. 确认现有 fileOverride 和 fileOverrideNoExistItem 测试无回归
6. 通过 QDir::cleanPath 测试包含冗余分隔符或点段的路径

Log: Fixed config override loading when subpath directories are missing
PMS: TASK-399295
@18202781743

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 0153ea2 into linuxdeepin:master Nov 25, 2026
20 of 23 checks passed
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.

3 participants