From aedb55ea36ed85060e437014ba5ce12f876aae99 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 21 Mar 2022 23:44:20 +0100 Subject: [PATCH] [partition] Require modern KPMCore --- CMakeModules/KPMcoreHelper.cmake | 14 +---------- src/libcalamares/partition/Global.h | 7 +----- src/libcalamares/partition/KPMManager.cpp | 24 +------------------ src/libcalamares/partition/KPMTests.cpp | 8 ------- src/libcalamares/partition/PartitionQuery.cpp | 7 +----- src/modules/fsresizer/ResizeFSJob.cpp | 4 ---- src/modules/partition/PartitionViewStep.cpp | 7 +----- src/modules/partition/core/DeviceList.cpp | 4 ---- src/modules/partition/core/KPMHelpers.h | 7 +----- src/modules/partition/core/PartUtils.cpp | 24 ------------------- .../partition/core/PartitionCoreModule.cpp | 7 ------ .../partition/core/PartitionLayout.cpp | 16 ------------- src/modules/partition/gui/ChoicePage.cpp | 4 ---- .../partition/gui/DeviceInfoWidget.cpp | 2 -- src/modules/partition/gui/PartitionPage.cpp | 4 ---- .../partition/jobs/CreatePartitionJob.cpp | 4 ---- .../partition/jobs/FillGlobalStorageJob.cpp | 2 -- .../partition/tests/CreateLayoutsTests.cpp | 7 ------ src/modules/partition/tests/DevicesTests.cpp | 7 +----- 19 files changed, 7 insertions(+), 152 deletions(-) diff --git a/CMakeModules/KPMcoreHelper.cmake b/CMakeModules/KPMcoreHelper.cmake index 6aacfc95c..05dff18dd 100644 --- a/CMakeModules/KPMcoreHelper.cmake +++ b/CMakeModules/KPMcoreHelper.cmake @@ -10,7 +10,7 @@ if ( NOT KPMcore_searched_for ) set( KPMcore_searched_for TRUE ) - find_package( KPMcore 3.3 ) + find_package( KPMcore 21.12.0 ) set_package_properties( KPMcore PROPERTIES URL "https://invent.kde.org/kde/kpmcore" @@ -21,18 +21,6 @@ if ( NOT KPMcore_searched_for ) if( KPMcore_FOUND ) set( KPMcore_API_DEFINITIONS "" ) - if( KPMcore_VERSION VERSION_GREATER "3.3.70" AND KPMcore_VERSION VERSION_LESS "4.0" ) - message( FATAL_ERROR "KPMCore beta versions ${KPMcore_VERSION} not supported" ) - endif() - if ( KPMcore_VERSION VERSION_GREATER "3.3.0") - list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations - endif() - if ( KPMcore_VERSION VERSION_GREATER_EQUAL "4.0") - list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE4API) # kpmcore 4 with new API - endif() - if( KPMcore_VERSION VERSION_GREATER_EQUAL "4.2" ) - list( APPEND KPMcore_API_DEFINITIONS WITH_KPMCORE42API) # kpmcore 4.2 with new API - endif() else() set( KPMcore_API_DEFINITIONS WITHOUT_KPMcore ) endif() diff --git a/src/libcalamares/partition/Global.h b/src/libcalamares/partition/Global.h index 733e2f69c..b76c74c58 100644 --- a/src/libcalamares/partition/Global.h +++ b/src/libcalamares/partition/Global.h @@ -17,13 +17,10 @@ #define PARTITION_GLOBAL_H #include "DllMacro.h" +#include "FileSystem.h" #include "JobQueue.h" -#ifdef WITH_KPMCORE4API -#include "FileSystem.h" - #include -#endif namespace CalamaresUtils { @@ -78,7 +75,6 @@ isFilesystemUsedGS( const QString& filesystemType ) return isFilesystemUsedGS( Calamares::JobQueue::instanceGlobalStorage(), filesystemType ); } -#ifdef WITH_KPMCORE4API /** @brief Mark a particular filesystem type as used (or not) * * See useFilesystemGS(const QString&, bool); this method uses the filesystem type @@ -100,7 +96,6 @@ isFilesystemUsedGS( FileSystem::Type filesystem ) return isFilesystemUsedGS( untranslatedFS( filesystem ) ); } -#endif } // namespace Partition } // namespace CalamaresUtils diff --git a/src/libcalamares/partition/KPMManager.cpp b/src/libcalamares/partition/KPMManager.cpp index ff7701703..7220b6151 100644 --- a/src/libcalamares/partition/KPMManager.cpp +++ b/src/libcalamares/partition/KPMManager.cpp @@ -14,10 +14,7 @@ #include #include -#if defined( WITH_KPMCORE4API ) #include -#endif - #include @@ -30,7 +27,6 @@ class InternalManager { public: InternalManager(); - ~InternalManager(); }; static bool s_kpm_loaded = false; @@ -69,22 +65,6 @@ InternalManager::InternalManager() } } -InternalManager::~InternalManager() -{ -#if defined( WITH_KPMCORE4API ) && !defined( WITH_KPMCORE42API ) - cDebug() << "Cleaning up KPMCore backend .."; - - // From KPMcore 4.0 until KPMcore 4.2 we needed to stop - // the helper by hand. KPMcore 4.2 ported to polkit directly, - // which doesn't need a helper. - auto backend_p = CoreBackendManager::self()->backend(); - if ( backend_p ) - { - ExternalCommand::stopHelper(); - } -#endif -} - std::shared_ptr< InternalManager > getInternal() { @@ -102,9 +82,7 @@ KPMManager::KPMManager() { } -KPMManager::~KPMManager() -{ -} +KPMManager::~KPMManager() {} KPMManager::operator bool() const { diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp index 3834b7913..2f828f772 100644 --- a/src/libcalamares/partition/KPMTests.cpp +++ b/src/libcalamares/partition/KPMTests.cpp @@ -57,18 +57,10 @@ KPMTests::testFlagNames() QCOMPARE( PartitionTable::flagName( static_cast< PartitionTable::Flag >( 1 ) ), QStringLiteral( "boot" ) ); -#ifdef WITH_KPMCORE4API // KPMCore 4 unifies the flags and handles them internally QCOMPARE( PartitionTable::flagName( PartitionTable::Flag::Boot ), QStringLiteral( "boot" ) ); QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); QVERIFY( !names.contains( QStringLiteral( "esp" ) ) ); -#else - // KPMCore 3 has separate flags - QCOMPARE( PartitionTable::flagName( PartitionTable::FlagBoot ), QStringLiteral( "boot" ) ); - QCOMPARE( PartitionTable::flagName( PartitionTable::FlagEsp ), QStringLiteral( "esp" ) ); - QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); - QVERIFY( names.contains( QStringLiteral( "esp" ) ) ); -#endif } void diff --git a/src/libcalamares/partition/PartitionQuery.cpp b/src/libcalamares/partition/PartitionQuery.cpp index 0356f920c..4d54215f3 100644 --- a/src/libcalamares/partition/PartitionQuery.cpp +++ b/src/libcalamares/partition/PartitionQuery.cpp @@ -50,12 +50,7 @@ isPartitionFreeSpace( const Partition* partition ) bool isPartitionNew( const Partition* partition ) { -#if defined( WITH_KPMCORE4API ) - constexpr auto NewState = Partition::State::New; -#else - constexpr auto NewState = Partition::StateNew; -#endif - return partition->state() == NewState; + return partition->state() == Partition::State::New; } diff --git a/src/modules/fsresizer/ResizeFSJob.cpp b/src/modules/fsresizer/ResizeFSJob.cpp index f972b9fa4..562644594 100644 --- a/src/modules/fsresizer/ResizeFSJob.cpp +++ b/src/modules/fsresizer/ResizeFSJob.cpp @@ -49,12 +49,8 @@ ResizeFSJob::PartitionMatch ResizeFSJob::findPartition() { using DeviceList = QList< Device* >; -#if defined( WITH_KPMCORE4API ) DeviceList devices = m_kpmcore.backend()->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) ); -#else - DeviceList devices = m_kpmcore.backend()->scanDevices( /* excludeReadOnly */ true ); -#endif cDebug() << "ResizeFSJob found" << devices.count() << "devices."; for ( DeviceList::iterator dev_it = devices.begin(); dev_it != devices.end(); ++dev_it ) diff --git a/src/modules/partition/PartitionViewStep.cpp b/src/modules/partition/PartitionViewStep.cpp index a2c0bd711..fe77bee3a 100644 --- a/src/modules/partition/PartitionViewStep.cpp +++ b/src/modules/partition/PartitionViewStep.cpp @@ -508,11 +508,6 @@ PartitionViewStep::onLeave() { const QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); -#ifdef WITH_KPMCORE4API - const auto espFlag = PartitionTable::Flag::Boot; -#else - const auto espFlag = PartitionTable::FlagEsp; -#endif Partition* esp = m_core->findPartitionByMountPoint( espMountPoint ); QString message; @@ -567,7 +562,7 @@ PartitionViewStep::onLeave() cDebug() << o << "ESP missing flag"; description.append( ' ' ); description.append( tr( "The filesystem must have flag %1 set." ) - .arg( PartitionTable::flagName( espFlag ) ) ); + .arg( PartitionTable::flagName( PartitionTable::Flag::Boot ) ) ); } if ( !description.isEmpty() ) { diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index b3a10dde7..321827876 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -127,11 +127,7 @@ getDevices( DeviceType which ) cWarning() << "No KPM backend found."; return {}; } -#if defined( WITH_KPMCORE4API ) DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) ); -#else - DeviceList devices = backend->scanDevices( /* excludeReadOnly */ true ); -#endif /* The list of devices is cleaned up for use: * - some devices can **never** be used (e.g. floppies, nullptr) diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 2f867bc25..5648e6171 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -27,15 +27,10 @@ class Partition; class PartitionNode; class PartitionRole; -#if defined( WITH_KPMCORE4API ) +// TODO:3.3: Remove defines, expand in-place #define KPM_PARTITION_FLAG( x ) PartitionTable::Flag::x #define KPM_PARTITION_STATE( x ) Partition::State::x #define KPM_PARTITION_FLAG_ESP PartitionTable::Flag::Boot -#else -#define KPM_PARTITION_FLAG( x ) PartitionTable::Flag##x -#define KPM_PARTITION_STATE( x ) Partition::State##x -#define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp -#endif /** * Helper functions to manipulate partitions diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index a4ec7fe0b..3d5e1e762 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -457,9 +457,7 @@ isEfiFilesystemSuitableType( const Partition* candidate ) { case FileSystem::Type::Fat32: return true; -#ifdef WITH_KPMCORE4API case FileSystem::Type::Fat12: -#endif case FileSystem::Type::Fat16: cWarning() << "FAT12 and FAT16 are probably not supported by EFI"; return false; @@ -496,31 +494,9 @@ isEfiBootable( const Partition* candidate ) { const auto flags = PartitionInfo::flags( candidate ); -#if defined( WITH_KPMCORE4API ) // In KPMCore4, the flags are remapped, and the ESP flag is the same as Boot. static_assert( KPM_PARTITION_FLAG_ESP == KPM_PARTITION_FLAG( Boot ), "KPMCore API enum changed" ); return flags.testFlag( KPM_PARTITION_FLAG_ESP ); -#else - // In KPMCore3, bit 17 is the old-style Esp flag, and it's OK - if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) ) - { - return true; - } - - /* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */ - const PartitionTable* table = CalamaresUtils::Partition::getPartitionTable( candidate ); - if ( !table ) - { - cWarning() << "Root of partition table is not a PartitionTable object"; - return false; - } - if ( table->type() == PartitionTable::TableType::gpt ) - { - const auto bootFlag = KPM_PARTITION_FLAG( Boot ); - return flags.testFlag( bootFlag ); - } - return false; -#endif } // TODO: this is configurable via the config file **already** diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 2040a2658..78af2abf7 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -847,13 +847,8 @@ PartitionCoreModule::scanForLVMPVs() } } -#if defined( WITH_KPMCORE4API ) VolumeManagerDevice::scanDevices( physicalDevices ); for ( auto p : LVM::pvList::list() ) -#else - LvmDevice::scanSystemLVM( physicalDevices ); - for ( auto p : LVM::pvList ) -#endif { m_lvmPVs << p.partition().data(); @@ -890,7 +885,6 @@ PartitionCoreModule::scanForLVMPVs() m_lvmPVs << p; } } -#if defined( WITH_KPMCORE4API ) else if ( p->fileSystem().type() == FileSystem::Type::Luks2 ) { // Encrypted LVM PVs @@ -901,7 +895,6 @@ PartitionCoreModule::scanForLVMPVs() m_lvmPVs << p; } } -#endif } } } diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 765d9fffa..a8aae61ff 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -154,11 +154,9 @@ PartitionLayout::setDefaultFsType( FileSystem::Type defaultFsType ) case FileSystem::Lvm2_PV: case FileSystem::Udf: case FileSystem::Iso9660: -#ifdef WITH_KPMCORE4API case FileSystem::Luks2: case FileSystem::LinuxRaidMember: case FileSystem::BitLocker: -#endif // bad bad cWarning() << "The selected default FS" << defaultFsType << "is not suitable." << "Using ext4 instead."; @@ -185,11 +183,9 @@ PartitionLayout::setDefaultFsType( FileSystem::Type defaultFsType ) case FileSystem::Hpfs: case FileSystem::Zfs: case FileSystem::Nilfs2: -#ifdef WITH_KPMCORE4API case FileSystem::Fat12: case FileSystem::Apfs: case FileSystem::Minix: -#endif // weird cWarning() << "The selected default FS" << defaultFsType << "is unusual, but not wrong."; break; @@ -355,30 +351,18 @@ PartitionLayout::createPartitions( Device* dev, } if ( !entry.partType.isEmpty() ) { -#if defined( WITH_KPMCORE42API ) part->setType( entry.partType ); -#else - cWarning() << "Ignoring type; requires KPMcore >= 4.2.0."; -#endif } if ( entry.partAttributes ) { -#if defined( WITH_KPMCORE42API ) part->setAttributes( entry.partAttributes ); -#else - cWarning() << "Ignoring attributes; requires KPMcore >= 4.2.0."; -#endif } if ( !entry.partFeatures.isEmpty() ) { -#if defined( WITH_KPMCORE42API ) for ( const auto& k : entry.partFeatures.keys() ) { part->fileSystem().addFeature( k, entry.partFeatures.value( k ) ); } -#else - cWarning() << "Ignoring features; requires KPMcore >= 4.2.0."; -#endif } // Some buggy (legacy) BIOSes test if the bootflag of at least one partition is set. // Otherwise they ignore the device in boot-order, so add it here. diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index c0845da7f..2d395764d 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -42,9 +42,7 @@ #include "widgets/PrettyRadioButton.h" #include -#ifdef WITH_KPMCORE4API #include -#endif #include #include @@ -1344,14 +1342,12 @@ ChoicePage::setupActions() bool isInactiveRAID = false; bool matchTableType = false; -#ifdef WITH_KPMCORE4API if ( currentDevice->type() == Device::Type::SoftwareRAID_Device && static_cast< SoftwareRAID* >( currentDevice )->status() == SoftwareRAID::Status::Inactive ) { cDebug() << Logger::SubEntry << "part of an inactive RAID device"; isInactiveRAID = true; } -#endif PartitionTable::TableType tableType = PartitionTable::unknownTableType; if ( currentDevice->partitionTable() ) diff --git a/src/modules/partition/gui/DeviceInfoWidget.cpp b/src/modules/partition/gui/DeviceInfoWidget.cpp index 39d9413e1..05a8c4b63 100644 --- a/src/modules/partition/gui/DeviceInfoWidget.cpp +++ b/src/modules/partition/gui/DeviceInfoWidget.cpp @@ -100,9 +100,7 @@ DeviceInfoWidget::retranslateUi() "that makes a file accessible as a block device. " "This kind of setup usually only contains a single filesystem." ); break; -#if defined( WITH_KPMCORE42API ) case PartitionTable::none: -#endif case PartitionTable::unknownTableType: typeString = " ? "; toolTipString = tr( "This installer cannot detect a partition table on the " diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 0b3cf2478..25e6a27ab 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -42,9 +42,7 @@ // KPMcore #include #include -#ifdef WITH_KPMCORE4API #include -#endif #include #include @@ -179,14 +177,12 @@ PartitionPage::updateButtons() { allow_create_table = true; -#ifdef WITH_KPMCORE4API if ( device->type() == Device::Type::SoftwareRAID_Device && static_cast< SoftwareRAID* >( device )->status() == SoftwareRAID::Status::Inactive ) { allow_create_table = false; allow_create = false; } -#endif } else { diff --git a/src/modules/partition/jobs/CreatePartitionJob.cpp b/src/modules/partition/jobs/CreatePartitionJob.cpp index fe7c6f350..19a04a2de 100644 --- a/src/modules/partition/jobs/CreatePartitionJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionJob.cpp @@ -111,7 +111,6 @@ CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition ) static QString prettyGptType( const Partition* partition ) { -#ifdef WITH_KPMCORE42API static const QMap< QString, QString > gptTypePrettyStrings = { { "44479540-f297-41b2-9af7-d131d5f0458a", "Linux Root Partition (x86)" }, { "4f68bce3-e8cd-4db1-96e7-fbcaf984b709", "Linux Root Partition (x86-64)" }, @@ -146,9 +145,6 @@ prettyGptType( const Partition* partition ) auto type = partition->type(); return gptTypePrettyStrings.value( type.toLower(), type ); -#else - return QString(); -#endif } static QString diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 5be353113..d734485f0 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -88,11 +88,9 @@ mapForPartition( Partition* partition, const QString& uuid ) map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); map[ "fsName" ] = userVisibleFS( partition->fileSystem() ); map[ "fs" ] = untranslatedFS( partition->fileSystem() ); -#ifdef WITH_KPMCORE42API map[ "parttype" ] = partition->type(); map[ "partattrs" ] = partition->attributes(); map[ "features" ] = partition->fileSystem().features(); -#endif if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) { diff --git a/src/modules/partition/tests/CreateLayoutsTests.cpp b/src/modules/partition/tests/CreateLayoutsTests.cpp index 68b839e08..b83f71a26 100644 --- a/src/modules/partition/tests/CreateLayoutsTests.cpp +++ b/src/modules/partition/tests/CreateLayoutsTests.cpp @@ -125,7 +125,6 @@ CreateLayoutsTests::testMixedSizePartition() QCOMPARE( partitions[ 2 ]->length(), ( ( 5_GiB - 5_MiB ) / 2 ) / LOGICAL_SIZE ); } -#ifdef WITH_KPMCORE4API // TODO: Get a clean way to instantiate a test Device from KPMCore class DevicePrivate { @@ -150,11 +149,5 @@ TestDevice::TestDevice( const QString& name, const qint64 logicalSectorSize, con Device::Type::Unknown_Device ) { } -#else -TestDevice::TestDevice( const QString& name, const qint64 logicalSectorSize, const qint64 totalLogicalSectors ) - : Device( name, QString( "node" ), logicalSectorSize, totalLogicalSectors, QString(), Device::Type::Unknown_Device ) -{ -} -#endif TestDevice::~TestDevice() {} diff --git a/src/modules/partition/tests/DevicesTests.cpp b/src/modules/partition/tests/DevicesTests.cpp index c63d7476d..ec6bdadff 100644 --- a/src/modules/partition/tests/DevicesTests.cpp +++ b/src/modules/partition/tests/DevicesTests.cpp @@ -52,12 +52,7 @@ DevicesTests::testKPMScanDevices() cDebug() << "Getting devices via KPMCore"; CoreBackend* backend = CoreBackendManager::self()->backend(); QVERIFY( backend ); -#if defined( WITH_KPMCORE4API ) - auto flags = ScanFlag( ~0 ); -#else - auto flags = true; -#endif - auto devices = backend->scanDevices( flags ); // These flags try to get "all" + auto devices = backend->scanDevices( ScanFlag( ~0 ) ); // These flags try to get "all" cDebug() << Logger::SubEntry << "Done getting devices."; if ( !m_isRoot )