fix(storage): compare size by raw bytes instead of localized float - #714
Conversation
Extract raw byte count before brackets for accurate comparison across locales with different thousand separators (comma/dot). 提取方括号前的原始字节数进行比较,解决不同locale下千分位 分隔符(逗号/点)导致的大小比较错误。 Log: 修复存储设备大小比较在非中文locale下出错的问题 PMS: 371721 Influence: 存储设备大小比较逻辑,影响smartctl解析的设备容量显示
Reviewer's GuideDeviceStorage::compareSize now compares storage sizes using the raw byte count extracted from the localized smartctl output instead of parsing the human-readable value inside brackets, fixing locale-dependent comparison errors. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The second qCDebug message still references
num1/num2even though the logic now usesbytes1/bytes2, which can confuse future readers and should be updated to match the new variables. - Consider handling space or non-breaking-space thousand separators in
extractBytes(common in some locales) and/or documenting that only comma/dot-separated formats are supported, to avoid future surprises when new locales are introduced.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The second qCDebug message still references `num1`/`num2` even though the logic now uses `bytes1`/`bytes2`, which can confuse future readers and should be updated to match the new variables.
- Consider handling space or non-breaking-space thousand separators in `extractBytes` (common in some locales) and/or documenting that only comma/dot-separated formats are supported, to avoid future surprises when new locales are introduced.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
0ca76cc to
24f35d0
Compare
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 提取原始字节数(方括号前的数字,千分位逗号/点)比较
auto extractBytes = [](const QString &str) -> quint64 {
static QRegularExpression reg("(\\d[\\d,.]*)\\s*(?:bytes\\s*)?\\[");
QRegularExpressionMatch match = reg.match(str);
if (match.hasMatch()) {
QString raw = match.captured(1);
raw.remove(",");
raw.remove(".");
return raw.toULongLong();
}
return 0;
};
quint64 bytes1 = extractBytes(size1);
quint64 bytes2 = extractBytes(size2);
if (bytes1 > bytes2) {
qCDebug(appLog) << "DeviceStorage::compareSize, bytes1 > bytes2";
return size1;
} else {
qCDebug(appLog) << "DeviceStorage::compareSize, bytes1 <= bytes2";
return size2;
} |
|
[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 |
|
/merge |
Extract raw byte count before brackets for accurate comparison across locales with different thousand separators (comma/dot).
提取方括号前的原始字节数进行比较,解决不同locale下千分位
分隔符(逗号/点)导致的大小比较错误。
Log: 修复存储设备大小比较在非中文locale下出错的问题
PMS: 371721
Influence: 存储设备大小比较逻辑,影响smartctl解析的设备容量显示
Summary by Sourcery
Bug Fixes: