Skip to content

fix: isSupportSeek use QTemporaryFile directly instead of close/reopen#443

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle
Jul 23, 2026
Merged

fix: isSupportSeek use QTemporaryFile directly instead of close/reopen#443
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle

Conversation

@LiHua000

@LiHua000 LiHua000 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fix permission denied error when reopening temporary file for seek detection on certain filesystems.
Log: isSupportSeek use QTemporaryFile directly

Bug:https://pms.uniontech.com/bug-view-371275.html

Summary by Sourcery

Bug Fixes:

  • Resolve permission denied errors on certain filesystems when checking if seek operations are supported by using the QTemporaryFile instance directly instead of closing and reopening it.

@sourcery-ai

sourcery-ai Bot commented Jul 23, 2026

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

Reviewer's Guide

Refactors Common::isSupportSeek to use an already-open QTemporaryFile for seek detection instead of closing and reopening it, preventing permission errors on some filesystems.

Sequence diagram for updated Common_isSupportSeek temporary file seek detection

sequenceDiagram
    participant Common
    participant QFileInfo
    participant QTemporaryFile

    Common->>QFileInfo: absoluteDir
    QFileInfo-->>Common: tempDir
    Common->>QTemporaryFile: QTemporaryFile(fileTemplate)
    Common->>QTemporaryFile: setAutoRemove(true)
    Common->>QTemporaryFile: open()
    alt tempFile opened
        Common->>QTemporaryFile: write("test\n")
        Common->>QTemporaryFile: flush()
        Common->>QTemporaryFile: seek(0)
        alt seek successful
            Common->>QTemporaryFile: close()
            Common-->>Common: return true
        else seek failed
            Common->>QTemporaryFile: close()
            Common-->>Common: return false
        end
    else open failed
        Common-->>Common: return false
    end
Loading

File-Level Changes

Change Details Files
Use QTemporaryFile directly for seek support detection instead of reopening the temporary file via QFile.
  • Remove the logic that closes the QTemporaryFile and reopens it through QFile for read-only access.
  • Perform write, flush, and seek operations directly on the QTemporaryFile instance.
  • Simplify control flow by returning success immediately when tempFile.seek(0) succeeds and ensuring the temporary file is closed in all paths.
  • Retain use of the original directory-based temporary filename template while eliminating redundant QFile handling.
3rdparty/interface/common.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 left some high level feedback:

  • The logic now calls tempFile.close() both inside the seek-success branch and again after the if block; consider removing the inner close to avoid redundant calls and keep the control flow simpler.
  • Since the temporary file is only used to test seek support, you could early-return on tempFile.open() failure as well, which would make the intent clearer and avoid unnecessary work in the non-seekable case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic now calls tempFile.close() both inside the seek-success branch and again after the if block; consider removing the inner close to avoid redundant calls and keep the control flow simpler.
- Since the temporary file is only used to test seek support, you could early-return on tempFile.open() failure as well, which would make the intent clearer and avoid unnecessary work in the non-seekable case.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Fix permission denied error when reopening temporary file
for seek detection on certain filesystems.

Log: isSupportSeek use QTemporaryFile directly

Bug:https://pms.uniontech.com/bug-view-371275.html
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码修复了临时文件生命周期管理不当导致的逻辑错误,逻辑清晰且实现正确。
修复了原BUG,消除了冗余的系统调用,无安全漏洞,代码质量优秀。

■ 【详细分析】

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

Common::isSupportSeek 函数中,原代码在调用 tempFile.close() 后因 setAutoRemove(true) 导致文件被删除,随后使用 QFile 重新打开必然失败。新代码直接使用未关闭的 tempFile 对象进行 seek(0) 测试,逻辑完全正确。
潜在问题:无
建议:无需额外修改

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

移除了冗余的 QFile 实例化和重新打开逻辑,去除了不必要的注释,代码更加简洁易读。
潜在问题:无
建议:无需额外修改

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

相比原代码,减少了文件关闭后再重新打开的系统调用开销,直接在已打开的文件描述符上进行 seek 操作,性能更优。
潜在问题:无
建议:无需额外修改

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及本地临时文件的读写测试,且使用安全的 Qt API,不存在安全风险。

  • 建议:无需额外修复措施

■ 【改进建议代码示例】

bool Common::isSupportSeek(QString sFileName)
{
    // ... 前置代码 ...
    } else {
        QString tempDir = info.absoluteDir().path();
        QString fileTemplate = tempDir + "/tempfile_XXXXXX";
        QTemporaryFile tempFile(fileTemplate);
        tempFile.setAutoRemove(true);
        if (tempFile.open()) {
            tempFile.write("test\n");
            tempFile.flush();
            if (tempFile.seek(0)) {
                tempFile.close();
                return true;
            }
        }
        tempFile.close();
    }
    return false;
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, 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

@LiHua000

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 1ace061 into linuxdeepin:release/eagle Jul 23, 2026
17 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