Skip to content

fix: fix checkLocalFolder ignoring param and remove dead code - #938

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/4d906d7e3dde
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/4d906d7e3dde

Conversation

@add-uos

@add-uos add-uos commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

fix: fix checkLocalFolder ignoring param and remove dead code

  1. Root cause: checkLocalFolder(const QString &path) discarded the
    parameter via Q_UNUSED(path) and used member mp_folderPath instead,
    making the API misleading; CmdButtonWidget::paintEvent called
    this->rect().setWidth(808) on a temporary QRect copy, which is
    dead code since the next line achieves the intent correctly
  2. Fix: remove Q_UNUSED(path) and use the path parameter in
    QStorageInfo constructor; remove the dead code line in paintEvent
  3. Impact: checkLocalFolder now validates the actual parameter passed
    by the caller; paintEvent behavior unchanged since the dead line
    had no effect; current callers pass the same value so no behavior
    change in practice

Influence:

  1. Test checkLocalFolder with a local valid folder path
  2. Test checkLocalFolder with a non-local or invalid path
  3. Verify CmdButtonWidget paint rendering is unchanged

fix: 修复checkLocalFolder忽略形参及移除paintEvent死代码

  1. 根因:checkLocalFolder(const QString &path) 通过 Q_UNUSED(path)
    丢弃形参,实际使用成员 mp_folderPath,导致 API 语义误导;
    CmdButtonWidget::paintEvent 中 this->rect().setWidth(808) 对
    临时 QRect 副本调用,属于死代码,下一行已正确实现相同逻辑
  2. 方案:移除 Q_UNUSED(path),将 QStorageInfo info(mp_folderPath)
    改为 QStorageInfo info(path);移除 paintEvent 中的死代码行
  3. 影响:checkLocalFolder 现在校验实际传入的形参;paintEvent 行为
    不变(死代码行本就无效果);当前调用点传入值与成员相同,实际
    无行为变化

Influence:

  1. 测试 checkLocalFolder 传入本地有效文件夹路径
  2. 测试 checkLocalFolder 传入非本地或无效路径
  3. 验证 CmdButtonWidget 绘制效果无变化

Fixes: #936
PMS: BUG-bug-fix-936-1

Summary by Sourcery

Correct local-folder validation semantics and remove ineffective painting code.

Bug Fixes:

  • Make checkLocalFolder validate the path supplied by the caller instead of an unrelated stored path.

Enhancements:

  • Remove ineffective rectangle modification code from CmdButtonWidget painting.

Tests:

  • Update URL chooser coverage to verify local-folder checks use the supplied path.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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 commented Oct 26, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

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

Reviewer's Guide

This PR fixes checkLocalFolder so it validates the path supplied by its caller and removes a no-op QRect mutation from CmdButtonWidget::paintEvent; rendering and current-call behavior should remain unchanged.

Sequence diagram for validating the caller-provided folder path

sequenceDiagram
    participant Caller
    participant UrlChooserEdit
    participant QStorageInfo

    Caller->>UrlChooserEdit: checkLocalFolder(path)
    UrlChooserEdit->>QStorageInfo: QStorageInfo(path)
    QStorageInfo-->>UrlChooserEdit: isValid() and device()
    alt local valid folder
        UrlChooserEdit->>UrlChooserEdit: setAlert(false)
    else non-local or invalid path
        UrlChooserEdit->>UrlChooserEdit: setAlert(true)
    end
Loading

File-Level Changes

Change Details Files
Make local-folder validation honor the caller-provided path instead of an unrelated member field.
  • Removed the unused-parameter suppression.
  • Constructed QStorageInfo from the path argument, preserving existing local-device validation and alert behavior.
deepin-devicemanager/src/Widget/UrlChooserEdit.cpp
Remove ineffective geometry code from button painting.
  • Deleted the width update applied to a temporary QRect.
  • Retained the subsequent local QRect width update used for rendering.
deepin-devicemanager/src/Widget/CmdButtonWidget.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

