From 0e4fca8de63da94279cf83b4442267a07faa395c Mon Sep 17 00:00:00 2001 From: Caio Carvalho Date: Sat, 24 Nov 2018 21:45:48 -0300 Subject: [PATCH] Getting lsblk kname in the cases where the model name isn't available Summary: lsblk command does not return model name as output in some specific cases, specially when you have a micro SD in your computer (perhaps it should happen with a normal SD card as well, but I haven't tested it). So I included a verification in SfdiskBackend::scanDevice to check for kname in lsblk and use it as the name in these cases. Reviewers: stikonas Reviewed By: stikonas Tags: #kde_partition_manager Differential Revision: https://phabricator.kde.org/D16577 --- src/plugins/sfdisk/sfdiskbackend.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plugins/sfdisk/sfdiskbackend.cpp b/src/plugins/sfdisk/sfdiskbackend.cpp index 6b54384..899a264 100644 --- a/src/plugins/sfdisk/sfdiskbackend.cpp +++ b/src/plugins/sfdisk/sfdiskbackend.cpp @@ -169,12 +169,23 @@ Device* SfdiskBackend::scanDevice(const QString& deviceNode) if ( d == nullptr && modelCommand.run(-1) && modelCommand.exitCode() == 0 ) { - QString modelName = modelCommand.output(); - modelName = modelName.left(modelName.length() - 1); + QString name = modelCommand.output(); + name = name.left(name.length() - 1); - Log(Log::Level::information) << xi18nc("@info:status", "Device found: %1", modelName); + if (name.trimmed().isEmpty()) { + // Get 'lsblk --output kname' in the cases where the model name is not available. + // As lsblk doesn't have an option to include a separator in its output, it is + // necessary to run it again getting only the kname as output. + ExternalCommand kname(QStringLiteral("lsblk"), {QStringLiteral("--nodeps"), QStringLiteral("--noheadings"), QStringLiteral("--output"), QStringLiteral("kname"), + deviceNode}); - d = new DiskDevice(modelName, deviceNode, 255, 63, deviceSize / logicalSectorSize / 255 / 63, logicalSectorSize); + if (kname.run(-1) && kname.exitCode() == 0) + name = kname.output(); + } + + Log(Log::Level::information) << xi18nc("@info:status", "Device found: %1", name); + + d = new DiskDevice(name, deviceNode, 255, 63, deviceSize / logicalSectorSize / 255 / 63, logicalSectorSize); } if ( d )