[partition] Migrate the defaultFS type

- remove the m_defaultFSType from PartitionLayout, because it is
  set on construction -- which is too early, before the configuration
  has been read.
- make the default FS explicit in the init() calls which pass in
  a configuration; this needs support in the intermediate
  PartitionCoreModule.
This commit is contained in:
Adriaan de Groot 2020-11-02 21:35:43 +01:00
parent 42014a8201
commit 73b5a0898d
5 changed files with 44 additions and 40 deletions

View file

@ -27,32 +27,10 @@
#include <kpmcore/core/partition.h>
#include <kpmcore/fs/filesystem.h>
static FileSystem::Type
getDefaultFileSystemType()
{
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
FileSystem::Type defaultFS = FileSystem::Ext4;
if ( gs->contains( "defaultFileSystemType" ) )
{
PartUtils::findFS( gs->value( "defaultFileSystemType" ).toString(), &defaultFS );
if ( defaultFS == FileSystem::Unknown )
{
defaultFS = FileSystem::Ext4;
}
}
return defaultFS;
}
PartitionLayout::PartitionLayout()
: m_defaultFsType( getDefaultFileSystemType() )
{
}
PartitionLayout::PartitionLayout() {}
PartitionLayout::PartitionLayout( const PartitionLayout& layout )
: m_defaultFsType( layout.m_defaultFsType )
, m_partLayout( layout.m_partLayout )
: m_partLayout( layout.m_partLayout )
{
}
@ -63,7 +41,11 @@ PartitionLayout::PartitionEntry::PartitionEntry()
{
}
PartitionLayout::PartitionEntry::PartitionEntry( FileSystem::Type type, const QString& mountPoint, const QString& size, const QString& minSize, const QString& maxSize )
PartitionLayout::PartitionEntry::PartitionEntry( FileSystem::Type type,
const QString& mountPoint,
const QString& size,
const QString& minSize,
const QString& maxSize )
: partType( type )
, partAttributes( 0 )
, partMountPoint( mountPoint )
@ -111,7 +93,7 @@ PartitionLayout::addEntry( const PartitionEntry& entry )
}
void
PartitionLayout::init( const QVariantList& config )
PartitionLayout::init( FileSystem::Type defaultFsType, const QVariantList& config )
{
bool ok;
@ -149,7 +131,7 @@ PartitionLayout::init( const QVariantList& config )
if ( !m_partLayout.count() )
{
addEntry( { m_defaultFsType, QString( "/" ), QString( "100%" ) } );
addEntry( { defaultFsType, QString( "/" ), QString( "100%" ) } );
}
}
@ -215,8 +197,8 @@ PartitionLayout::createPartitions( Device* dev,
{
if ( entry.partSize.unit() == CalamaresUtils::Partition::SizeUnit::Percent )
{
qint64 sectors = entry.partSize.toSectors( availableSectors + partSectorsMap.value( &entry ),
dev->logicalSize() );
qint64 sectors
= entry.partSize.toSectors( availableSectors + partSectorsMap.value( &entry ), dev->logicalSize() );
if ( entry.partMinSize.isValid() )
{
sectors = std::max( sectors, entry.partMinSize.toSectors( totalSectors, dev->logicalSize() ) );
@ -245,13 +227,24 @@ PartitionLayout::createPartitions( Device* dev,
Partition* part = nullptr;
if ( luksPassphrase.isEmpty() )
{
part = KPMHelpers::createNewPartition(
parent, *dev, role, entry.partFileSystem, currentSector, currentSector + sectors - 1, KPM_PARTITION_FLAG( None ) );
part = KPMHelpers::createNewPartition( parent,
*dev,
role,
entry.partFileSystem,
currentSector,
currentSector + sectors - 1,
KPM_PARTITION_FLAG( None ) );
}
else
{
part = KPMHelpers::createNewEncryptedPartition(
parent, *dev, role, entry.partFileSystem, currentSector, currentSector + sectors - 1, luksPassphrase, KPM_PARTITION_FLAG( None ) );
part = KPMHelpers::createNewEncryptedPartition( parent,
*dev,
role,
entry.partFileSystem,
currentSector,
currentSector + sectors - 1,
luksPassphrase,
KPM_PARTITION_FLAG( None ) );
}
PartitionInfo::setFormat( part, true );
PartitionInfo::setMountPoint( part, entry.partMountPoint );