mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
solid: use KMountPoint to lookup the device mount points
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
ef89940958
commit
5ff9befa1e
1 changed files with 6 additions and 44 deletions
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "udevstorageaccess.h"
|
#include "udevstorageaccess.h"
|
||||||
#include "kstandarddirs.h"
|
#include "kstandarddirs.h"
|
||||||
|
#include "kmountpoint.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -47,56 +48,17 @@ StorageAccess::~StorageAccess()
|
||||||
|
|
||||||
bool StorageAccess::isAccessible() const
|
bool StorageAccess::isAccessible() const
|
||||||
{
|
{
|
||||||
QFile mounts("/proc/mounts");
|
return !filePath().isEmpty();
|
||||||
if (!mounts.open(QFile::ReadOnly)) {
|
|
||||||
qWarning() << "cannot open /proc/mounts";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString devpath = m_device->property("DEVNAME").toString();
|
|
||||||
const QString uuidpath = QLatin1String("/dev/disk/by-uuid/") + m_device->property("ID_FS_UUID").toString();
|
|
||||||
const QString labelpath = QLatin1String("/dev/disk/by-label/") + m_device->property("ID_FS_LABEL").toString();
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const QString line = mounts.readLine();
|
|
||||||
const QString deviceentry = line.split(" ").at(0);
|
|
||||||
|
|
||||||
if (deviceentry == devpath || deviceentry == uuidpath || deviceentry == labelpath) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mounts.atEnd()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString StorageAccess::filePath() const
|
QString StorageAccess::filePath() const
|
||||||
{
|
{
|
||||||
QFile mounts("/proc/mounts");
|
|
||||||
if (!mounts.open(QFile::ReadOnly)) {
|
|
||||||
qWarning() << "cannot open /proc/mounts";
|
|
||||||
return QString();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString devpath = m_device->property("DEVNAME").toString();
|
const QString devpath = m_device->property("DEVNAME").toString();
|
||||||
const QString uuidpath = QLatin1String("/dev/disk/by-uuid/") + m_device->property("ID_FS_UUID").toString();
|
const KMountPoint::List mountpoints = KMountPoint::currentMountPoints();
|
||||||
const QString labelpath = QLatin1String("/dev/disk/by-label/") + m_device->property("ID_FS_LABEL").toString();
|
|
||||||
|
|
||||||
while (true) {
|
KMountPoint::Ptr found = mountpoints.findByDevice(devpath);
|
||||||
const QString line = mounts.readLine();
|
if (found) {
|
||||||
const QStringList splitline = line.split(" ");
|
return found->mountPoint();
|
||||||
const QString deviceentry = splitline.at(0);
|
|
||||||
|
|
||||||
if (deviceentry == devpath || deviceentry == uuidpath || deviceentry == labelpath) {
|
|
||||||
return splitline.at(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mounts.atEnd()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
|
|
Loading…
Add table
Reference in a new issue