From 0f3a6a2786e0a546ea521f8ac618f18340d123c3 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sat, 20 Nov 2021 13:08:52 +0100 Subject: [PATCH] Linux/udisks2/multi-file zip extraction: handle auto-mount better If mounting partition after FAT32 format fails, check if race occurs in which the Linux distribution was faster in auto-mounting the partition then we were in manually mounting it. --- linux/udisks2api.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ linux/udisks2api.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/linux/udisks2api.cpp b/linux/udisks2api.cpp index 3a23f32..fc4b289 100644 --- a/linux/udisks2api.cpp +++ b/linux/udisks2api.cpp @@ -160,6 +160,16 @@ bool UDisks2Api::formatDrive(const QString &device, bool mountAfterwards) qDebug() << "Mounted new file system at:" << mp; return true; } + else + { + /* Check if already auto-mounted */ + auto mps = mountPoints(filesystem); + if (!mps.isEmpty()) + { + qDebug() << "Was already auto-mounted at:" << mps; + return true; + } + } QThread::sleep(1); } @@ -207,3 +217,36 @@ void UDisks2Api::unmountDrive(const QString &device) _unmountDrive(devpath); } + +QByteArrayList UDisks2Api::mountPoints(const QString &partitionDevice) +{ + QString devpath = _resolveDevice(partitionDevice); + if (devpath.isEmpty()) + return QByteArrayList(); + + QDBusInterface filesystem("org.freedesktop.UDisks2", devpath, + "org.freedesktop.UDisks2.Filesystem", QDBusConnection::systemBus()); + return mountPoints(filesystem); +} + +QByteArrayList UDisks2Api::mountPoints(const QDBusInterface &filesystem) +{ + QByteArrayList mps; + + QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.UDisks2", filesystem.path(), + "org.freedesktop.DBus.Properties", "Get"); + QVariantList args = {"org.freedesktop.UDisks2.Filesystem", "MountPoints"}; + msg.setArguments(args); + QDBusMessage reply = QDBusConnection::systemBus().call(msg); + for (auto arg : reply.arguments()) + { + arg.value().variant().value() >> mps; + } + for (auto &str : mps) + { + if (!str.isEmpty() && str.back() == '\0') + str.chop(1); + } + + return mps; +} diff --git a/linux/udisks2api.h b/linux/udisks2api.h index e3e784b..b81e071 100644 --- a/linux/udisks2api.h +++ b/linux/udisks2api.h @@ -8,6 +8,7 @@ #include #include +#include class UDisks2Api : public QObject { @@ -18,6 +19,8 @@ public: bool formatDrive(const QString &device, bool mountAfterwards = true); QString mountDevice(const QString &device); void unmountDrive(const QString &device); + QByteArrayList mountPoints(const QString &partitionDevice); + QByteArrayList mountPoints(const QDBusInterface &filesystem); protected: QString _resolveDevice(const QString &device);