Use lsblk to detect devices.
This commit is contained in:
parent
e64a82ff19
commit
4a0b8f8efb
|
@ -1,9 +1,3 @@
|
|||
[org.kde.kpmcore.scan.scandevices]
|
||||
Name=Scan devices action
|
||||
Description=Scan available devices
|
||||
Policy=yes
|
||||
Persistence=session
|
||||
|
||||
[org.kde.kpmcore.scan.scandevice]
|
||||
Name=Scan device action
|
||||
Description=Scan device
|
||||
|
|
|
@ -19,35 +19,6 @@
|
|||
#include "core/partitiontable.h"
|
||||
#include "plugins/libparted/pedflags.h"
|
||||
|
||||
ActionReply Scan::scandevices(const QVariantMap& args)
|
||||
{
|
||||
ActionReply reply;
|
||||
|
||||
ped_device_probe_all();
|
||||
PedDevice* pedDevice = nullptr;
|
||||
QList<QVariant> paths;
|
||||
bool excludeReadOnly = args[QLatin1String("excludeReadOnly")].toBool();
|
||||
|
||||
while (true) {
|
||||
pedDevice = ped_device_get_next(pedDevice);
|
||||
if (!pedDevice)
|
||||
break;
|
||||
if (pedDevice->type == PED_DEVICE_DM)
|
||||
continue;
|
||||
if (excludeReadOnly && (
|
||||
pedDevice->type == PED_DEVICE_LOOP ||
|
||||
pedDevice->read_only))
|
||||
continue;
|
||||
|
||||
paths.append(QString::fromUtf8(pedDevice->path));
|
||||
}
|
||||
|
||||
QVariantMap returnArgs;
|
||||
returnArgs[QLatin1String("paths")] = paths;
|
||||
reply.setData(returnArgs);
|
||||
return reply;
|
||||
}
|
||||
|
||||
ActionReply Scan::scandevice(const QVariantMap& args)
|
||||
{
|
||||
ActionReply reply;
|
||||
|
|
|
@ -29,7 +29,6 @@ class Scan : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public Q_SLOTS:
|
||||
ActionReply scandevices(const QVariantMap& args);
|
||||
ActionReply scandevice(const QVariantMap& args);
|
||||
ActionReply readsectorsused(const QVariantMap& args);
|
||||
};
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "fs/luks.h"
|
||||
|
||||
#include "util/globallog.h"
|
||||
#include "util/externalcommand.h"
|
||||
#include "util/helpers.h"
|
||||
|
||||
#include <blkid/blkid.h>
|
||||
|
@ -310,26 +311,21 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode)
|
|||
QList<Device*> LibPartedBackend::scanDevices(bool excludeReadOnly)
|
||||
{
|
||||
QList<Device*> result;
|
||||
QVariantMap args;
|
||||
args[QLatin1String("excludeReadOnly")] = excludeReadOnly;
|
||||
|
||||
KAuth::Action scanAction = QStringLiteral("org.kde.kpmcore.scan.scandevices");
|
||||
scanAction.setHelperId(QStringLiteral("org.kde.kpmcore.scan"));
|
||||
scanAction.setArguments(args);
|
||||
KAuth::ExecuteJob *job = scanAction.execute();
|
||||
if (!job->exec()) {
|
||||
qWarning() << "KAuth returned an error code: " << job->errorString();
|
||||
return result;
|
||||
}
|
||||
QList<QVariant> paths = job->data()[QLatin1String("paths")].toList();
|
||||
|
||||
quint32 totalDevices = paths.size();
|
||||
ExternalCommand cmd(QStringLiteral("lsblk"), {
|
||||
QStringLiteral("--nodeps"),
|
||||
QStringLiteral("--noheadings"),
|
||||
QStringLiteral("--output"), QString::fromLatin1("name"),
|
||||
QStringLiteral("--paths"),
|
||||
QStringLiteral("--include"), excludeReadOnly ? QStringLiteral("3,8") : QStringLiteral("3,7,8") });
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QStringList devices = cmd.output().split(QString::fromLatin1("\n"));
|
||||
devices.removeLast();
|
||||
quint32 totalDevices = devices.length();
|
||||
for (quint32 i = 0; i < totalDevices; ++i) {
|
||||
QString path = paths[i].toString();
|
||||
emitScanProgress(path, i * 100 / totalDevices);
|
||||
Device* d = scanDevice(path);
|
||||
if (d)
|
||||
result.append(d);
|
||||
emitScanProgress(devices[i], i * 100 / totalDevices);
|
||||
result.append(scanDevice(devices[i]));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue