Skip to content

fix(storage): widen disk size matching tolerance to ±2 GB - #981

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/backport-722-to-master
Nov 18, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/backport-722-to-master

Conversation

@add-uos

@add-uos add-uos commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #722 (merged into release/1071) to master.

Adjust the nominal disk capacity boundaries in checkDiskSize() from ±1 GB to ±2 GB so that storage devices whose reported byte count deviates slightly more from the nominal value are still matched to the standard 256 GB / 512 GB / 1 TB / 2 TB labels.

将 checkDiskSize() 中磁盘容量匹配的上下限容差从 ±1 GB 调整为 ±2 GB,使上报字节数偏离标称值稍大的存储设备仍能匹配到标准的 256 GB / 512 GB / 1 TB / 2 TB 标签。

Log: 调整磁盘容量匹配上下限至±2GB
PMS: 372871
Influence: checkDiskSize 的容量匹配逻辑,影响定制机型存储设备的容量显示规范化

Summary by Sourcery

Bug Fixes:

  • Widen disk capacity matching tolerance to ±2 GB so slightly deviating devices are normalized to the standard 256 GB, 512 GB, 1 TB, and 2 TB labels.

Adjust the nominal disk capacity boundaries in checkDiskSize() from
±1 GB to ±2 GB so that storage devices whose reported byte count
deviates slightly more from the nominal value are still matched to
the standard 256 GB / 512 GB / 1 TB / 2 TB labels.

将 checkDiskSize() 中磁盘容量匹配的上下限容差从 ±1 GB 调整为
±2 GB,使上报字节数偏离标称值稍大的存储设备仍能匹配到标准的
256 GB / 512 GB / 1 TB / 2 TB 标签。

Log: 调整磁盘容量匹配上下限至±2GB
PMS: 372871
Influence: checkDiskSize 的容量匹配逻辑,影响定制机型存储设备的容量显示规范化
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Widen the disk-size thresholds in checkDiskSize() so capacities within ±2 GB of the standard values receive the corresponding labels.

  • deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp L608-614

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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp" line_range="608" />
<code_context>

 //    if (m_Interface.contains("UFS", Qt::CaseInsensitive)) { // TODO Ignore ufs disk
-    if (m_SizeBytes > 255*gbyte && m_SizeBytes < 257*gbyte) {
+    if (m_SizeBytes > 254*gbyte && m_SizeBytes < 258*gbyte) {
         m_Size = "256 GB";
-    } else if (m_SizeBytes > 511*gbyte && m_SizeBytes < 513*gbyte) {
</code_context>
<issue_to_address>
**Endpoint capacities keep raw labels**

When a device reports a capacity exactly at a widened range limit, `checkDiskSize()` uses strict `>` and `<` comparisons, so `m_SizeBytes` at a lower or upper limit does not match the range and `m_Size` keeps its unnormalized value instead of receiving the standard label.

Make the widened range comparisons inclusive at both endpoints.

Also at `deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp:610-614`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨


// if (m_Interface.contains("UFS", Qt::CaseInsensitive)) { // TODO Ignore ufs disk
if (m_SizeBytes > 255*gbyte && m_SizeBytes < 257*gbyte) {
if (m_SizeBytes > 254*gbyte && m_SizeBytes < 258*gbyte) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Endpoint capacities keep raw labels

When a device reports a capacity exactly at a widened range limit, checkDiskSize() uses strict > and < comparisons, so m_SizeBytes at a lower or upper limit does not match the range and m_Size keeps its unnormalized value instead of receiving the standard label.

Make the widened range comparisons inclusive at both endpoints.

Also at deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp:610-614.

Prompt for AI agents
In `deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp` at line 608:

**Endpoint capacities keep raw labels**

When a device reports a capacity exactly at a widened range limit, `checkDiskSize()` uses strict `>` and `<` comparisons, so `m_SizeBytes` at a lower or upper limit does not match the range and `m_Size` keeps its unnormalized value instead of receiving the standard label.

Make the widened range comparisons inclusive at both endpoints.

Also at `deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp:610-614`.

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为磁盘容量匹配容差由 ±1 GB 放宽至 ±2 GB 的 bug 修复,变更范围小且目的明确。 四维度(语法逻辑、代码质量、代码性能、代码安全)均未发现问题,启发式扫描与 OCR 审查 均未报告问题,不存在安全漏洞。代码逻辑正确,无性能影响,无安全风险,审查通过。

🔍 详细分析

1. 语法逻辑 ✅

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

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

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


2. 代码质量 ✅

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

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

建议: ['可选优化:将 gbyte、标称容量阈值等常量提取为命名常量或枚举,提升可维护性,但非本次必须。']


3. 代码性能 ✅

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

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

建议: ['无性能优化建议。']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

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


💡 改进建议代码示例

// 当前实现已正确,无需修复。如需进一步提升可维护性,可将标称容量阈值定义为命名常量: // // const quint64 gbyte = 1000000000; // const quint64 tolerance = 2 * gbyte; // const quint64 nominal_256gb = 256 * gbyte; // if (m_SizeBytes > nominal_256gb - tolerance && m_SizeBytes < nominal_256gb + tolerance) { //     m_Size = "256 GB"; // } // ...其余区间同理

本报告由 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 Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 3b539ae into linuxdeepin:master Nov 18, 2026
18 of 20 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