[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
This commit is contained in:
Adriaan de Groot 2021-04-09 13:32:48 +02:00
parent 7a26143fbc
commit 4912de5893
2 changed files with 14 additions and 7 deletions

View File

@ -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 )

View File

@ -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