Skip to content

Commit

Permalink
Merge branch 'jb38282' into 'master'
Browse files Browse the repository at this point in the history
[nemo-qml-plugin-systemsettings] Fix systemd UnitNew and UnitRemoved of PartitionManager. Fixes JB#38282

See merge request !27
  • Loading branch information
rainemak committed Apr 7, 2017
2 parents 37caffd + 25de951 commit 2f6fb25
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/partitionmanager.cpp
Expand Up @@ -31,6 +31,7 @@

#include "partitionmanager_p.h"

#include <QDBusInterface>
#include <QFile>
#include <QRegularExpression>

Expand Down Expand Up @@ -96,6 +97,13 @@ PartitionManagerPrivate::PartitionManagerPrivate()

QDBusConnection systemBus = QDBusConnection::systemBus();

QDBusInterface systemd(systemdService,
systemdPath,
managerInterface,
systemBus);
// Subscribe to systemd signals.
systemd.call(QDBus::NoBlock, QStringLiteral("Subscribe"));

if (!systemBus.connect(
systemdService,
systemdPath,
Expand Down Expand Up @@ -355,41 +363,41 @@ void PartitionManagerPrivate::refresh(const Partitions &partitions, Partitions &
}
}

static const QString deviceNameFromSystemdService(const QString &serviceName)
static const QString mountPathFromSystemdService(const QString &serviceName)
{
// strip mount-sd@ (9) from the front, and .service (8) from the back to get the device name.
return serviceName.mid(9, serviceName.length() - 17);
// Format is like media-sdcard-3630\\x2d3563.mount
QString mountPath = serviceName;

mountPath.replace("-", "/");
mountPath.replace("\\x2d", "-");
mountPath.insert(0, "/");

// .mount (6) from the back
return mountPath.mid(0, mountPath.length() - 6);
}

void PartitionManagerPrivate::newUnit(const QString &serviceName, const QDBusObjectPath &)
{
if (!serviceName.startsWith(QStringLiteral("mount-sd@"))) {
if (!serviceName.startsWith(QStringLiteral("media-sdcard"))) {
return;
}

const QString deviceName = deviceNameFromSystemdService(serviceName);

for (auto partition : m_partitions) {
if (partition->deviceName == deviceName) {
return;
}
}

// Always refresh when an sdcard got mounted.
refresh();
}

void PartitionManagerPrivate::removedUnit(const QString &serviceName, const QDBusObjectPath &)
{
if (!serviceName.startsWith(QStringLiteral("mount-sd@"))) {
if (!serviceName.startsWith(QStringLiteral("media-sdcard"))) {
return;
}

const QString deviceName = deviceNameFromSystemdService(serviceName);
const QString mountPath = mountPathFromSystemdService(serviceName);

for (Partitions::iterator it = m_partitions.begin(); it != m_partitions.end(); ++it) {
const auto partition = *it;

if (partition->deviceName == deviceName) {
if (partition->mountPath == mountPath) {
refresh();

return;
Expand Down

0 comments on commit 2f6fb25

Please sign in to comment.