This instance will be upgraded to Heptapod 0.20.1 on 2020-03-08 at 14:00 UTC+1 (10 minutes of downtime)

Commit 4395ee55 authored by Gleb Popov's avatar Gleb Popov

Check if the directory is already mounted before selecting/removing it.

parent b8340d6af87f
......@@ -34,16 +34,42 @@
#include <QProcess>
#include <QDir>
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <unistd.h>
#include <errno.h>
QString createMountPoint(QString id, uid_t uid, int suff = 0)
static bool alreadyMounted(QDir d)
{
struct statfs* buf;
int count = ::getmntinfo(&buf, MNT_NOWAIT);
if(!count)
{
QString error = QString::fromLocal8Bit(::strerror(errno));
qDebug() << "alreadyMounted: getmntinfo failed: " << error;
return false;
}
for(int i = 0; i<count; i++)
{
QString mntOn = QString::fromLocal8Bit(buf[i].f_mntonname);
if(d == QDir(mntOn))
return true;
}
return false;
}
static QString createMountPoint(QString id, uid_t uid, int suff = 0)
{
auto mp = suff == 0 ? QStringLiteral("/media/") + id
: QStringLiteral("/media/") + id + QString::number(suff);
QDir mpDir(mp);
if(mpDir.exists())
if(mpDir.exists() && alreadyMounted(mpDir))
return createMountPoint(id, uid, ++suff);
mpDir.mkpath(".");
......@@ -58,7 +84,7 @@ QString createMountPoint(QString id, uid_t uid, int suff = 0)
return mp;
}
void removeMountPoint(QString mp, bool checkIfEmpty = false)
static void removeMountPoint(QString mp, bool checkIfEmpty = false)
{
QDir mpDir(mp);
......
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