mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
soliduiserver: implement methods to mount/unmount devices that are not Solid UDI and adjust to KAutoMount changes
this goes with 986a303ff6b8e179aadc85468abcae448711a108 in kdelibs repo Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
4302882d08
commit
4c43b79a88
4 changed files with 73 additions and 88 deletions
|
@ -408,8 +408,7 @@ void KonqOperations::asyncDrop( const KFileItem & destItem )
|
|||
else
|
||||
{
|
||||
const bool ro = desktopGroup.readEntry( "ReadOnly", false );
|
||||
const QByteArray fstype = desktopGroup.readEntry( "FSType" ).toLatin1();
|
||||
KAutoMount* am = new KAutoMount( ro, fstype, dev, point, m_destUrl.path(), false );
|
||||
KAutoMount* am = new KAutoMount( ro, dev, point, m_destUrl.path(), false );
|
||||
connect( am, SIGNAL(finished()), this, SLOT(doDropFileCopy()) );
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -42,52 +42,6 @@
|
|||
|
||||
#include <QDir>
|
||||
|
||||
static int doMount(const QString &deviceuuid, const QString &devicenode, const QString &devicefstype)
|
||||
{
|
||||
// permission denied on /run/mount so.. using base directory that is writable
|
||||
const QString mountbase = KGlobal::dirs()->saveLocation("tmp");
|
||||
const QString mountpoint = mountbase + QLatin1Char('/') + deviceuuid;
|
||||
QDir mountdir(mountbase);
|
||||
if (!mountdir.exists(deviceuuid) && !mountdir.mkdir(deviceuuid)) {
|
||||
kWarning() << "could not create" << mountpoint;
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
QVariantMap mountarguments;
|
||||
mountarguments.insert("device", devicenode);
|
||||
mountarguments.insert("mountpoint", mountpoint);
|
||||
mountarguments.insert("fstype", devicefstype);
|
||||
int mountreply = KAuthorization::execute(
|
||||
"org.kde.soliduiserver.mountunmounthelper", "mount", mountarguments
|
||||
);
|
||||
// qDebug() << "mount" << mountreply;
|
||||
|
||||
if (mountreply == KAuthorization::NoError) {
|
||||
return int(Solid::ErrorType::NoError);
|
||||
} else if (mountreply == KAuthorization::AuthorizationError) {
|
||||
return int(Solid::ErrorType::UnauthorizedOperation);
|
||||
}
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
static int doUnmount(const QString &devicemountpoint)
|
||||
{
|
||||
QVariantMap unmountarguments;
|
||||
unmountarguments.insert("mountpoint", devicemountpoint);
|
||||
int unmountreply = KAuthorization::execute(
|
||||
"org.kde.soliduiserver.mountunmounthelper", "unmount", unmountarguments
|
||||
);
|
||||
// qDebug() << "unmount" << unmountreply;
|
||||
|
||||
if (unmountreply == KAuthorization::NoError) {
|
||||
return int(Solid::ErrorType::NoError);
|
||||
} else if (unmountreply == KAuthorization::AuthorizationError) {
|
||||
return int(Solid::ErrorType::UnauthorizedOperation);
|
||||
}
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
|
||||
K_PLUGIN_FACTORY(SolidUiServerFactory,
|
||||
registerPlugin<SolidUiServer>();
|
||||
)
|
||||
|
@ -167,7 +121,44 @@ void SolidUiServer::onActionDialogFinished()
|
|||
}
|
||||
}
|
||||
|
||||
int SolidUiServer::mountDevice(const QString &udi)
|
||||
|
||||
int SolidUiServer::mountDevice(const QString &device, const QString &mountpoint, bool readonly)
|
||||
{
|
||||
QVariantMap mountarguments;
|
||||
mountarguments.insert("device", device);
|
||||
mountarguments.insert("mountpoint", mountpoint);
|
||||
mountarguments.insert("readonly", readonly);
|
||||
int mountreply = KAuthorization::execute(
|
||||
"org.kde.soliduiserver.mountunmounthelper", "mount", mountarguments
|
||||
);
|
||||
// qDebug() << "mount" << mountreply;
|
||||
|
||||
if (mountreply == KAuthorization::NoError) {
|
||||
return int(Solid::ErrorType::NoError);
|
||||
} else if (mountreply == KAuthorization::AuthorizationError) {
|
||||
return int(Solid::ErrorType::UnauthorizedOperation);
|
||||
}
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
int SolidUiServer::unmountDevice(const QString &mountpoint)
|
||||
{
|
||||
QVariantMap unmountarguments;
|
||||
unmountarguments.insert("mountpoint", mountpoint);
|
||||
int unmountreply = KAuthorization::execute(
|
||||
"org.kde.soliduiserver.mountunmounthelper", "unmount", unmountarguments
|
||||
);
|
||||
// qDebug() << "unmount" << unmountreply;
|
||||
|
||||
if (unmountreply == KAuthorization::NoError) {
|
||||
return int(Solid::ErrorType::NoError);
|
||||
} else if (unmountreply == KAuthorization::AuthorizationError) {
|
||||
return int(Solid::ErrorType::UnauthorizedOperation);
|
||||
}
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
int SolidUiServer::mountUdi(const QString &udi)
|
||||
{
|
||||
Solid::Device device(udi);
|
||||
Solid::StorageVolume *storagevolume = device.as<Solid::StorageVolume>();
|
||||
|
@ -218,7 +209,23 @@ int SolidUiServer::mountDevice(const QString &udi)
|
|||
#warning crypto storage devices are not supported on this platform
|
||||
#endif
|
||||
|
||||
const int mountresult = doMount(deviceuuid, devicenode, storagevolume->fsType());
|
||||
// permission denied on /run/mount so.. using base directory that is writable
|
||||
const QString mountbase = KGlobal::dirs()->saveLocation("tmp");
|
||||
const QString mountpoint = mountbase + QLatin1Char('/') + deviceuuid;
|
||||
QDir mountdir(mountbase);
|
||||
if (!mountdir.exists(mountpoint) && !mountdir.mkdir(mountpoint)) {
|
||||
if (didcryptopen) {
|
||||
QVariantMap cryptclosearguments;
|
||||
cryptclosearguments.insert("name", deviceuuid);
|
||||
(void)KAuthorization::execute(
|
||||
"org.kde.soliduiserver.mountunmounthelper", "cryptclose", cryptclosearguments
|
||||
);
|
||||
}
|
||||
kWarning() << "could not create" << mountpoint;
|
||||
return int(Solid::ErrorType::OperationFailed);
|
||||
}
|
||||
|
||||
const int mountresult = mountDevice(devicenode, mountpoint);
|
||||
if (mountresult != int(Solid::ErrorType::NoError) && didcryptopen) {
|
||||
QVariantMap cryptclosearguments;
|
||||
cryptclosearguments.insert("name", deviceuuid);
|
||||
|
@ -229,7 +236,7 @@ int SolidUiServer::mountDevice(const QString &udi)
|
|||
return mountresult;
|
||||
}
|
||||
|
||||
int SolidUiServer::unmountDevice(const QString &udi)
|
||||
int SolidUiServer::unmountUdi(const QString &udi)
|
||||
{
|
||||
Solid::Device device(udi);
|
||||
Solid::StorageAccess *storageaccess = device.as<Solid::StorageAccess>();
|
||||
|
@ -238,7 +245,7 @@ int SolidUiServer::unmountDevice(const QString &udi)
|
|||
return int(Solid::ErrorType::InvalidOption);
|
||||
}
|
||||
|
||||
const int unmountresult = doUnmount(storageaccess->filePath());
|
||||
const int unmountresult = unmountDevice(storageaccess->filePath());
|
||||
if (unmountresult != int(Solid::ErrorType::NoError)) {
|
||||
return unmountresult;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,11 @@ public Q_SLOTS:
|
|||
Q_SCRIPTABLE void showActionsDialog(const QString &udi,
|
||||
const QStringList &desktopFiles);
|
||||
|
||||
Q_SCRIPTABLE int mountDevice(const QString &udi);
|
||||
Q_SCRIPTABLE int unmountDevice(const QString &udi);
|
||||
Q_SCRIPTABLE int mountDevice(const QString &device, const QString &mountpoint, bool readonly = false);
|
||||
Q_SCRIPTABLE int unmountDevice(const QString &mountpoint);
|
||||
|
||||
Q_SCRIPTABLE int mountUdi(const QString &udi);
|
||||
Q_SCRIPTABLE int unmountUdi(const QString &udi);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onActionDialogFinished();
|
||||
|
|
|
@ -102,47 +102,23 @@ int SolidUiServerHelper::cryptclose(const QVariantMap ¶meters)
|
|||
int SolidUiServerHelper::mount(const QVariantMap ¶meters)
|
||||
{
|
||||
if (!parameters.contains("device") || !parameters.contains("mountpoint")
|
||||
|| !parameters.contains("fstype")) {
|
||||
|| !parameters.contains("readonly")) {
|
||||
return KAuthorization::HelperError;
|
||||
}
|
||||
|
||||
const QString device = parameters.value("device").toString();
|
||||
const QString mountpoint = parameters.value("mountpoint").toString();
|
||||
const QString fstype = parameters.value("fstype").toString();
|
||||
// qDebug() << Q_FUNC_INFO << device << mountpoint << fstype;
|
||||
const bool readonly = parameters.value("readonly").toBool();
|
||||
// qDebug() << Q_FUNC_INFO << device << mountpoint << readonly;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
// NOTE: if the filesystem type is not listed in /proc/filesystems then mount() will fail
|
||||
bool isknownfs = false;
|
||||
const QByteArray fstypebytes = fstype.toLocal8Bit();
|
||||
QFile filesystemsfile(QString::fromLatin1("/proc/filesystems"));
|
||||
if (filesystemsfile.open(QFile::ReadOnly)) {
|
||||
const QByteArray filesystemmatch = QByteArray(" ") + fstypebytes;
|
||||
while (!filesystemsfile.atEnd()) {
|
||||
const QByteArray filesystemsline = filesystemsfile.readLine().trimmed();
|
||||
if (filesystemsline.endsWith(filesystemmatch)) {
|
||||
isknownfs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QStringList mountargs = QStringList() << device << mountpoint;
|
||||
if (readonly) {
|
||||
#if defined(Q_OS_SOLARIS)
|
||||
mountargs << QString::fromLatin1("-oro");
|
||||
#else
|
||||
mountargs << QString::fromLatin1("-r");
|
||||
#endif
|
||||
}
|
||||
if (isknownfs) {
|
||||
const QByteArray devicebytes = device.toLocal8Bit();
|
||||
const QByteArray mountpointbytes = mountpoint.toLocal8Bit();
|
||||
const int mountresult = ::mount(
|
||||
devicebytes.constData(), mountpointbytes.constData(), fstypebytes.constData(),
|
||||
0, NULL
|
||||
);
|
||||
if (mountresult == 0) {
|
||||
return KAuthorization::NoError;
|
||||
}
|
||||
const int savederrno = errno;
|
||||
kWarning() << qt_error_string(savederrno);
|
||||
return KAuthorization::HelperError;
|
||||
}
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
const QStringList mountargs = QStringList() << device << mountpoint;
|
||||
QProcess mountproc;
|
||||
mountproc.start("mount", mountargs);
|
||||
mountproc.waitForStarted();
|
||||
|
|
Loading…
Add table
Reference in a new issue