Add support for smartmontools 7.0 user_capacity json output

Summary:
smartmontools 7.0 reports user capacity as an object that contains bytes and blocks value, instead of being an int that just contains bytes
This should fix incorrect calculation of bad blocks threshold and incorrect display of "Overall" status

Test Plan:
run partitionmanager on a system that has smartmontools 7, open smart status
overall status should be reported correctly

Reviewers: stikonas

Reviewed By: stikonas

Differential Revision: https://phabricator.kde.org/D21311
This commit is contained in:
Valerii Malov 2019-05-20 22:22:01 +03:00
parent 8238c94447
commit 9565ef61ab
1 changed files with 9 additions and 1 deletions

View File

@ -91,7 +91,15 @@ bool SmartParser::init()
m_DiskInformation->setModel(smartJson[model_name].toString());
m_DiskInformation->setFirmware(smartJson[firmware].toString());
m_DiskInformation->setSerial(smartJson[serial_number].toString());
m_DiskInformation->setSize(smartJson[user_capacity].toVariant().toULongLong());
if (smartJson[user_capacity].isObject()) {
// smartmontools 7.0+
const auto user_capacity_object = smartJson[user_capacity].toObject();
QString user_capacity_bytes = QStringLiteral("bytes");
m_DiskInformation->setSize(user_capacity_object[user_capacity_bytes].toVariant().toULongLong());
} else {
m_DiskInformation->setSize(smartJson[user_capacity].toVariant().toULongLong());
}
QJsonObject selfTest = smartJson[self_test].toObject();
QJsonObject selfTestStatus = selfTest[status].toObject();