Skip to content

fix: match exact dpkg status line for install - #884

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/2c1b00adde4d
Oct 26, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/2c1b00adde4d

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: match exact dpkg status line for install

  1. Root cause: packageHasInstalled used r.contains("installed")
    substring match, but dpkg output for uninstalled packages also
    contains "installed" causing false positive
  2. Fix: change to r.contains("Status: install ok installed") for
    exact dpkg status line matching
  3. Impact: uninstalled packages no longer misjudged as installed,
    no behavior change for installed packages

Influence:

  1. Test packageHasInstalled with installed package output
  2. Test packageHasInstalled with uninstalled package output
  3. Verify no regression on dde-printer detection

fix: 精确匹配 dpkg 状态行判断安装状态

  1. 根因:packageHasInstalled 使用 r.contains("installed") 子串匹配,
    未安装包输出同样包含 "installed" 导致误判为已安装
  2. 方案:改为 r.contains("Status: install ok installed") 精确匹配
    dpkg 标准状态行
  3. 影响:未安装包不再误判为已安装,已安装包行为不变

Influence:

  1. 测试已安装包的 packageHasInstalled 返回 true
  2. 测试未安装包的 packageHasInstalled 返回 false
  3. 验证 dde-printer 检测逻辑无回归

PMS: DEF-DM-PAGE-001

Summary by Sourcery

Match the exact dpkg installation status when determining whether a package is installed.

Bug Fixes:

  • Correct package installation detection by requiring the exact dpkg status line, preventing uninstalled packages from being reported as installed.

Tests:

  • Add parameterized coverage for installed, uninstalled, empty, and dde-printer dpkg output cases.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 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 4 days and 19 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes package installation detection by matching the canonical Status: install ok installed dpkg status line instead of any occurrence of installed, preventing uninstalled packages from being reported as installed while adding parameterized coverage for representative outputs, including dde-printer.

Sequence diagram for exact dpkg package installation detection

sequenceDiagram
    participant PageInfo
    participant Dpkg as dpkg

    PageInfo->>Dpkg: packageHasInstalled(packageName)
    Dpkg-->>PageInfo: dpkg status output
    PageInfo->>PageInfo: QByteArray::contains("Status: install ok installed")
    alt canonical installed status present
        PageInfo-->>PageInfo: return true
    else canonical status absent
        PageInfo-->>PageInfo: return false
    end
Loading

File-Level Changes

Change Details Files
Use the complete dpkg status field to determine whether a package is installed.
  • Replace the broad substring check with an exact status-line substring match.
  • Preserve the existing logging and return behavior for installed and uninstalled packages.
deepin-devicemanager/src/Page/PageInfo.cpp
Add parameterized coverage for dpkg output parsing.
  • Verify installed status output returns true, including realistic dde-printer output.
  • Verify empty and uninstalled-package output return false.
deepin-devicemanager/tests/src/Page/ut_pageinfo.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

@add-uos
add-uos force-pushed the agent/bug/2c1b00adde4d branch 2 times, most recently from 4eaf24a to 9c3a269 Compare October 26, 2026 02:43
1. Root cause: packageHasInstalled used r.contains("installed")
   substring match, but dpkg output for uninstalled packages also
   contains "installed" causing false positive
2. Fix: change to r.contains("Status: install ok installed") for
   exact dpkg status line matching
3. Rebased onto latest upstream master to resolve merge conflicts
4. Impact: uninstalled packages no longer misjudged as installed,
   no behavior change for installed packages

Influence:
1. Test packageHasInstalled with installed package output
2. Test packageHasInstalled with uninstalled package output
3. Verify no regression on dde-printer detection

fix: 精确匹配 dpkg 状态行判断安装状态

1. 根因:packageHasInstalled 使用 r.contains("installed") 子串匹配,
   未安装包输出同样包含 "installed" 导致误判为已安装
2. 方案:改为 r.contains("Status: install ok installed") 精确匹配
   dpkg 标准状态行
3. 基于最新上游 master 分支 rebase 解决合并冲突,版权头格式已与
   上游一致
4. 影响:未安装包不再误判为已安装,已安装包行为不变

Influence:
1. 测试已安装包的 packageHasInstalled 返回 true
2. 测试未安装包的 packageHasInstalled 返回 false
3. 验证 dde-printer 检测逻辑无回归

PMS: BUG-DEF-DM-PAGE-001
@add-uos
add-uos force-pushed the agent/bug/2c1b00adde4d branch from 9c3a269 to e660550 Compare October 26, 2026 05:23
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 packageHasInstalled 中以裸子串 'installed' 判断安装状态导致的误判缺陷,改为精确匹配 dpkg 状态行 'Status: install ok installed',逻辑正确且附带参数化测试。语法逻辑、性能、安全三维度无问题;代码质量维度仅有测试未直接调用生产函数的轻微改进建议。无安全漏洞,代码审查通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: ['无需修改,逻辑修复正确。']


2. 代码质量 ✅

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

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

建议: ['将 dpkg 输出解析逻辑抽取为可测试的静态/辅助方法(如 static bool isDpkgStatusInstalled(const QByteArray &output)),让测试直接调用该方法,从而真正回归验证生产代码。', '测试数据改用真实 dpkg -s 输出样本,使测试更具实际意义。']


3. 代码性能 ✅

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

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

建议: ['无需优化。']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无需安全加固。']


💡 改进建议代码示例

// PageInfo.h —— 抽取可测试的解析方法
class PageInfo {
public:
    // 判断 dpkg -s 输出是否表示已安装
    static bool isDpkgStatusInstalled(const QByteArray &output) {
        return output.contains("Status: install ok installed");
    }
    bool packageHasInstalled(const QString &packageName);
};

// PageInfo.cpp
bool PageInfo::packageHasInstalled(const QString &packageName) {
    QProcess p;
    p.start("dpkg", QStringList() << "-s" << packageName);
    p.waitForFinished(-1);
    return isDpkgStatusInstalled(p.readAll());
}

// ut_pageinfo.cpp —— 测试直接调用生产代码
TEST_P(PackageHasInstalled_UT, ParseDpkgOutput) {
    const auto &param = GetParam();
    bool result = PageInfo::isDpkgStatusInstalled(param.dpkgOutput);
    EXPECT_EQ(param.expectedResult, result);
}

INSTANTIATE_TEST_SUITE_P(DpkgOutputCases, PackageHasInstalled_UT,
    testing::Values(
        PackageHasInstalledParam{"Status: install ok installed\n", true},
        PackageHasInstalledParam{"Package: dde-printer\nStatus: install ok installed\nPriority: optional\n", true},
        PackageHasInstalledParam{"Status: unknown ok not-installed\n", false},
        PackageHasInstalledParam{"", false}
    ));

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@add-uos

add-uos commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 4a8e526 into linuxdeepin:master Oct 26, 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