[partition] Introduce new constructors for PartitionEntry

- Introduces new constructors for PartitionEntry: copy constructory and
  constructor with all attributes.
- Use the new constructor in method addEntry().
main
Gaël PORTAY 4 years ago
parent 3f2dd516d3
commit 81bec68b3d

@ -63,74 +63,60 @@ PartitionLayout::PartitionEntry::PartitionEntry()
{
}
PartitionLayout::PartitionEntry::PartitionEntry( const QString& size, const QString& min, const QString& max )
PartitionLayout::PartitionEntry::PartitionEntry( const QString& mountPoint, const QString& size, const QString& minSize, const QString& maxSize )
: partAttributes( 0 )
, partMountPoint( mountPoint )
, partSize( size )
, partMinSize( min )
, partMaxSize( max )
, partMinSize( minSize )
, partMaxSize( maxSize )
{
}
bool
PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const QString& min, const QString& max )
PartitionLayout::PartitionEntry::PartitionEntry( const QString& label,
const QString& uuid,
const QString& type,
quint64 attributes,
const QString& mountPoint,
const QString& fs,
const QVariantMap& features,
const QString& size,
const QString& minSize,
const QString& maxSize )
: partLabel( label )
, partUUID( uuid )
, partType( type )
, partAttributes( attributes )
, partMountPoint( mountPoint )
, partFeatures( features )
, partSize( size )
, partMinSize( minSize )
, partMaxSize( maxSize )
{
PartitionLayout::PartitionEntry entry( size, min, max );
if ( !entry.isValid() )
{
cError() << "Partition size" << size << "is invalid or" << min << ">" << max;
return false;
}
if ( mountPoint.isEmpty() || !mountPoint.startsWith( QString( "/" ) ) )
{
cError() << "Partition mount point" << mountPoint << "is invalid";
return false;
}
entry.partMountPoint = mountPoint;
entry.partFileSystem = m_defaultFsType;
m_partLayout.append( entry );
PartUtils::findFS( fs, &partFileSystem );
}
return true;
PartitionLayout::PartitionEntry::PartitionEntry( const PartitionEntry& e )
: partLabel( e.partLabel )
, partUUID( e.partUUID )
, partType( e.partType )
, partAttributes( e.partAttributes )
, partMountPoint( e.partMountPoint )
, partFileSystem( e.partFileSystem )
, partFeatures( e.partFeatures )
, partSize( e.partSize )
, partMinSize( e.partMinSize )
, partMaxSize( e.partMaxSize )
{
}
bool
PartitionLayout::addEntry( const QString& label,
const QString& uuid,
const QString& type,
quint64 attributes,
const QString& mountPoint,
const QString& fs,
const QVariantMap& features,
const QString& size,
const QString& min,
const QString& max )
PartitionLayout::addEntry( const PartitionEntry& entry )
{
PartitionLayout::PartitionEntry entry( size, min, max );
if ( !entry.isValid() )
{
cError() << "Partition size" << size << "is invalid or" << min << ">" << max;
return false;
}
if ( mountPoint.isEmpty() || !mountPoint.startsWith( QString( "/" ) ) )
{
cError() << "Partition mount point" << mountPoint << "is invalid";
return false;
}
entry.partLabel = label;
entry.partUUID = uuid;
entry.partType = type;
entry.partAttributes = attributes;
entry.partMountPoint = mountPoint;
PartUtils::findFS( fs, &entry.partFileSystem );
if ( entry.partFileSystem == FileSystem::Unknown )
{
entry.partFileSystem = m_defaultFsType;
}
entry.partFeatures = features;
m_partLayout.append( entry );
@ -157,16 +143,16 @@ PartitionLayout::init( const QVariantList& config )
break;
}
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 ),
CalamaresUtils::getString( pentry, "size", QStringLiteral( "0" ) ),
CalamaresUtils::getString( pentry, "minSize", QStringLiteral( "0" ) ),
CalamaresUtils::getString( pentry, "maxSize", QStringLiteral( "0" ) ) ) )
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 ),
CalamaresUtils::getString( pentry, "size", QStringLiteral( "0" ) ),
CalamaresUtils::getString( pentry, "minSize", QStringLiteral( "0" ) ),
CalamaresUtils::getString( pentry, "maxSize", QStringLiteral( "0" ) ) } ) )
{
cError() << "Partition layout entry #" << config.indexOf( r ) << "is invalid, switching to default layout.";
m_partLayout.clear();
@ -176,7 +162,7 @@ PartitionLayout::init( const QVariantList& config )
if ( !m_partLayout.count() )
{
addEntry( QString( "/" ), QString( "100%" ) );
addEntry( { QString( "/" ), QString( "100%" ) } );
}
}

