Commit f4e7a1b8 authored by Kwon-Young Choi's avatar Kwon-Young Choi

Autmatically unmount mounted directory when deleting loop device

When deleting a loop device, all mounts depending on this loop device
should be unmounted before deletion.
This patch uses Solid to get all StorageAccess devices linked to the loop
device to delete and unmounts them if needed before the loop devie
deletion.

BUG: 422082
parent 68acdc34
......@@ -74,7 +74,7 @@ MountIsoAction::MountIsoAction(QObject *parent, const QVariantList &)
* @return: device udi of the found block device. If no corresponding device
* was found, return a null QString.
*/
const QString getDeviceFromBackingFile(const QString &backingFile)
const Solid::Device getDeviceFromBackingFile(const QString &backingFile)
{
const QList<Solid::Device> blockDevices =
Solid::Device::listFromQuery("[ IS Block AND IS GenericInterface ]");
......@@ -83,10 +83,18 @@ const QString getDeviceFromBackingFile(const QString &backingFile)
QMap<QString, QVariant> properties = device.as<Solid::GenericInterface>()->allProperties();
if (properties.contains("BackingFile")
&& backingFile == properties["BackingFile"].value<QString>()) {
return device.udi();
return device;
}
}
return QString();
return Solid::Device();
}
const QList<Solid::Device> getStorageAccessFromDevice(const Solid::Device &device)
{
auto genericInterface = device.as<Solid::GenericInterface>();
const QString uuid = genericInterface->property(QLatin1String("IdUUID")).value<QString>();
auto query = QString("[ StorageVolume.uuid == '%1' AND IS StorageAccess ]").arg(uuid);
return Solid::Device::listFromQuery(query);
}
/**
......@@ -174,14 +182,21 @@ void mount(const QString &file)
*
* @file: iso file to mount
*/
void unmount(const QString &device)
void unmount(const Solid::Device &device)
{
for (Solid::Device storageAccessDevice : getStorageAccessFromDevice(device)) {
auto storageAccess = storageAccessDevice.as<Solid::StorageAccess>();
if (storageAccess->isAccessible()) {
storageAccess->teardown();
}
}
// Empty argument required for Loop Delete method to work
QMap<QString, QVariant> options;
QDBusInterface manager(
"org.freedesktop.UDisks2",
device,
device.udi(),
"org.freedesktop.UDisks2.Loop",
QDBusConnection::systemBus());
manager.call("Delete", options);
......@@ -205,9 +220,9 @@ QList<QAction *> MountIsoAction::actions(const KFileItemListProperties &fileItem
return {};
}
const QString device = getDeviceFromBackingFile(file);
const Solid::Device device = getDeviceFromBackingFile(file);
if (device.isEmpty()) {
if (!device.isValid()) {
const QIcon icon = QIcon::fromTheme(QStringLiteral("media-mount"));
const QString title = i18nc("@action:inmenu Action to mount an ISO image", "Mount ISO");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment