Skip to content

Commit 23ae0bb

Browse files
committed
fix: get the storage size info from smartctl
fix get the storage size info from smartctl Log: fix get the storage size info from smartctl. Bug: https://pms.uniontech.com/bug-view-312479.html Change-Id: I5ee5e270c0d5170d4c950d82bf028a0c6023693f
1 parent ed89899 commit 23ae0bb

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// 项目自身文件
66
#include "DeviceStorage.h"
77
#include "commonfunction.h"
8+
#include <cfloat>
89
#include <cmath>
910

1011
// Qt库文件
@@ -477,16 +478,16 @@ QString DeviceStorage::compareSize(const QString &size1, const QString &size2)
477478
return size1 + size2;
478479

479480
// 将字符串转为数字大小进行比较
480-
int num1 = 0;
481-
int num2 = 0;
482-
QRegExp reg(".*\\[(\\d*).*\\]$");
481+
float num1 = 0;
482+
float num2 = 0;
483+
QRegExp reg(".*\\[(\\d+\\.?\\d+).*\\]");
483484
if (reg.exactMatch(size1))
484-
num1 = reg.cap(1).toInt();
485+
num1 = reg.cap(1).toFloat();
485486
if (reg.exactMatch(size2))
486-
num2 = reg.cap(1).toInt();
487+
num2 = reg.cap(1).toFloat();
487488

488489
// 返回较大值
489-
if (num1 > num2)
490+
if ((num1 - num2) > FLT_EPSILON * fmaxf(fabsf(num1), fabsf(num2)))
490491
return size1;
491492
else
492493
return size2;
@@ -685,6 +686,9 @@ void DeviceStorage::getInfoFromsmartctl(const QMap<QString, QString> &mapInfo)
685686

686687
capacity.replace(",","").replace(" ","");
687688
QRegExp re("(\\d+)bytes*"); //取值格式如: User Capacity: 1,000,204,886,016 bytes [1.00 TB] Total NVM Capacity: 256,060,514,304 [256 GB]
689+
if (!capacity.contains("bytes", Qt::CaseInsensitive)) {
690+
re.setPattern("(\\d+)");
691+
}
688692
int pos = re.indexIn(capacity);
689693
if (pos != -1) {
690694
QString byteSize = re.cap(1);

0 commit comments

Comments
 (0)