Skip to content

fix: improve symlink handling in filename search#303

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master
Jun 17, 2026
Merged

fix: improve symlink handling in filename search#303
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Added test cases for symlink directory handling in real-time search
  2. Modified real-time strategy to skip recursing into symlink
    directories while still matching their names
  3. Handles three key scenarios: symlink name matching, preventing
    recursion into symlinks, and avoiding cycles from circular symlinks
  4. Tests verify correct behavior for each scenario

Log: Improved symlink directory handling in file search

Influence:

  1. Test searching for files in directories containing symlinks
  2. Verify symlink directory names are matched correctly
  3. Confirm search doesn't follow symlinks into other directories
  4. Check circular symlink detection and handling
  5. Test search performance with multiple symlinks

fix: 改进文件名搜索中的符号链接处理

  1. 为实时搜索中的符号链接目录处理添加测试用例
  2. 修改实时策略跳过递归进入符号链接目录,同时仍可匹配其名称
  3. 处理三种关键场景:符号链接名称匹配、防止递归进入符号链接、避免环形符
    号链接导致的循环
  4. 测试验证了每种场景的正确行为

Log: 改进文件搜索中的符号链接目录处理

Influence:

  1. 测试包含符号链接目录中的文件搜索
  2. 验证符号链接目录名称能被正确匹配
  3. 确认搜索不会跟随符号链接进入其他目录
  4. 检查环形符号链接的检测和处理
  5. 测试多符号链接情况下的搜索性能

1. Added test cases for symlink directory handling in real-time search
2. Modified real-time strategy to skip recursing into symlink
directories while still matching their names
3. Handles three key scenarios: symlink name matching, preventing
recursion into symlinks, and avoiding cycles from circular symlinks
4. Tests verify correct behavior for each scenario

Log: Improved symlink directory handling in file search

Influence:
1. Test searching for files in directories containing symlinks
2. Verify symlink directory names are matched correctly
3. Confirm search doesn't follow symlinks into other directories
4. Check circular symlink detection and handling
5. Test search performance with multiple symlinks

fix: 改进文件名搜索中的符号链接处理

1. 为实时搜索中的符号链接目录处理添加测试用例
2. 修改实时策略跳过递归进入符号链接目录,同时仍可匹配其名称
3. 处理三种关键场景:符号链接名称匹配、防止递归进入符号链接、避免环形符
号链接导致的循环
4. 测试验证了每种场景的正确行为

Log: 改进文件搜索中的符号链接目录处理

Influence:
1. 测试包含符号链接目录中的文件搜索
2. 验证符号链接目录名称能被正确匹配
3. 确认搜索不会跟随符号链接进入其他目录
4. 检查环形符号链接的检测和处理
5. 测试多符号链接情况下的搜索性能

@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.

Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码优化了符号链接目录的遍历逻辑并补充了完善的单元测试,质量极高
逻辑严密且无任何安全风险,测试覆盖了边界情况,满分通过

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修改后的条件判断 if (info.isDir() && !info.isSymLink()) 准确实现了“匹配名称但不递归”的逻辑,去除了原有 continue 导致的跳过匹配副作用。单元测试中临时目录创建、符号链接建立及断言逻辑均正确无误

  • 2.代码质量(优秀)✓

注释精准解释了修改意图。新增的三个单元测试分别覆盖了符号链接名称匹配、防递归进入、循环链接防死循环三个核心场景,命名规范且结构清晰,符合高标准的测试规范

  • 3.代码性能(高效)✓

将两层嵌套的条件判断合并为单层逻辑与运算,减少了不必要的分支跳转。测试用例使用 QTemporaryDir 确保资源自动释放,无性能损耗

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
总体风险描述:无安全风险。该修改有效阻止了通过符号链接目录进行路径遍历的风险,同时彻底消除了循环符号链接可能引发的拒绝服务攻击面

  • 建议:当前实现已足够安全,无需额外修改

■ 【改进建议代码示例】

// 示例:在现有修改基础上增加对文件系统状态突变的防御性检查
void FileNameRealTimeStrategy::search(const SearchQuery &query)
{
    // ...
    while (!directoryStack.isEmpty()) {
        const QString currentDir = directoryStack.pop();
        QDir dir(currentDir);
        
        // 防御性检查:处理遍历过程中目录被删除或权限变更的竞态情况
        if (!dir.exists()) {
            qCWarning(logDFMSearch) << "Directory vanished during traversal:" << currentDir;
            continue;
        }

        const QFileInfoList entries = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
        for (const QFileInfo &info : entries) {
            // ... 执行文件名匹配逻辑 ...

            // 符号链接目录不递归进入(防止循环),但其名称仍参与匹配
            if (info.isDir() && !info.isSymLink()) {
                directoryStack.push(info.filePath());
            }
        }
    }
}

@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit ad74c48 into linuxdeepin:master Jun 17, 2026
22 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.

2 participants