[partition] Address default-labeling issues
This commit is contained in:
parent
7d89643146
commit
f4a10a313c
@ -23,7 +23,7 @@ This release contains contributions from (alphabetically by name):
|
||||
## Modules ##
|
||||
- *fstab* module correctly handles empty UUID strings. (Thanks Evan)
|
||||
- *partition* module no longer forgets configured partition-layouts.
|
||||
(Thanks Santosh)
|
||||
It also respects configured partition labels better. (Thanks Santosh)
|
||||
|
||||
|
||||
# 3.2.53 (2022-03-04) #
|
||||
|
@ -941,6 +941,15 @@ PartitionCoreModule::setBootLoaderInstallPath( const QString& path )
|
||||
m_bootLoaderInstallPath = path;
|
||||
}
|
||||
|
||||
static void
|
||||
applyDefaultLabel( Partition* p, bool ( *predicate )( const Partition* ), const QString& label )
|
||||
{
|
||||
if ( p->label().isEmpty() && predicate( p ) )
|
||||
{
|
||||
p->setLabel( label );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PartitionCoreModule::layoutApply( Device* dev,
|
||||
qint64 firstSector,
|
||||
@ -957,25 +966,28 @@ PartitionCoreModule::layoutApply( Device* dev,
|
||||
// PartitionInfo::mountPoint() says where it will be mounted in the target system.
|
||||
// .. the latter is more interesting.
|
||||
//
|
||||
// If we have a separate /boot, mark that one as bootable, otherwise mark
|
||||
// the root / as bootable.
|
||||
// If we have a separate /boot, mark that one as bootable,
|
||||
// otherwise mark the root / as bootable.
|
||||
//
|
||||
// TODO: perhaps the partition that holds the bootloader?
|
||||
const QString boot = QStringLiteral( "/boot" );
|
||||
const QString root = QStringLiteral( "/" );
|
||||
const auto is_boot
|
||||
= [ & ]( Partition* p ) -> bool { return PartitionInfo::mountPoint( p ) == boot || p->mountPoint() == boot; };
|
||||
const auto is_root
|
||||
= [ & ]( Partition* p ) -> bool { return PartitionInfo::mountPoint( p ) == root || p->mountPoint() == root; };
|
||||
// If the layout hasn't applied a label to the partition,
|
||||
// apply a default label (to boot and root, at least).
|
||||
const auto is_boot = []( const Partition* p ) -> bool
|
||||
{
|
||||
const QString boot = QStringLiteral( "/boot" );
|
||||
return PartitionInfo::mountPoint( p ) == boot || p->mountPoint() == boot;
|
||||
};
|
||||
const auto is_root = []( const Partition* p ) -> bool
|
||||
{
|
||||
const QString root = QStringLiteral( "/" );
|
||||
return PartitionInfo::mountPoint( p ) == root || p->mountPoint() == root;
|
||||
};
|
||||
|
||||
const bool separate_boot_partition
|
||||
= std::find_if( partList.constBegin(), partList.constEnd(), is_boot ) != partList.constEnd();
|
||||
for ( Partition* part : partList )
|
||||
{
|
||||
if ( is_boot( part ) )
|
||||
{
|
||||
part->setLabel( "boot" );
|
||||
}
|
||||
applyDefaultLabel( part, is_root, QStringLiteral( "root" ) );
|
||||
applyDefaultLabel( part, is_boot, QStringLiteral( "boot" ) );
|
||||
if ( ( separate_boot_partition && is_boot( part ) ) || ( !separate_boot_partition && is_root( part ) ) )
|
||||
{
|
||||
createPartition(
|
||||
|
Loading…
Reference in New Issue
Block a user