Optimize luks::mapperName function.
Now it uses lsblk to find out mapper node. It also makes opened luks volumes to be properly detected when no cryptsetup is found, e.g. crypt is opened in initramfs.
This commit is contained in:
parent
25e28a0e16
commit
6b772f3332
|
@ -511,18 +511,16 @@ bool luks::updateUUID(Report& report, const QString& deviceNode) const
|
|||
|
||||
QString luks::mapperName(const QString& deviceNode)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("find"),
|
||||
{ QStringLiteral("/dev/mapper/"),
|
||||
QStringLiteral("-exec"),
|
||||
QStringLiteral("cryptsetup"),
|
||||
QStringLiteral("status"),
|
||||
QStringLiteral("{}"),
|
||||
QStringLiteral(";") });
|
||||
if (cmd.run()) {
|
||||
QRegExp rxDeviceName(QStringLiteral("(/dev/mapper/[A-Za-z0-9-/]+) is "
|
||||
"active[A-Za-z0-9- \\.\n]+[A-Za-z0-9-: \n]+") + deviceNode);
|
||||
if (rxDeviceName.indexIn(cmd.output()) > -1)
|
||||
return rxDeviceName.cap(1);
|
||||
ExternalCommand cmd(QStringLiteral("lsblk"),
|
||||
{ QStringLiteral("--raw"),
|
||||
QStringLiteral("--noheadings"),
|
||||
QStringLiteral("--output"),
|
||||
QStringLiteral("name"),
|
||||
deviceNode });
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QStringList output=cmd.output().split(QStringLiteral("\n"));
|
||||
output.removeFirst();
|
||||
return QStringLiteral("/dev/mapper/") + output.first();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue