[partition] Move initLayout logic to object PartitionLayout

- The logic of the method initLayout belongs to the object
  PartitionLayout. Move logic to that object.
- Use a single method initLayout in object PartitionCoreModule.
- Member m_partLayout in object PartitionCoreModule is no longer
  allocated.
This commit is contained in:
Gaël PORTAY 2020-06-19 23:06:38 -04:00
parent eae1e90dce
commit d6ea30b23e
5 changed files with 81 additions and 85 deletions

View file

@ -860,82 +860,10 @@ PartitionCoreModule::setBootLoaderInstallPath( const QString& path )
m_bootLoaderInstallPath = path;
}
void
PartitionCoreModule::initLayout()
{
m_partLayout = new PartitionLayout();
m_partLayout->addEntry( QString( "/" ), QString( "100%" ) );
}
void
PartitionCoreModule::initLayout( const QVariantList& config )
{
bool ok;
QString sizeString;
QString minSizeString;
QString maxSizeString;
m_partLayout = new PartitionLayout();
for ( const auto& r : config )
{
QVariantMap pentry = r.toMap();
if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || !pentry.contains( "filesystem" )
|| !pentry.contains( "size" ) )
{
cError() << "Partition layout entry #" << config.indexOf( r )
<< "lacks mandatory attributes, switching to default layout.";
delete ( m_partLayout );
initLayout();
break;
}
if ( pentry.contains( "size" ) && CalamaresUtils::getString( pentry, "size" ).isEmpty() )
{
sizeString.setNum( CalamaresUtils::getInteger( pentry, "size", 0 ) );
}
else
{
sizeString = CalamaresUtils::getString( pentry, "size" );
}
if ( pentry.contains( "minSize" ) && CalamaresUtils::getString( pentry, "minSize" ).isEmpty() )
{
minSizeString.setNum( CalamaresUtils::getInteger( pentry, "minSize", 0 ) );
}
else
{
minSizeString = CalamaresUtils::getString( pentry, "minSize" );
}
if ( pentry.contains( "maxSize" ) && CalamaresUtils::getString( pentry, "maxSize" ).isEmpty() )
{
maxSizeString.setNum( CalamaresUtils::getInteger( pentry, "maxSize", 0 ) );
}
else
{
maxSizeString = CalamaresUtils::getString( pentry, "maxSize" );
}
if ( !m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ),
CalamaresUtils::getString( pentry, "uuid" ),
CalamaresUtils::getString( pentry, "type" ),
CalamaresUtils::getUnsignedInteger( pentry, "attributes", 0 ),
CalamaresUtils::getString( pentry, "mountPoint" ),
CalamaresUtils::getString( pentry, "filesystem" ),
CalamaresUtils::getSubMap( pentry, "features", ok ),
sizeString,
minSizeString,
maxSizeString ) )
{
cError() << "Partition layout entry #" << config.indexOf( r ) << "is invalid, switching to default layout.";
delete ( m_partLayout );
initLayout();
break;
}
}
m_partLayout.init( config );
}
void
@ -947,7 +875,7 @@ PartitionCoreModule::layoutApply( Device* dev,
const PartitionRole& role )
{
bool isEfi = PartUtils::isEfiSystem();
QList< Partition* > partList = m_partLayout->execute( dev, firstSector, lastSector, luksPassphrase, parent, role );
QList< Partition* > partList = m_partLayout.execute( dev, firstSector, lastSector, luksPassphrase, parent, role );
// Partition::mountPoint() tells us where it is mounted **now**, while
// PartitionInfo::mountPoint() says where it will be mounted in the target system.