Repository navigation
fix: fix 3 defects in DriverControl module - #854
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis low-risk fix addresses three independent DriverControl defects: it makes maximum-level driver selection deterministic and efficient, parses two-line apt policy output correctly in both code paths, and aborts backup cleanly when the destination directory cannot be created. Sequence diagram for failed driver backup setupsequenceDiagram
participant Backup as DriverBackupThread
participant FS as QDir
participant Controller as BackupController
Backup->>FS: mkpath(backupPath)
alt directory creation succeeds
Backup->>Backup: apt download
else directory creation fails
Backup-->>Controller: backupProgressFinished(false)
Backup-->>Backup: return
end
Flow diagram for deterministic maximum-level driver selectionflowchart TD
A[Candidate drivers] --> B[Find maximum level]
B --> C{Installed max-level candidate?}
C -->|Yes| D["packageInstall(package_name, deb_version)"]
D --> E[Select first installed candidate]
C -->|No| F[Select first max-level candidate]
E --> G[Continue installation flow]
F --> G
Flow diagram for two-line apt policy parsingflowchart TD
A[apt policy output] --> B{"infoList.size() > 1 + index"}
B -->|Yes| C["Parse infoList[1 + index]"]
C --> D[Populate current version]
B -->|No| E[Version not found]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Root cause: checkDriverInfo used index==0 to mean both "not found" and "element 0 selected", causing redundant packageInstall calls and fallback to non-max-level element when all max-level candidates were uninstalled 2. Fix: introduce bool found flag, break on first installed max-level candidate, fallback loop selects first max-level element when none installed 3. Root cause: apt policy parse guard size()>(2+index) required 3 lines but only consumed 2 lines, skipping valid 2-line output 4. Fix: change guard to size()>(1+index) in DriverScanner.cpp and matching size()<=(1+index) in HttpDriverInterface.cpp 5. Root cause: mkpath failure only logged without stopping, causing downstream apt download to fail on non-existent directory 6. Fix: emit backupProgressFinished(false) and return on mkpath failure Influence: 1. Test driver install with multiple candidates of different levels 2. Test apt policy output with exactly 2 lines (package + Installed) 3. Test backup when temp directory creation fails fix: 修复DriverControl模块3处缺陷 1. 根因:checkDriverInfo中index==0同时表示"未找到"和"选中元素0", 导致冗余调用packageInstall且所有max等级候选未安装时回退非max元素 2. 方案:引入bool found标志位,命中即break,未命中时回退循环选 中第一个max等级元素 3. 根因:apt policy解析守卫size()>(2+index)要求3行但仅消费2行, 2行有效输出被跳过导致版本号为空 4. 方案:DriverScanner.cpp守卫改为>(1+index),HttpDriverInterface.cpp 同源守卫改为<=(1+index) 5. 根因:mkpath失败仅记日志不中止,后续apt download指向不存在目录 6. 方案:mkpath失败时emit backupProgressFinished(false)并return Influence: 1. 测试多候选不同等级的驱动安装场景 2. 测试apt policy输出仅2行(包名+Installed行)的情况 3. 测试临时目录创建失败时的备份流程
3e765f4 to
4d8ad01
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本报告由 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 |
…dling After the checkDriverInfo fix (PR #854), packageInstall is only consulted for candidates at the best level, and the redundant index==0 fallback path was removed. Three checkDriverInfo test fixtures omitted the "level" field, so the uninitialized RepoDriverInfo::iLevel decided the outcome: checkDriverInfo_canUpdate only passed through the removed fallback path and now fails with stack-garbage levels. Set an explicit level in those fixtures and pin the package selection of the not-installed fallback path. All 104 DriverControl tests pass against the fixed code.
Root Cause Analysis
Three independent source defects were identified in the DriverControl module during unit testing (baseline
f2d46ee9):checkDriverInfo selection logic (
HttpDriverInterface.cpp:219-236): Theif (index == 0)branch usedindex=0to mean both "not found" and "element 0 selected", causing redundantpackageInstall()calls (apt policy subprocess) on every loop iteration. When all max-level candidates were uninstalled,indexsilently fell back to element 0, overriding the optimal-level selection.apt policy parse guard too strict (
DriverScanner.cpp:56): Guardsize() > (2 + index)required 3 lines but only consumedinfoList[1 + index](2 lines), causing valid 2-line apt policy output to be skipped, resulting in empty version numbers.mkpath failure silently swallowed (
DriverBackupThread.cpp:49-51):mkpathfailure only logged a message without stopping execution, causing downstreamapt downloadto target a non-existent directory.Fix
Introduced a
bool foundflag incheckDriverInfo,breakon first installed max-level candidate, and added a fallback loop selecting the first max-level element when none are installed. Removed the redundantif (index == 0)branch.Changed guard from
size() > (2 + index)tosize() > (1 + index)in bothDriverScanner.cpp:56andHttpDriverInterface.cpp:288(same-source guard).On
mkpathfailure:emit backupProgressFinished(false)andreturn, with log level upgraded fromqCInfotoqCWarning.Change Safety Assessment
Code Safety
Business Impact Scope
Verification Suggestion
根因分析
单元测试(基线
f2d46ee9)中发现 DriverControl 模块 3 处独立源码缺陷:checkDriverInfo 选型逻辑(
HttpDriverInterface.cpp:219-236):if (index == 0)分支用 index=0 同时表示"未找到"和"选中元素0",导致每轮循环冗余调用packageInstall()(apt policy 子进程)。所有 max 等级候选未安装时 index 静默回退元素 0,最优等级判定失效。apt policy 解析守卫过严(
DriverScanner.cpp:56):守卫size() > (2 + index)要求 3 行但仅消费infoList[1 + index](2 行),2 行有效输出被跳过,版本号为空。mkpath 失败错误被吞(
DriverBackupThread.cpp:49-51):mkpath 失败仅记日志不中止,后续 apt download 指向不存在目录注定失败。修复方案
引入
bool found标志位,命中即break,未命中时回退循环选中第一个 max 等级元素。删除冗余if (index == 0)分支。守卫改为
size() > (1 + index),同步修复HttpDriverInterface.cpp:288同源守卫。mkpath 失败时
emit backupProgressFinished(false)并return,日志级别从qCInfo提升至qCWarning。改动安全评估
代码安全评估
业务影响范围
验证建议
Summary by Sourcery
Fix DriverControl candidate selection, version detection, and backup error handling.
Bug Fixes:
Chores: