From f4a10a313cdb08b3ebadd7b12ef853a082986aa3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 18 Mar 2022 14:35:35 +0100 Subject: [PATCH] [partition] Address default-labeling issues --- CHANGES-3.2 | 2 +- .../partition/core/PartitionCoreModule.cpp | 38 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/CHANGES-3.2 b/CHANGES-3.2 index bd281d8fe..55f964723 100644 --- a/CHANGES-3.2 +++ b/CHANGES-3.2 @@ -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) # diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 8d74444d1..f7d1e8278 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -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(