Allow excluding read-only devices from backend scan.

This commit is contained in:
Teo Mrnjavac 2015-07-23 16:42:09 +02:00
parent adbcfb8943
commit a683078b28
5 changed files with 20 additions and 13 deletions

View File

@ -88,7 +88,7 @@ public:
* @return a QList of pointers to Device instances. The caller is responsible * @return a QList of pointers to Device instances. The caller is responsible
* for deleting these objects. * for deleting these objects.
*/ */
virtual QList<Device*> scanDevices() = 0; virtual QList<Device*> scanDevices(bool excludeReadOnly = false) = 0;
/** /**
* Scan a single device in the system. * Scan a single device in the system.

View File

@ -45,8 +45,9 @@ void DummyBackend::initFSSupport()
{ {
} }
QList<Device*> DummyBackend::scanDevices() QList<Device*> DummyBackend::scanDevices(bool excludeReadOnly)
{ {
Q_UNUSED(excludeReadOnly)
QList<Device*> result; QList<Device*> result;
result.append(scanDevice(QStringLiteral("/dev/sda"))); result.append(scanDevice(QStringLiteral("/dev/sda")));

View File

@ -44,11 +44,11 @@ private:
public: public:
virtual void initFSSupport(); virtual void initFSSupport();
virtual QList<Device*> scanDevices(); virtual QList<Device*> scanDevices(bool excludeReadOnly = false) override;
virtual CoreBackendDevice* openDevice(const QString& device_node); virtual CoreBackendDevice* openDevice(const QString& device_node) override;
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node); virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node) override;
virtual bool closeDevice(CoreBackendDevice* core_device); virtual bool closeDevice(CoreBackendDevice* core_device) override;
virtual Device* scanDevice(const QString& device_node); virtual Device* scanDevice(const QString& device_node) override;
}; };
#endif #endif

View File

@ -407,7 +407,7 @@ Device* LibPartedBackend::scanDevice(const QString& device_node)
return d; return d;
} }
QList<Device*> LibPartedBackend::scanDevices() QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
{ {
QList<Device*> result; QList<Device*> result;
@ -421,6 +421,12 @@ QList<Device*> LibPartedBackend::scanDevices()
break; break;
if (pedDevice->type == PED_DEVICE_DM) if (pedDevice->type == PED_DEVICE_DM)
continue; continue;
if (excludeReadOnly && (
pedDevice->type == PED_DEVICE_LOOP ||
pedDevice->type == PED_DEVICE_UNKNOWN ||
pedDevice->read_only))
continue;
path.push_back(QString::fromUtf8(pedDevice->path)); path.push_back(QString::fromUtf8(pedDevice->path));
++totalDevices; ++totalDevices;
} }

View File

@ -60,11 +60,11 @@ private:
public: public:
virtual void initFSSupport(); virtual void initFSSupport();
virtual CoreBackendDevice* openDevice(const QString& device_node); virtual CoreBackendDevice* openDevice(const QString& device_node) override;
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node); virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node) override;
virtual bool closeDevice(CoreBackendDevice* core_device); virtual bool closeDevice(CoreBackendDevice* core_device) override;
virtual Device* scanDevice(const QString& device_node); virtual Device* scanDevice(const QString& device_node) override;
virtual QList<Device*> scanDevices(); virtual QList<Device*> scanDevices(bool excludeReadOnly = false) override;
static QString lastPartedExceptionMessage(); static QString lastPartedExceptionMessage();