[luksbootkeyfile] Extract devices that need cryptsetup

- Rename classes and functions to be more descriptive
   (a LuksDevice is .. information for a LUKS device, for instance).
 - Move the smarts of unpacking a QVariantMap to LuksDevice.
 - Apply code formatting
main
Adriaan de Groot 6 years ago
parent 745b4b1693
commit f6c50564cd

@ -38,20 +38,41 @@ LuksBootKeyFileJob::prettyName() const
return tr( "Configuring LUKS key file." ); return tr( "Configuring LUKS key file." );
} }
struct LuksPassphrase struct LuksDevice
{ {
LuksDevice( const QMap< QString, QVariant >& pinfo )
: isValid( false )
, isRoot( false )
{
if ( pinfo.contains( "luksMapperName" ) )
{
QString fs = pinfo[ "fs" ].toString();
QString mountPoint = pinfo[ "mountPoint" ].toString();
if ( !mountPoint.isEmpty() || fs == QStringLiteral( "linuxswap" ) )
{
isValid = true;
isRoot = mountPoint == '/';
device = pinfo[ "device" ].toString();
passphrase = pinfo[ "luksPassphrase" ].toString();
}
}
}
bool isValid;
bool isRoot;
QString device; QString device;
QString passphrase; QString passphrase;
}; };
struct GlobalSettings struct LuksDeviceList
{ {
GlobalSettings( const QVariant& partitions ) LuksDeviceList( const QVariant& partitions )
: valid( false ) : valid( false )
{ {
if ( partitions.canConvert<QVariantList>() ) if ( partitions.canConvert< QVariantList >() )
{ {
filesystems = getPartitionInfo( partitions.toList() ); devices = getLuksDevices( partitions.toList() );
valid = true; valid = true;
} }
} }
@ -62,27 +83,26 @@ struct GlobalSettings
* so there's maps with keys inside), returns just the list of * so there's maps with keys inside), returns just the list of
* luks passphrases for each device. * luks passphrases for each device.
*/ */
static QList< LuksPassphrase > getPartitionInfo( const QVariantList& list ) static QList< LuksDevice >
getLuksDevices( const QVariantList& list )
{ {
int count = 0; QList< LuksDevice > luksItems;
for( const auto& p : list )
for ( const auto& p : list )
{ {
if ( p.canConvert< QVariantMap>() ) if ( p.canConvert< QVariantMap >() )
{ {
auto pinfo = p.toMap(); LuksDevice d( p.toMap() );
QString device = pinfo["device"].toString(); if ( d.isValid )
QString fs = pinfo["fs"].toString(); {
QString mountPoint = pinfo["mountPoint"].toString(); luksItems.append( d );
QString uuid = pinfo["uuid"].toString(); }
cDebug() << count << "D=" << device << mountPoint << '(' << fs << ')';
} }
count++;
} }
return QList< LuksPassphrase >(); return luksItems;
} }
QList< LuksPassphrase > filesystems; QList< LuksDevice > devices;
bool valid; bool valid;
}; };
@ -103,7 +123,13 @@ LuksBootKeyFileJob::exec()
Calamares::JobResult::InvalidConfiguration ); Calamares::JobResult::InvalidConfiguration );
} }
GlobalSettings s( gs->value( "partitions" ) ); LuksDeviceList s( gs->value( "partitions" ) );
cDebug() << "There are" << s.devices.count() << "LUKS partitions";
for ( const auto& p : s.devices )
{
cDebug() << Logger::SubEntry << p.isRoot << p.device << p.passphrase;
}
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
} }

Loading…
Cancel
Save