Skip to content

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

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Aug 6, 2026
Merged

fix(storage): widen disk size matching tolerance to ±2 GB#722
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos

@add-uos add-uos commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

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:

  • Adjust disk capacity matching tolerance from approximately ±1 GB to ±2 GB when mapping raw byte sizes to 256 GB, 512 GB, 1 TB, and 2 TB labels to better handle devices with larger nominal deviations.

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 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.

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

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

Reviewer's Guide

Widens the acceptable byte ranges used by DeviceStorage::checkDiskSize() so that more disks are mapped to the standard 256 GB / 512 GB / 1 TB / 2 TB labels.

Flow diagram for updated DeviceStorage::checkDiskSize() size matching

flowchart TD
    A[m_SizeBytes] --> B{m_SizeBytes in 256GB range}
    B -->|> 254*gbyte and < 258*gbyte| C[set m_Size = 256 GB]
    B -->|else| D{m_SizeBytes in 512GB range}
    D -->|> 510*gbyte and < 514*gbyte| E[set m_Size = 512 GB]
    D -->|else| F{m_SizeBytes in 1TB range}
    F -->|> 998*gbyte and < 1026*gbyte| G[set m_Size = 1 TB]
    F -->|else| H{m_SizeBytes in 2TB range}
    H -->|> 1998*gbyte and < 2050*gbyte| I[set m_Size = 2 TB]
    H -->|else| J[m_Size unchanged]
Loading

File-Level Changes

Change Details Files
Relax disk capacity matching thresholds in checkDiskSize() to a ±2 GB window around nominal sizes.
  • Adjusted 256 GB matching range from (255, 257) GB to (254, 258) GB in terms of m_SizeBytes/gbyte bounds.
  • Adjusted 512 GB matching range from (511, 513) GB to (510, 514) GB.
  • Adjusted 1 TB matching range from approximately (999, 1025) GB to (998, 1026) GB.
  • Adjusted 2 TB matching range from approximately (1999, 2049) GB to (1998, 2050) GB, widening all ranges symmetrically.
deepin-devicemanager/src/DeviceManager/DeviceStorage.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码正确扩大了存储容量标称匹配区间的容错范围,解决了边缘容量硬盘显示异常的问题
逻辑完全正确且无任何安全风险,因硬编码扩展性一般扣5分

■ 【详细分析】

  • 1.语法逻辑 完全正确 ✓
    修改位于 DeviceStorage::checkDiskSize 函数中,通过将各容量档位的判断区间上下界各放宽约 1GB,有效覆盖了底层汇报容量的微小波动,边界计算无误
    建议:无需修改
  • 2.代码质量 良好 ✓
    代码风格与原代码保持一致,注释清晰说明了修改意图,精准修复了特定 BUG
    潜在问题:采用硬编码的 if-else 链进行档位匹配,当未来需要支持 4TB、8TB 等更大容量时,代码会变得冗长且难以维护
    建议:在后续迭代中可考虑将容量档位与阈值提取为静态配置数组进行遍历匹配,提升可扩展性
  • 3.代码性能 高效 ✓
    仅包含基础的整数乘法与大小比较运算,时间复杂度为 O(1),无任何性能瓶颈
    建议:无需修改
  • 4.代码安全 存在0个安全漏洞 ✓
    漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
    代码不涉及外部输入、内存操作、系统调用或权限变更,纯算术比较逻辑绝对安全
  • 建议:无需修改

■ 【改进建议代码示例】

--- a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp
+++ b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp
@@ -577,13 +577,13 @@ void DeviceStorage::checkDiskSize()
 
     quint64 gbyte =  1000000000;
 //    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) {
+    } else if (m_SizeBytes > 510*gbyte && m_SizeBytes < 514*gbyte) {
         m_Size = "512 GB";
-    } else if (m_SizeBytes > 999*gbyte && m_SizeBytes < 1025*gbyte) {
+    } else if (m_SizeBytes > 998*gbyte && m_SizeBytes < 1026*gbyte) {
         m_Size = "1 TB";
-    } else if (m_SizeBytes > 1999*gbyte && m_SizeBytes < 2049*gbyte) {
+    } else if (m_SizeBytes > 1998*gbyte && m_SizeBytes < 2050*gbyte) {
         m_Size = "2 TB";
     }
 //    }

@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 Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 52e9f7f into linuxdeepin:develop/eagle Aug 6, 2026
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