From 3cd18fd285a8e22501f3e33fa5d39beebf4f3a2b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Jul 2017 06:40:54 -0400 Subject: [PATCH] Partitions: extend getDevices() with minimum size. This is preparatory work for making the available-space check consistent with what the partition module will allow for installation. Right now, the check for available space will allow a mounted drive, even /, to satisfy the check. --- src/modules/partition/core/DeviceList.cpp | 7 ++++++- src/modules/partition/core/DeviceList.h | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/core/DeviceList.cpp b/src/modules/partition/core/DeviceList.cpp index 207306ac4..22d7e643f 100644 --- a/src/modules/partition/core/DeviceList.cpp +++ b/src/modules/partition/core/DeviceList.cpp @@ -105,7 +105,7 @@ operator <<( QDebug& s, QList< Device* >::iterator& it ) return s; } -QList< Device* > getDevices( DeviceType which ) +QList< Device* > getDevices( DeviceType which, qint64 minimumSize ) { bool writableOnly = (which == DeviceType::WritableOnly); @@ -135,6 +135,11 @@ QList< Device* > getDevices( DeviceType which ) cDebug() << " .. Removing" << it; it = devices.erase( it ); } + else if ( (minimumSize >= 0) && !( (*it)->capacity() > minimumSize ) ) + { + cDebug() << " .. Removing too-small" << it; + it = devices.erase( it ); + } else ++it; diff --git a/src/modules/partition/core/DeviceList.h b/src/modules/partition/core/DeviceList.h index 6871f7fc9..6da34c5d1 100644 --- a/src/modules/partition/core/DeviceList.h +++ b/src/modules/partition/core/DeviceList.h @@ -36,9 +36,12 @@ enum class DeviceType { All, WritableOnly }; * the system, filtering out those that do not meet a criterium. * If set to WritableOnly, only devices which can be overwritten * safely are returned (e.g. RO-media are ignored, as are mounted partitions). + * @param minimumSize Can be used to filter devices based on their + * size (in bytes). If non-negative, only devices with a size + * greater than @p minimumSize will be returned. * @return a list of Devices meeting this criterium. */ -QList< Device* > getDevices( DeviceType which = DeviceType::All ); +QList< Device* > getDevices( DeviceType which = DeviceType::All, qint64 minimumSize = -1 ); }