[app] Fixed detection of removable storage for non-nemo users
I'm wondering why it was renamed in the first place :/
This commit is contained in:
parent
70b5753703
commit
4e479a3381
1 changed files with 26 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015-2019 Jolla Ltd.
|
* Copyright (C) 2015-2020 Jolla Ltd.
|
||||||
* Copyright (C) 2015-2019 Slava Monich <slava.monich@jolla.com>
|
* Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
|
||||||
*
|
*
|
||||||
* You may use this file under the terms of the BSD license as follows:
|
* You may use this file under the terms of the BSD license as follows:
|
||||||
*
|
*
|
||||||
|
@ -51,6 +51,8 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
#include <libudev.h>
|
#include <libudev.h>
|
||||||
|
|
||||||
#define INTERNAL_STATE_DIR "internal"
|
#define INTERNAL_STATE_DIR "internal"
|
||||||
|
@ -291,7 +293,6 @@ public:
|
||||||
QString path;
|
QString path;
|
||||||
|
|
||||||
bool parse(QString aLine);
|
bool parse(QString aLine);
|
||||||
bool isMediaMount();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Private(BooksStorageManager* aParent);
|
Private(BooksStorageManager* aParent);
|
||||||
|
@ -300,6 +301,7 @@ public:
|
||||||
BooksStorage internalStorage() const;
|
BooksStorage internalStorage() const;
|
||||||
int findDevice(QString aDevice) const;
|
int findDevice(QString aDevice) const;
|
||||||
int findPath(QString aPath, QString* aRelPath) const;
|
int findPath(QString aPath, QString* aRelPath) const;
|
||||||
|
bool isMediaMount(const MountEntry* aEntry);
|
||||||
bool scanMounts();
|
bool scanMounts();
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -317,6 +319,7 @@ public:
|
||||||
QSocketNotifier* iNotifier;
|
QSocketNotifier* iNotifier;
|
||||||
QTimer* iScanMountsTimer;
|
QTimer* iScanMountsTimer;
|
||||||
QDateTime iScanDeadline;
|
QDateTime iScanDeadline;
|
||||||
|
QString iRunMediaPrefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
BooksStorageManager* BooksStorageManager::Private::gInstance = NULL;
|
BooksStorageManager* BooksStorageManager::Private::gInstance = NULL;
|
||||||
|
@ -338,13 +341,6 @@ bool BooksStorageManager::Private::MountEntry::parse(QString aLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BooksStorageManager::Private::MountEntry::isMediaMount()
|
|
||||||
{
|
|
||||||
static const QString MOUNT_PREFIX("/media/");
|
|
||||||
static const QString MOUNT_PREFIX2("/run/media/nemo/");
|
|
||||||
return path.startsWith(MOUNT_PREFIX) || path.startsWith(MOUNT_PREFIX2);
|
|
||||||
}
|
|
||||||
|
|
||||||
BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
||||||
QObject(aParent),
|
QObject(aParent),
|
||||||
iParent(aParent),
|
iParent(aParent),
|
||||||
|
@ -353,15 +349,24 @@ BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
||||||
iMonitor(NULL),
|
iMonitor(NULL),
|
||||||
iDescriptor(-1),
|
iDescriptor(-1),
|
||||||
iNotifier(NULL),
|
iNotifier(NULL),
|
||||||
iScanMountsTimer(NULL)
|
iScanMountsTimer(NULL),
|
||||||
|
iRunMediaPrefix("/run/media/")
|
||||||
{
|
{
|
||||||
QString homeDevice;
|
QString homeDevice;
|
||||||
QString homeBooks = QDir::homePath();
|
QString homeBooks = QDir::homePath();
|
||||||
QString homeMount(BooksStorage::Private::mountPoint(homeBooks));
|
QString homeMount(BooksStorage::Private::mountPoint(homeBooks));
|
||||||
if (!homeBooks.endsWith('/')) homeBooks += '/';
|
if (!homeBooks.endsWith('/')) homeBooks += '/';
|
||||||
homeBooks += QLatin1String(BOOKS_INTERNAL_ROOT);
|
homeBooks += QLatin1String(BOOKS_INTERNAL_ROOT);
|
||||||
|
|
||||||
|
const struct passwd* pw = getpwuid(geteuid());
|
||||||
|
if (pw) {
|
||||||
|
iRunMediaPrefix += QLatin1String(pw->pw_name);
|
||||||
|
iRunMediaPrefix += QChar('/');
|
||||||
|
}
|
||||||
|
|
||||||
HDEBUG("home mount" << qPrintable(homeMount));
|
HDEBUG("home mount" << qPrintable(homeMount));
|
||||||
HDEBUG("home books path" << qPrintable(homeBooks));
|
HDEBUG("home books path" << qPrintable(homeBooks));
|
||||||
|
HDEBUG("media mount prefix" << qPrintable(iRunMediaPrefix));
|
||||||
|
|
||||||
QFile mounts(STORAGE_MOUNTS_FILE);
|
QFile mounts(STORAGE_MOUNTS_FILE);
|
||||||
if (mounts.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (mounts.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
@ -374,13 +379,15 @@ BooksStorageManager::Private::Private(BooksStorageManager* aParent) :
|
||||||
if (entry.path == homeMount) {
|
if (entry.path == homeMount) {
|
||||||
homeDevice = entry.dev;
|
homeDevice = entry.dev;
|
||||||
HDEBUG("internal" << homeDevice);
|
HDEBUG("internal" << homeDevice);
|
||||||
} else if (entry.isMediaMount()) {
|
} else if (isMediaMount(&entry)) {
|
||||||
QString path(entry.path);
|
QString path(entry.path);
|
||||||
if (!path.endsWith('/')) path += '/';
|
if (!path.endsWith('/')) path += '/';
|
||||||
path += iSettings->removableRoot();
|
path += iSettings->removableRoot();
|
||||||
BooksStorage bs(entry.dev, entry.path, path, false);
|
BooksStorage bs(entry.dev, entry.path, path, false);
|
||||||
HDEBUG("removable" << entry.dev << bs.booksDir().path());
|
HDEBUG("removable" << entry.dev << bs.booksDir().path());
|
||||||
iStorageList.append(bs);
|
iStorageList.append(bs);
|
||||||
|
} else {
|
||||||
|
HDEBUG(entry.dev << entry.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,7 +489,7 @@ bool BooksStorageManager::Private::scanMounts()
|
||||||
MountEntry entry;
|
MountEntry entry;
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
if (entry.parse(in.readLine()) &&
|
if (entry.parse(in.readLine()) &&
|
||||||
entry.isMediaMount() &&
|
isMediaMount(&entry) &&
|
||||||
findDevice(entry.dev) < 0) {
|
findDevice(entry.dev) < 0) {
|
||||||
QString path(entry.path);
|
QString path(entry.path);
|
||||||
if (!path.endsWith('/')) path += '/';
|
if (!path.endsWith('/')) path += '/';
|
||||||
|
@ -499,6 +506,12 @@ bool BooksStorageManager::Private::scanMounts()
|
||||||
return newStorageFound;
|
return newStorageFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BooksStorageManager::Private::isMediaMount(const MountEntry* aEntry)
|
||||||
|
{
|
||||||
|
return aEntry->path.startsWith(QStringLiteral("/media/")) ||
|
||||||
|
aEntry->path.startsWith(iRunMediaPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
void BooksStorageManager::Private::onScanMounts()
|
void BooksStorageManager::Private::onScanMounts()
|
||||||
{
|
{
|
||||||
if (scanMounts()) {
|
if (scanMounts()) {
|
||||||
|
|
Loading…
Reference in a new issue