[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.

View file

@ -156,8 +156,7 @@ public:
/// @brief Set the path where the bootloader will be installed
void setBootLoaderInstallPath( const QString& path );
void initLayout();
void initLayout( const QVariantList& config );
void initLayout( const QVariantList& config = QVariantList() );
void layoutApply( Device* dev, qint64 firstSector, qint64 lastSector, QString luksPassphrase );
void layoutApply( Device* dev,
@ -256,7 +255,7 @@ private:
bool m_hasRootMountPoint = false;
bool m_isDirty = false;
QString m_bootLoaderInstallPath;
PartitionLayout* m_partLayout;
PartitionLayout m_partLayout;
OsproberEntryList m_osproberLines;

View file

@ -21,6 +21,8 @@
#include "core/PartitionActions.h"
#include "core/PartitionInfo.h"
#include "utils/Variant.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
@ -135,6 +137,79 @@ PartitionLayout::addEntry( const QString& label,
return true;
}
void
PartitionLayout::init( const QVariantList& config )
{
bool ok;
QString sizeString;
QString minSizeString;
QString maxSizeString;
m_partLayout.clear();
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.";
m_partLayout.clear();
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 ( !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.";
m_partLayout.clear();
break;
}
}
if ( !m_partLayout.count() )
{
addEntry( QString( "/" ), QString( "100%" ) );
}
}
QList< Partition* >
PartitionLayout::execute( Device* dev,
qint64 firstSector,

View file

@ -62,6 +62,7 @@ public:
PartitionLayout( const PartitionLayout& layout );
~PartitionLayout();
void init( const QVariantList& config );
bool addEntry( const QString& mountPoint,
const QString& size,
const QString& min = QString(),

View file

@ -596,14 +596,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap )
QFuture< void > future = QtConcurrent::run( this, &PartitionViewStep::initPartitionCoreModule );
m_future->setFuture( future );
if ( configurationMap.contains( "partitionLayout" ) )
{
m_core->initLayout( configurationMap.value( "partitionLayout" ).toList() );
}
else
{
m_core->initLayout();
}
m_core->initLayout( configurationMap.value( "partitionLayout" ).toList() );
}