From 4912de589384f82e43db52943ec82b6a0063b698 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 9 Apr 2021 13:32:48 +0200 Subject: [PATCH] [partition] reduce warnings with unsafe-option - Move variables closer to where they are needed - Do the winnowing / selection always, but in unsafe mode return the un-winnowed list of devices - Massage build documentation a little --- src/modules/partition/CMakeLists.txt | 5 +++-- src/modules/partition/core/DeviceList.cpp | 16 +++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 07f1eaf5d..bffb2128c 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -8,8 +8,9 @@ # want to allow unsafe partitioning choices (e.g. doing things to the # current disk). Set DEBUG_PARTITION_UNSAFE to allow that (it turns off # some filtering of devices). If you **do** allow unsafe partitioning, -# it will error out unless you **also** switch **off** DEBUG_PARTITION_LAME, -# at which point you are welcome to shoot yourself in the foot. +# it will error out at runtime unless you **also** switch **off** +# DEBUG_PARTITION_LAME, at which point you are welcome to shoot +# yourself in the foot. option( DEBUG_PARTITION_UNSAFE "Allow unsafe partitioning choices." OFF ) option( DEBUG_PARTITION_LAME "Unsafe partitioning will error out on exec." ON ) diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index 2fce62e9d..395b6b484 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -118,8 +118,6 @@ erase( DeviceList& l, DeviceList::iterator& it ) QList< Device* > getDevices( DeviceType which ) { - bool writableOnly = ( which == DeviceType::WritableOnly ); - CoreBackend* backend = CoreBackendManager::self()->backend(); #if defined( WITH_KPMCORE4API ) DeviceList devices = backend->scanDevices( /* not includeReadOnly, not includeLoopback */ ScanFlag( 0 ) ); @@ -129,14 +127,18 @@ getDevices( DeviceType which ) #ifdef DEBUG_PARTITION_UNSAFE cWarning() << "Allowing unsafe partitioning choices." << devices.count() << "candidates."; + DeviceList unsafeDevices = devices; #ifdef DEBUG_PARTITION_LAME cDebug() << Logger::SubEntry << "it has been lamed, and will fail."; #endif -#else +#endif + cDebug() << "Removing unsuitable devices:" << devices.count() << "candidates."; + bool writableOnly = ( which == DeviceType::WritableOnly ); // Remove the device which contains / from the list for ( DeviceList::iterator it = devices.begin(); it != devices.end(); ) + { if ( !( *it ) ) { cDebug() << Logger::SubEntry << "Skipping nullptr device"; @@ -166,9 +168,13 @@ getDevices( DeviceType which ) { ++it; } -#endif - + } + cDebug() << Logger::SubEntry << "there are" << devices.count() << "devices left."; +#ifdef DEBUG_PARTITION_UNSAFE + return unsafeDevices; +#else return devices; +#endif } } // namespace PartUtils