Skip to content

fix(dfm-io): prevent readlink blocking on GVFS paths in resolveSymlink - #409

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/meagle-20260526from
liyigang1:agent/pms-bug-bot/ce1baead72db
Oct 15, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/meagle-20260526from
liyigang1:agent/pms-bug-bot/ce1baead72db

Conversation

@liyigang1

@liyigang1 liyigang1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

fix(dfm-io): prevent readlink blocking on GVFS paths in resolveSymlink

Add DFMUtils::isGvfsFile() guard in DLocalHelper::resolveSymlink() to
stop symlink resolution when the target is a GVFS (remote) path,
avoiding synchronous readlink() calls that block on network I/O.
Also extend isGvfsFile() regex to match /media/ smbmounts paths in
addition to /run/media/.

Summary by Sourcery

Avoid blocking symlink resolution for GVFS paths and broaden detection of remote SMB mounts.

Bug Fixes:

  • Prevent symlink resolution from blocking on network I/O when paths point to GVFS remote locations.
  • Recognize both /run/media and /media SMB mount paths as GVFS files.

Add DFMUtils::isGvfsFile() guard in DLocalHelper::resolveSymlink() to
stop symlink resolution when the target is a GVFS (remote) path,
avoiding synchronous readlink() calls that block on network I/O.
Also extend isGvfsFile() regex to match /media/ smbmounts paths in
addition to /run/media/.
@sourcery-ai

sourcery-ai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Prevents resolveSymlink from issuing further synchronous readlink/stat operations after reaching a GVFS-backed target, while expanding GVFS detection to recognize SMB mounts under both /run/media and /media.

Flow diagram for GVFS-safe symlink resolution

flowchart TD
    A[resolveSymlink] --> B[symlinkTarget]
    B --> C{isGvfsFile}
    C -->|yes| D[Return remote target]
    C -->|no| E{nextTarget exists}
    E -->|no| F[Return target]
    E -->|yes| G{isGvfsFile nextTarget}
    G -->|yes| D
    G -->|no| H[Continue symlink resolution]
    H --> I{Cycle detected}
    I -->|yes| J[Return empty]
    I -->|no| B
Loading

File-Level Changes

Change Details Files
Guard symlink resolution from traversing into GVFS targets that can trigger blocking network I/O.
  • Check the initial symlink target before entering the resolution loop.
  • Check each subsequent symlink target and return it without further resolution when it is remote.
  • Preserve cycle detection and normal local symlink traversal behavior.
src/dfm-io/dfm-io/utils/dlocalhelper.cpp
Broaden GVFS path detection to include both /run/media and /media SMB mount paths.
  • Update the regular expression to make the run/ component optional for media SMB mounts.
  • Continue matching existing user GVFS and root .gvfs paths.
src/dfm-io/dfm-io/dfmio_utils.cpp

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

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

## Individual Comments

### Comment 1
<location path="src/dfm-io/dfm-io/utils/dlocalhelper.cpp" line_range="1287-1288" />
<code_context>
 {
     QSet<QString> visited;
     QString target = DLocalHelper::symlinkTarget(url);
+    if (DFMUtils::isGvfsFile(QUrl::fromLocalFile(target)))
+        return target;   // Remote target: stop resolving, further readlink/stat would block on network I/O
     while (!target.isEmpty()) {
         if (visited.contains(target))
</code_context>
<issue_to_address>
**Remote directory links appear as files**

When a symlink resolves to a directory under a GVFS path, `createSortFileInfo` skips `stat()` for the returned target and leaves `isDir` false, so `insertSortFileInfoList` treats the directory symlink as a file and directory-first ordering and filters misclassify it.

Set the directory/file classification for GVFS targets before returning them from either target check.

Also at `src/dfm-io/dfm-io/utils/dlocalhelper.cpp:1297-1298`.
</issue_to_address>

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

Comment on lines +1287 to +1288
if (DFMUtils::isGvfsFile(QUrl::fromLocalFile(target)))
return target; // Remote target: stop resolving, further readlink/stat would block on network I/O

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 · Remote directory links appear as files

When a symlink resolves to a directory under a GVFS path, createSortFileInfo skips stat() for the returned target and leaves isDir false, so insertSortFileInfoList treats the directory symlink as a file and directory-first ordering and filters misclassify it.

Set the directory/file classification for GVFS targets before returning them from either target check.

Also at src/dfm-io/dfm-io/utils/dlocalhelper.cpp:1297-1298.

Prompt for AI agents
In `src/dfm-io/dfm-io/utils/dlocalhelper.cpp` at lines 1287-1288:

**Remote directory links appear as files**

When a symlink resolves to a directory under a GVFS path, `createSortFileInfo` skips `stat()` for the returned target and leaves `isDir` false, so `insertSortFileInfoList` treats the directory symlink as a file and directory-first ordering and filters misclassify it.

Set the directory/file classification for GVFS targets before returning them from either target check.

Also at `src/dfm-io/dfm-io/utils/dlocalhelper.cpp:1297-1298`.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 99 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 99 分,大于 70 分通过阈值,代码质量符合要求。本次提交修复了 resolveSymlink 在 GVFS 路径上的阻塞问题,逻辑清晰,注释完整,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码语法正确,逻辑清晰。正则表达式修改正确,(?:run/)? 非捕获组语法有效。边界条件处理完善:空 target 安全通过(正则不匹配空字符串,while 循环条件捕获),环检测逻辑不受影响。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/dfm-io/dfm-io/dfmio_utils.cpp:353 - static const QString *gvfsMatch = new QString{...} 堆分配未释放,建议使用栈分配静态变量

建议: 建议将 static const QString *gvfsMatch = new QString{...} 改为 static const QString gvfsMatch{...}(栈分配静态变量),避免堆内存泄漏。同时建议将 QRegularExpression 也设为 static,避免每次调用重新编译正则。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 本次修改净性能提升显著:通过在 resolveSymlink 中添加 GVFS 守卫,避免了在远程路径上调用阻塞式 readlink(),isGvfsFile() 的正则匹配开销远小于网络 I/O 阻塞。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 存在0个安全漏洞。本次修改未引入安全风险,无用户输入处理变更,无硬编码密钥,无注入风险。


💡 改进建议代码示例

// 建议优化 isGvfsFile() 中的静态变量声明
bool DFMUtils::isGvfsFile(const QUrl &url)
{
    if (!url.isValid())
        return false;

    const QString &path = url.toLocalFile();
    // 使用栈分配的静态变量,避免堆内存泄漏
    static const QString gvfsMatch = QStringLiteral("(^/run/user/\\d+/gvfs/|^/root/.gvfs/|^/(?:run/)?media/[\\s\\S]*/smbmounts)");
    // 将 QRegularExpression 也设为 static,避免每次调用重新编译
    static const QRegularExpression re(gvfsMatch);
    QRegularExpressionMatch match = re.match(path);
    return match.hasMatch();
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: liyigang1, max-lvs

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

@liyigang1

Copy link
Copy Markdown
Contributor Author

/forcemerge

1 similar comment
@liyigang1

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 7d87834 into linuxdeepin:develop/meagle-20260526 Oct 15, 2026
17 checks passed
@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

This pr force merged! (status: unknown)

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