summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-01-05 15:58:14 +0200
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-01-15 09:27:29 +0200
commit57078aec62049ac08c5df94db06c79e956fd0eeb (patch)
treec5b2801f47e03d3b94a714440249a779d9e87637
parent20f354b38b83e4aab107b388fe3c5e2ccd878946 (diff)
Fix InstallIcons and CreateDesktopEntry operations usage as root
The operations write the output files to a valid, writable directory value of XDG_DATA_HOME variable if set, otherwise defaulting to "$HOME/.local/share". This follows the XDG Base Directory Specification but misses the use case of system-wide installation: the XDG_DATA_HOME should only contain base directory relative to which user specific data files should be stored. Prefer a predefined value "/usr/local/share" when launced as root or the internal elevated admin rights handling is active. This should be a sane and well known value for applications installed system-wide, and should not conflict with files extracted by distribution's package management system. Task-number: QTIFW-2093 Change-Id: I96fab3367122e7df783697e07baeb71dfd9b3f0e Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--doc/operations.qdoc7
-rw-r--r--src/libs/installer/createdesktopentryoperation.cpp7
-rw-r--r--src/libs/installer/installiconsoperation.cpp7
-rw-r--r--tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp2
-rw-r--r--tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp2
5 files changed, 20 insertions, 5 deletions
diff --git a/doc/operations.qdoc b/doc/operations.qdoc
index a01446a69..cec0dba40 100644
--- a/doc/operations.qdoc
+++ b/doc/operations.qdoc
@@ -162,7 +162,8 @@
If \c filename is absolute, the desktop entry is stored there.
Otherwise, it is stored in the location specified in
\c{$XDG_DATA_HOME/applications}, including the default path,
- as defined by freedesktop.org.
+ as defined by freedesktop.org. For system-wide installations,
+ it is stored in \c {/usr/local/share/applications} instead.
The key-value pairs are written to the file.
@@ -172,8 +173,8 @@
\li "InstallIcons" \c directory \c [Vendorprefix]
\li Installs the contents of \c directory into a location, as
specified by freedesktop.org. That is, into
- \c {$XDG_DATA_HOME/icons} or
- \c {$HOME/.local/share/icons}. The files are removed from their initial
+ \c {$XDG_DATA_HOME/icons}, \c {$HOME/.local/share/icons} or
+ \c {/usr/local/share/icons}. The files are removed from their initial
location. Make sure to add this operation after the operation
that extracts the files from the archive.
If you provide a \c Vendorprefix it replaces all characters up to the
diff --git a/src/libs/installer/createdesktopentryoperation.cpp b/src/libs/installer/createdesktopentryoperation.cpp
index 5907e2f21..1a56c193c 100644
--- a/src/libs/installer/createdesktopentryoperation.cpp
+++ b/src/libs/installer/createdesktopentryoperation.cpp
@@ -30,6 +30,8 @@
#include "errors.h"
#include "fileutils.h"
#include "globals.h"
+#include "adminauthorization.h"
+#include "remoteclient.h"
#include <QDir>
#include <QFile>
@@ -60,7 +62,10 @@ QString CreateDesktopEntryOperation::absoluteFileName()
.split(QLatin1Char(':'),
QString::SkipEmptyParts);
- XDG_DATA_HOME.push_back(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); // default path
+ XDG_DATA_HOME.push_back(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); // default user-specific path
+
+ if (AdminAuthorization::hasAdminRights() || RemoteClient::instance().isActive())
+ XDG_DATA_HOME.push_front(QLatin1String("/usr/local/share")); // default system-wide path
const QStringList directories = XDG_DATA_HOME;
QString directory;
diff --git a/src/libs/installer/installiconsoperation.cpp b/src/libs/installer/installiconsoperation.cpp
index eea83a462..9443b7f71 100644
--- a/src/libs/installer/installiconsoperation.cpp
+++ b/src/libs/installer/installiconsoperation.cpp
@@ -30,6 +30,8 @@
#include "fileutils.h"
#include "packagemanagercore.h"
#include "globals.h"
+#include "adminauthorization.h"
+#include "remoteclient.h"
#include <QDebug>
#include <QDir>
@@ -52,7 +54,10 @@ QString InstallIconsOperation::targetDirectory()
QStringList XDG_DATA_HOME = QString::fromLocal8Bit(qgetenv("XDG_DATA_HOME"))
.split(QLatin1Char(':'),
QString::SkipEmptyParts);
- XDG_DATA_HOME.push_back(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); // default path
+ XDG_DATA_HOME.push_back(QDir::home().absoluteFilePath(QLatin1String(".local/share"))); // default user-specific path
+
+ if (AdminAuthorization::hasAdminRights() || RemoteClient::instance().isActive())
+ XDG_DATA_HOME.push_front(QLatin1String("/usr/local/share")); // default system-wide path
QString directory;
const QStringList& directories = XDG_DATA_HOME;
diff --git a/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp b/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp
index ac3fffbe1..32e23ea14 100644
--- a/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp
+++ b/tests/auto/installer/createdesktopentryoperation/tst_createdesktopentryoperation.cpp
@@ -73,6 +73,8 @@ private:
.split(QLatin1Char(':'), QString::SkipEmptyParts);
// Default path if XDG_DATA_HOME is not set
directories.append(QDir::home().absoluteFilePath(QLatin1String(".local/share")));
+ // Default path if run as root
+ directories.append(QLatin1String("/usr/local/share"));
bool validPath = false;
foreach (const QString &dir, directories) {
// Desktop entry should be in one of the expected locations
diff --git a/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp b/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp
index d1a9c680e..fdbbb29bc 100644
--- a/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp
+++ b/tests/auto/installer/installiconsoperation/tst_installiconsoperation.cpp
@@ -205,6 +205,8 @@ private slots:
.split(QLatin1Char(':'), QString::SkipEmptyParts);
// Default path if XDG_DATA_HOME is not set
directories.append(QDir::home().absoluteFilePath(QLatin1String(".local/share")));
+ // Default path if run as root
+ directories.append(QLatin1String("/usr/local/share"));
bool validPath = false;
foreach (const QString &dir, directories) {
// Icon directory should be one of the expected locations