Repository navigation
fix: match exact dpkg status line for install - #884
Conversation
Reviewer's GuideThe PR fixes package installation detection by matching the canonical Sequence diagram for exact dpkg package installation detectionsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
4eaf24a to
9c3a269
Compare
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
9c3a269 to
e660550
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无需修改,逻辑修复正确。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['将 dpkg 输出解析逻辑抽取为可测试的静态/辅助方法(如 static bool isDpkgStatusInstalled(const QByteArray &output)),让测试直接调用该方法,从而真正回归验证生产代码。', '测试数据改用真实 dpkg -s 输出样本,使测试更具实际意义。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无需优化。'] 4. 代码安全 🔒评价: 存在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 ¶m = 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 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
fix: match exact dpkg status line for install
substring match, but dpkg output for uninstalled packages also
contains "installed" causing false positive
exact dpkg status line matching
no behavior change for installed packages
Influence:
fix: 精确匹配 dpkg 状态行判断安装状态
未安装包输出同样包含 "installed" 导致误判为已安装
dpkg 标准状态行
Influence:
PMS: DEF-DM-PAGE-001
Summary by Sourcery
Match the exact dpkg installation status when determining whether a package is installed.
Bug Fixes:
Tests: