Skip to content

fix(storage): show real partition table type in disk info - #224

Closed
tianming-1996 wants to merge 1 commit into
linuxdeepin:release/1071from
tianming-1996:fix/storage-parttable-display
Closed

tianming-1996 wants to merge 1 commit into
linuxdeepin:release/1071from
tianming-1996:fix/storage-parttable-display

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Sep 23, 2026 •

Copy link
Copy Markdown

Read the partition table type from lsblk pttype and use it to normalize the capabilities string, so a GPT disk no longer shows "partitioned:dos" (which comes from lshw misreading the protective MBR) and the redundant bare "partitioned" token is dropped.

从 lsblk pttype 读取分区表类型并用于修正 capabilities 显示,避免 GPT 盘因 lshw 误读保护性 MBR 而显示 partitioned:dos,同时去掉冗余的裸 partitioned。

Log: 修复磁盘信息中分区表类型显示错误的问题
Influence: 磁盘信息的"功能"中分区表类型显示准确(如 GPT 盘显示 partitioned:gpt),不改变其它信息。

Summary by Sourcery

Display accurate disk partition table types in storage information.

Bug Fixes:

  • Correct disk capability output by using the partition table type reported by lsblk, preventing GPT disks from being displayed as DOS and removing redundant partitioned labels.

Tests:

  • Add unit coverage for partition table detection and capability normalization, including GPT, unpartitioned, and unchanged capability cases.

Chores:

  • Add the GPL-3.0-or-later license text and update copyright years.

@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes inaccurate disk capability display by obtaining the partition-table type from lsblk, using it to correct lshw-derived partitioning tokens, and removing redundant bare partitioned output while preserving other capabilities. Unit tests cover normalization behavior and mocked lsblk parsing.

Sequence diagram for normalized disk capability display

sequenceDiagram
    participant PartedCore
    participant DeviceStorage
    participant Lsblk
    participant Lshw

    PartedCore->>DeviceStorage: getDiskInfoFromLsblk(devicepath)
    DeviceStorage->>Lshw: read disk capabilities
    Lshw-->>DeviceStorage: capabilities
    PartedCore->>DeviceStorage: getDiskInfoPartTableType(devicepath)
    DeviceStorage->>Lsblk: lsblk -d -o name,pttype devicepath
    Lsblk-->>DeviceStorage: pttype
    PartedCore->>DeviceStorage: cleanCapabilitiesForDisplay(capabilities, partTableType)
    DeviceStorage-->>PartedCore: normalized capabilities
Loading

Flow diagram for partition capability normalization

flowchart TD
    A[Disk capabilities from lshw] --> B[Read partition table type from lsblk pttype]
    B --> C{pttype available}
    C -->|yes| D[Replace partitioned scheme with pttype]
    C -->|no| E[Preserve existing capabilities]
    D --> F[Remove redundant bare partitioned token]
    E --> G[Return display capabilities]
    F --> G
Loading

File-Level Changes

Change Details Files
Read the disk partition-table type from lsblk and use it to normalize the displayed capabilities.
  • Add a helper that queries lsblk -d -o name,pttype and parses the single-disk result.
  • Store the detected partition-table type during disk-info collection.
  • Override partitioned:<scheme> with the lsblk value and remove redundant bare partitioned tokens when appropriate.
  • Pass the cleaned capabilities string into the returned disk-info structure without changing the original member value.
service/diskoperation/DeviceStorage.cpp
service/diskoperation/DeviceStorage.h
service/diskoperation/partedcore.cpp
Add unit coverage for capability normalization and lsblk partition-table parsing.
  • Verify redundant-token removal, scheme correction, preservation of unrelated or unqualified capabilities, and empty input handling.
  • Mock lsblk output to cover GPT detection and unpartitioned disks.
test/ut_diskoperation/ut_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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tianming-1996

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

@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 reviewed your changes and they look great!


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

@tianming-1996
tianming-1996 force-pushed the fix/storage-parttable-display branch from 15af609 to 1f26e38 Compare September 23, 2026 13:01
Read the partition table type from lsblk pttype and use it to normalize
the capabilities string, so a GPT disk no longer shows "partitioned:dos"
(which comes from lshw misreading the protective MBR) and the redundant
bare "partitioned" token is dropped.

Also add the missing LICENSES/GPL-3.0-or-later.txt, which the translation
scripts reference, so the REUSE license check passes on release/1071.

从 lsblk pttype 读取分区表类型并用于修正 capabilities 显示,避免 GPT 盘因
lshw 误读保护性 MBR 而显示 partitioned:dos,同时去掉冗余的裸 partitioned。

补齐 release/1071 缺失的 LICENSES/GPL-3.0-or-later.txt(翻译脚本引用),
使 REUSE license 检查通过。

Log: 修复磁盘信息中分区表类型显示错误的问题
Influence: 磁盘信息的"功能"中分区表类型显示准确(如 GPT 盘显示 partitioned:gpt),不改变其它信息。
@tianming-1996
tianming-1996 force-pushed the fix/storage-parttable-display branch from 1f26e38 to 7c0af80 Compare September 23, 2026 13:17
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 90 分,大于 70 分通过阈值,代码质量符合要求。本次提交修复了磁盘信息中分区表类型显示不准确的问题,新增 lsblk pttype 获取真实分区表类型并清洗 capabilities 显示,代码结构清晰且包含完整单元测试。

🔍 详细分析

1. 语法逻辑 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. service/diskoperation/DeviceStorage.cpp:279 - QString::SkipEmptyParts 在 Qt 5.15+ 已废弃,应替换为 Qt::SkipEmptyParts

建议: 将 QString::SkipEmptyParts 替换为 Qt::SkipEmptyParts 以消除废弃警告,保持与 Qt 5.15+ 的兼容性


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. service/diskoperation/DeviceStorage.cpp:274 - cleanCapabilitiesForDisplay 函数两次遍历 tokens,可简化为单次遍历

建议: 考虑将 hasPartitionedScheme 的检查与结果构建合并为单次遍历,或使用更简洁的条件表达式提升可读性


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. service/diskoperation/DeviceStorage.cpp:262 - waitForFinished(-1) 无超时设置,可能导致程序挂起
  2. service/diskoperation/DeviceStorage.cpp:259 - 使用命令字符串拼接而非分离参数形式调用 QProcess::start

建议: 建议设置合理的超时时间,如 proc.waitForFinished(5000),并在超时后进行错误处理


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 建议使用 QProcess::start(program, args) 分离形式:proc.start("lsblk", QStringList() << "-d" << "-o" << "name,pttype" << devicePath),避免参数拼接


💡 改进建议代码示例

// 修复建议1: 使用 Qt::SkipEmptyParts 替换废弃的 QString::SkipEmptyParts
QStringList tokens = caps.split(" ", Qt::SkipEmptyParts);

// 修复建议2: 使用分离参数形式调用 QProcess,并设置超时
QString DeviceStorage::getDiskInfoPartTableType(const QString &devicePath)
{
    QProcess proc;
    proc.start("lsblk", QStringList() << "-d" << "-o" << "name,pttype" << devicePath);
    if (!proc.waitForStarted(3000)) {
        return QString();
    }
    if (!proc.waitForFinished(5000)) {
        proc.kill();
        proc.waitForFinished(1000);
        return QString();
    }

    QMap<QString, QString> mapInfo;
    loadLsblkInfo(proc.readAllStandardOutput(), mapInfo);

    if (mapInfo.size() == 1) {
        return mapInfo.value(mapInfo.firstKey());
    }
    return QString();
}

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

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.

2 participants