1. Root cause: checkLocalFolder(const QString &path) discarded the
   parameter via Q_UNUSED(path) and used member mp_folderPath instead,
   making the API misleading; CmdButtonWidget::paintEvent called
   this->rect().setWidth(808) on a temporary QRect copy, which is
   dead code since the next line achieves the intent correctly
2. Fix: remove Q_UNUSED(path) and use the path parameter in
   QStorageInfo constructor; remove the dead code line in paintEvent;
   update UT_UrlChooserEdit_checkLocalFolder_001 to pass smb:// path
   matching mp_folderPath so the test validates fixed behavior
3. Impact: checkLocalFolder now validates the actual parameter passed
   by the caller; paintEvent behavior unchanged since the dead line
   had no effect; test case now correctly expects alert for non-local
   path; current callers pass the same value so no behavior change

Influence:
1. Test checkLocalFolder with a local valid folder path
2. Test checkLocalFolder with a non-local or invalid path
3. Verify CmdButtonWidget paint rendering is unchanged

fix: 修复checkLocalFolder忽略形参及更新测试用例

1. 根因:checkLocalFolder(const QString &path) 通过 Q_UNUSED(path)
   丢弃形参,实际使用成员 mp_folderPath,导致 API 语义误导;
   CmdButtonWidget::paintEvent 中 this->rect().setWidth(808) 对
   临时 QRect 副本调用,属于死代码,下一行已正确实现相同逻辑
2. 方案:移除 Q_UNUSED(path),将 QStorageInfo info(mp_folderPath)
   改为 QStorageInfo info(path);移除 paintEvent 中的死代码行;
   更新 UT_UrlChooserEdit_checkLocalFolder_001 传入 smb:// 路径
   与 mp_folderPath 一致,使测试验证修复后的正确行为
3. 影响:checkLocalFolder 现在校验实际传入的形参;paintEvent 行为
   不变(死代码行本就无效果);测试用例现在正确期望非本地路径
   触发告警;当前调用点传入值与成员相同,实际无行为变化

Influence:
1. 测试 checkLocalFolder 传入本地有效文件夹路径
2. 测试 checkLocalFolder 传入非本地或无效路径
3. 验证 CmdButtonWidget 绘制效果无变化

Fixes: linuxdeepin#936
PMS: BUG-bug-fix-936-1
@add-uos
add-uos force-pushed the agent/pms-bug-bot/4d906d7e3dde branch from ba9191d to 84a7f45 Compare October 26, 2026 16:45
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 checkLocalFolder 函数忽略 path 参数的 Bug,并移除了 CmdButtonWidget 中的无效代码。 生产代码修复正确,语法逻辑清晰,无安全漏洞。但测试用例存在逻辑缺陷:mp_folderPath 与 path 参数 设置为相同值,导致测试无法真正验证修复效果(即使 Bug 仍存在测试也会通过)。建议改进测试用例以 确保使用不同值来验证参数被正确使用。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['修改测试用例,使 mp_folderPath 和 path 参数使用不同的值。例如设置 mp_folderPath 为本地路径 "/home",传入非本地路径 "smb://10.4.10.4" 作为参数, 这样如果函数错误地使用 mp_folderPath,isAlert 将为 false,测试会失败']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 改进后的测试用例,使用不同的值来真正验证修复效果
TEST_F(UT_UrlChooserEdit, UT_UrlChooserEdit_checkLocalFolder_001)
{
    // 设置 mp_folderPath 为本地路径,传入非本地路径作为参数
    // 如果 checkLocalFolder 错误地使用 mp_folderPath,isAlert 将为 false,测试会失败
    m_UrlChooserEdit->mp_folderPath = "/home";
    m_UrlChooserEdit->checkLocalFolder("smb://10.4.10.4");
    EXPECT_TRUE(m_UrlChooserEdit->mp_urlEdit->isAlert());

    // 反向测试:传入本地路径作为参数,不应触发 alert
    m_UrlChooserEdit->mp_folderPath = "smb://10.4.10.4";
    m_UrlChooserEdit->checkLocalFolder("/home");
    EXPECT_FALSE(m_UrlChooserEdit->mp_urlEdit->isAlert());
}

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

@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

@add-uos add-uos closed this Oct 29, 2026
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