@ -44,8 +44,24 @@ public:
/// @brief All-zeroes PartitionEntry
PartitionEntry();
/// @brief Parse @p size, @p min and @p max to their respective member variables
PartitionEntry( const QString& size, const QString& min, const QString& max );
/// @brief Parse @p mountPoint, @p size, @p minSize and @p maxSize to their respective member variables
PartitionEntry( const QString& mountPoint,
const QString& size,
const QString& minSize = QString(),
const QString& maxSize = QString() );
/// @brief All-field PartitionEntry
PartitionEntry( const QString& label,
const QString& uuid,
const QString& type,
quint64 attributes,
const QString& mountPoint,
const QString& fs,
const QVariantMap& features,
const QString& size,
const QString& minSize = QString(),
const QString& maxSize = QString() );
/// @brief Copy PartitionEntry
PartitionEntry( const PartitionEntry& e );
bool isValid() const
{
@ -63,20 +79,7 @@ public:
~PartitionLayout();
void init( const QVariantList& config );
bool addEntry( const QString& mountPoint,
const QString& size,
const QString& min = QString(),
const QString& max = QString() );
bool addEntry( const QString& label,
const QString& uuid,
const QString& type,
quint64 attributes,
const QString& mountPoint,
const QString& fs,
const QVariantMap& features,
const QString& size,
const QString& min = QString(),
const QString& max = QString() );
bool addEntry( const PartitionEntry& entry );
/**
* @brief Apply the current partition layout to the selected drive space.

@ -154,7 +154,19 @@ defaultFileSystemType: "ext4"
# If nothing is specified, LUKS is enabled in automated modes.
#enableLuksAutomatedPartitioning: true
# To apply a custom partition layout, it has to be defined this way :
# Partition layout.
#
# This optional setting specifies a custom partition layout.
#
# If nothing is specified, the default partition layout is a single partition
# for root that uses 100% of the space and uses the filesystem defined by
# defaultFileSystemType.
#
# Note: the EFI system partition is prepend automatically to the layout if
# needed; the swap partition is appended to the layout if enabled (small of
# suspend).
#
# Otherwise, the partition layout is defined as follow:
#
# partitionLayout:
# - name: "rootfs"

@ -61,7 +61,7 @@ CreateLayoutsTests::testFixedSizePartition()
PartitionRole role( PartitionRole::Role::Any );
QList< Partition* > partitions;
if ( !layout.addEntry( QString( "/" ), QString( "5MiB" ) ) )
if ( !layout.addEntry( { QString( "/" ), QString( "5MiB" ) } ) )
{
QFAIL( qPrintable( "Unable to create / partition" ) );
}
@ -81,7 +81,7 @@ CreateLayoutsTests::testPercentSizePartition()
PartitionRole role( PartitionRole::Role::Any );
QList< Partition* > partitions;
if ( !layout.addEntry( QString( "/" ), QString( "50%" ) ) )
if ( !layout.addEntry( { QString( "/" ), QString( "50%" ) } ) )
{
QFAIL( qPrintable( "Unable to create / partition" ) );
}
@ -101,17 +101,17 @@ CreateLayoutsTests::testMixedSizePartition()
PartitionRole role( PartitionRole::Role::Any );
QList< Partition* > partitions;
if ( !layout.addEntry( QString( "/" ), QString( "5MiB" ) ) )
if ( !layout.addEntry( { QString( "/" ), QString( "5MiB" ) } ) )
{
QFAIL( qPrintable( "Unable to create / partition" ) );
}
if ( !layout.addEntry( QString( "/home" ), QString( "50%" ) ) )
if ( !layout.addEntry( { QString( "/home" ), QString( "50%" ) } ) )
{
QFAIL( qPrintable( "Unable to create /home partition" ) );
}
if ( !layout.addEntry( QString( "/bkup" ), QString( "50%" ) ) )
if ( !layout.addEntry( { QString( "/bkup" ), QString( "50%" ) } ) )
{
QFAIL( qPrintable( "Unable to create /bkup partition" ) );
}

Loading…
Cancel
Save