1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
From: Debian/Kubuntu Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Date: Sun, 12 Jun 2016 21:57:24 +0200
Subject: Return the shortest filePath to avoid errors like https://bugs.debian.org/762950
---
src/solid/devices/backends/udisks2/udisksstorageaccess.cpp | 27 ++++++++++---
1 file changed, 21 insertions(+), 6 deletions(-)
--- a/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp
+++ b/src/solid/devices/backends/udisks2/udisksstorageaccess.cpp
@@ -216,6 +216,25 @@ static QString baseMountPoint(const QByt
return mountPoint;
}
+// We return the shortest filePath to avoid errors like:
+// https://bugs.debian.org/762950
+static inline QString get_shortest(const QByteArrayList& mntPoints)
+{
+ if (mntPoints.isEmpty()) {
+ return QString();
+ }
+ QByteArray shortestBA = Utils::sanitizeValue(mntPoints.first());
+ QString shortest = QFile::decodeName(shortestBA);
+ for (int i = 1; i < mntPoints.count(); i++) {
+ QByteArray currentBA = Utils::sanitizeValue(mntPoints.at(i));
+ QString current = QFile::decodeName(currentBA);
+ if (shortest.length() > current.length()) {
+ shortest = current;
+ }
+ }
+ return shortest;
+}
+
QString StorageAccess::filePath() const
{
if (isLuksDevice()) { // encrypted (and unlocked) device
@@ -225,11 +244,8 @@ QString StorageAccess::filePath() const
}
Device holderDevice(m_device->manager(), path);
const auto mntPoints = qdbus_cast<QByteArrayList>(holderDevice.prop(QStringLiteral("MountPoints")));
- if (!mntPoints.isEmpty()) {
- return QFile::decodeName(Utils::sanitizeValue(mntPoints.first())); // FIXME Solid doesn't support multiple mount points
- } else {
- return QString();
- }
+ // FIXME Solid doesn't support multiple mount points
+ return get_shortest(mntPoints);
}
const auto mntPoints = qdbus_cast<QByteArrayList>(m_device->prop(QStringLiteral("MountPoints")));
@@ -239,7 +257,7 @@ QString StorageAccess::filePath() const
return {};
}
- const QString potentialMountPoint = QFile::decodeName(Utils::sanitizeValue(mntPoints.first()));
+ const QString potentialMountPoint = get_shortest(mntPoints);
if (mntPoints.size() == 1) {
return potentialMountPoint;
|