Skip to content

Revert "fix: Fix fail to format disk to FAT32"#196

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1071from
pppanghu77:release/1071
Mar 13, 2026
Merged

Revert "fix: Fix fail to format disk to FAT32"#196
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/1071from
pppanghu77:release/1071

Conversation

@pppanghu77
Copy link

@pppanghu77 pppanghu77 commented Mar 13, 2026

This reverts commit db3d1ce.

Bug: https://pms.uniontech.com/bug-view-352827.html

Summary by Sourcery

Bug Fixes:

  • Re-enable FAT32 disk formatting support by reinstating the FAT32 mapping to the FAT handler in the filesystem registry.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Re-enables FAT32 filesystem support by instantiating a FAT16 handler for FAT32 entries instead of leaving them commented out, effectively reverting a previous change that disabled FAT32 formatting.

Sequence diagram for FAT32 format request using FAT16 handler

sequenceDiagram
actor User
participant UI
participant DiskService
participant SupportedFileSystems
participant FAT16

User ->> UI: requestFormat(device, FS_FAT32)
UI ->> DiskService: format(device, FS_FAT32)
DiskService ->> SupportedFileSystems: getFileSystem(FSType FS_FAT32)
SupportedFileSystems -->> DiskService: FAT16 instance
DiskService ->> FAT16: format(device)
FAT16 -->> DiskService: formatResult
DiskService -->> UI: formatResult
UI -->> User: showFormatResult
Loading

Updated class diagram for SupportedFileSystems FAT32 mapping

classDiagram
class SupportedFileSystems {
  - map<FSType, FileSystem*> m_fsObjects
  + SupportedFileSystems()
  + FileSystem* getFileSystem(FSType type)
}

class FileSystem {
  <<interface>>
  + format(Device device)
  + mount(Device device)
}

class EXT2 {
  + EXT2(FSType type)
}

class FAT16 {
  + FAT16(FSType type)
}

FileSystem <|.. EXT2
FileSystem <|.. FAT16
SupportedFileSystems --> FileSystem : manages_filesystems
SupportedFileSystems --> FAT16 : FS_FAT16_and_FS_FAT32_entries
SupportedFileSystems --> EXT2 : FS_EXT2_FS_EXT3_FS_EXT4_entries
Loading

File-Level Changes

Change Details Files
Re-enable FAT32 filesystem object initialization in the supported filesystems registry.
  • Uncomment the FAT32 entry in the filesystem objects map
  • Instantiate a FAT16-based handler for the FAT32 filesystem identifier
service/diskoperation/supportedfilesystems.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Since FS_FAT32 is being handled by the FAT16 class, consider adding a brief comment explaining this design choice to avoid future confusion or accidental reversion of this line.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `FS_FAT32` is being handled by the `FAT16` class, consider adding a brief comment explaining this design choice to avoid future confusion or accidental reversion of this line.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见

1. 语法逻辑

  • 类型与名称不匹配
    代码中 m_fsObjects[FS_FAT32] 使用了 FAT16 类进行实例化(new FAT16(FS_FAT32))。
    • 潜在问题:虽然 FAT32 是 FAT16 的后续版本,且底层结构有相似之处,但在面向对象编程中,如果 FAT16 类没有明确设计为兼容 FS_FAT32 的多态行为,或者 FAT16 类的构造函数/成员函数没有针对 FAT32 的特殊处理,这会导致逻辑错误。程序可能会错误地按照 FAT16 的逻辑去处理 FAT32 文件系统,导致数据损坏或操作失败。
    • 建议:确认 FAT16 类是否完全支持 FS_FAT32 类型。如果不支持,应该创建专门的 FAT32 类,或者在 FAT16 类内部根据传入的 FS_FAT32 参数进行正确的逻辑分支处理。

2. 代码质量

  • 注释一致性
    代码取消了 m_fsObjects[FS_FAT32] 的注释,启用了该功能。建议检查该模块的单元测试或集成测试是否覆盖了 FAT32 文件系统的相关场景,以确保启用该功能后不会引入回归错误。
  • 命名规范
    变量名 m_fsObjects 使用了驼峰命名法,而 FS_EXT4FS_FAT32 使用了全大写下划线命名法(宏/常量风格)。这在 C++ 中是常见的区分成员变量和枚举/宏的做法,整体风格尚可,但需保持项目内部一致性。

3. 代码性能

  • 内存管理
    使用了裸指针 new FAT16(...) 并将其存入 m_fsObjects 中。
    • 潜在风险:如果 m_fsObjects 是一个普通的指针容器(如 std::map),在析构时需要手动遍历 delete 这些指针,否则会导致内存泄漏。
    • 建议:考虑使用智能指针(如 std::unique_ptrstd::shared_ptr)来管理这些文件系统对象的生命周期。例如,将容器定义为 std::map<int, std::unique_ptr<FileSystemBase>>,这样可以自动管理内存,防止内存泄漏。

4. 代码安全

  • 空指针检查
    如果 new FAT16(FS_FAT32) 抛出异常(例如内存不足),程序可能会中断。虽然现代 C++ 推荐使用异常来处理构造函数失败,但在某些系统级代码中,可能需要更严格的控制。
    • 建议:确保 SupportedFileSystems 的构造函数是异常安全的,或者上层调用者能够处理构造过程中抛出的异常。
  • 类型安全
    直接使用 FS_FAT32(可能是枚举或整数)作为 map 的 key 是可行的,但最好使用 enum class 来替代普通的 enumint,以避免隐式类型转换带来的潜在错误。

改进建议代码示例

假设 FileSystemBase 是基类,建议修改如下:

// 使用 enum class 增强类型安全
enum class FsType { EXT4, FAT32, ... };

// 使用智能指针管理资源
std::map<FsType, std::unique_ptr<FileSystemBase>> m_fsObjects;

SupportedFileSystems::SupportedFileSystems()
{
    // 使用 std::make_unique 并处理可能的异常(如果需要)
    m_fsObjects[FsType::EXT4] = std::make_unique<EXT2>(FsType::EXT4);
    
    // 针对 FAT32,建议确认是否有专门的 FAT32 类
    // 如果 FAT16 类确实兼容 FAT32,请确保文档说明清晰
    m_fsObjects[FsType::FAT32] = std::make_unique<FAT16>(FsType::FAT32);
    
    // ...
}

总结

主要关注点在于 FAT16 类处理 FS_FAT32 的逻辑正确性。如果这是为了兼容性而故意为之,请务必添加详细的注释说明原因,并补充针对 FAT32 的测试用例。同时,建议引入智能指针以提升代码的健壮性和安全性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, pppanghu77

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

@pppanghu77
Copy link
Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Mar 13, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit b84073d into linuxdeepin:release/1071 Mar 13, 2026
17 of 19 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