summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2022-03-21 23:42:44 +0100
committerRobert Griebl <robert.griebl@qt.io>2022-03-22 14:44:39 +0000
commitbc06a04dd845d039ba802f94b5eae57519ec63a8 (patch)
treef8080dff2b7f24a20661b9dc1d1340af93c30375
parent8f0a7fc2429b01f4196e615e1dff2be13f26306d (diff)
downloadqtapplicationmanager-bc06a04dd845d039ba802f94b5eae57519ec63a8.tar.gz
Handle an empty or invalid documentDir correctly
Not specifying the documentDir, but enabling the installer would - unexpectedly - use $PWD as documentDir. The code does now follow the documentation: if not set, no document directories will be created on package installation. Also, we now fail early if the documentDir and installationDir are sub-directories of each other, as that would lead to mayhem on PackageManager::cleanupBrokenInstallations(). Change-Id: Id8d89f82bf0d63c771f3d86a963c66681f43f195 Fixes: QTBUG-101881 Pick-to: 6.3 6.2 5.15 Reviewed-by: Bernd Weimer <bernd.weimer@qt.io>
-rw-r--r--doc/configuration.qdoc3
-rw-r--r--src/main-lib/main.cpp9
-rw-r--r--src/manager-lib/deinstallationtask.cpp2
-rw-r--r--src/manager-lib/installationtask.cpp2
-rw-r--r--src/manager-lib/packagemanager.cpp5
5 files changed, 17 insertions, 4 deletions
diff --git a/doc/configuration.qdoc b/doc/configuration.qdoc
index 171997c2..fa1935b4 100644
--- a/doc/configuration.qdoc
+++ b/doc/configuration.qdoc
@@ -192,6 +192,9 @@ ui:
\li string
\li The base directory for per-package document storage directories.
(default: empty/disabled)
+
+ Please note, that if you do not set a \c documentDir here, no per-application
+ document directories will be created when installing new packages.
\row
\li [\c applications/installationDirMountPoint]
\li string
diff --git a/src/main-lib/main.cpp b/src/main-lib/main.cpp
index 323431aa..a0140294 100644
--- a/src/main-lib/main.cpp
+++ b/src/main-lib/main.cpp
@@ -491,6 +491,15 @@ void Main::setupInstaller(bool devMode, bool allowUnsigned, const QStringList &c
"even automatically switching to C.UTF-8 or en_US.UTF-8 failed.";
}
+ // make sure the installation and document dirs are valid
+ Q_ASSERT(!m_installationDir.isEmpty());
+ const auto instPath = QDir(m_installationDir).canonicalPath();
+ const auto docPath = m_documentDir.isEmpty() ? QString { }
+ : QDir(m_documentDir).canonicalPath();
+
+ if (!docPath.isEmpty() && (instPath.startsWith(docPath) || docPath.startsWith(instPath)))
+ throw Exception("either installationDir or documentDir cannot be a sub-directory of the other");
+
// we only output these deployment warnings, if we are on embedded, applicationUserIdSeparation
// is enabled and either...
if (isRunningOnEmbedded() && userIdSeparation && userIdSeparation(nullptr, nullptr, nullptr)) {
diff --git a/src/manager-lib/deinstallationtask.cpp b/src/manager-lib/deinstallationtask.cpp
index ec7fcf1e..740c6e36 100644
--- a/src/manager-lib/deinstallationtask.cpp
+++ b/src/manager-lib/deinstallationtask.cpp
@@ -104,7 +104,7 @@ void DeinstallationTask::execute()
ScopedRenamer docDirRename;
ScopedRenamer appDirRename;
- if (!m_keepDocuments) {
+ if (!m_keepDocuments || !m_documentPath.isEmpty()) {
if (!docDirRename.rename(QDir(m_documentPath).absoluteFilePath(packageId()),
ScopedRenamer::NameToNameMinus)) {
throw Exception(Error::IO, "could not rename %1 to %1-").arg(docDirRename.baseName());
diff --git a/src/manager-lib/installationtask.cpp b/src/manager-lib/installationtask.cpp
index cd4efc5c..6ddcd58f 100644
--- a/src/manager-lib/installationtask.cpp
+++ b/src/manager-lib/installationtask.cpp
@@ -401,7 +401,7 @@ void InstallationTask::finishInstallation() Q_DECL_NOEXCEPT_EXPR(false)
reportFile.close();
// create the document directories when installing (not needed on updates)
- if (mode == Installation) {
+ if ((mode == Installation) && !m_documentPath.isEmpty()) {
// this package may have been installed earlier and the document directory may not have been removed
if (!documentDirectory.cd(m_packageId)) {
if (!documentDirCreator.create(documentDirectory.absoluteFilePath(m_packageId)))
diff --git a/src/manager-lib/packagemanager.cpp b/src/manager-lib/packagemanager.cpp
index 36bb5fb0..4d80868b 100644
--- a/src/manager-lib/packagemanager.cpp
+++ b/src/manager-lib/packagemanager.cpp
@@ -824,7 +824,7 @@ QVariantMap PackageManager::installationLocation() const
*/
QVariantMap PackageManager::documentLocation() const
{
- return locationMap(d->documentPath);
+ return d->documentPath.isEmpty() ? QVariantMap { } : locationMap(d->documentPath);
}
void PackageManager::cleanupBrokenInstallations() Q_DECL_NOEXCEPT_EXPR(false)
@@ -875,7 +875,8 @@ void PackageManager::cleanupBrokenInstallations() Q_DECL_NOEXCEPT_EXPR(false)
if (valid) {
validPaths.insert(d->installationPath, pkg->id() + QDir::separator());
- validPaths.insert(d->documentPath, pkg->id() + QDir::separator());
+ if (!d->documentPath.isEmpty())
+ validPaths.insert(d->documentPath, pkg->id() + QDir::separator());
} else {
if (startingPackageRemoval(pkg->id())) {
if (finishedPackageInstall(pkg->id()))