summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-12-07 16:15:18 +0200
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2021-12-20 13:42:51 +0200
commit48200db8b0e493602ce23f04255dde970cd7a7d5 (patch)
treec5661becfb0d80359c3eb54e641448c928cb8bb1
parent347fc142d29d734223a2afd0d7290256117aefc4 (diff)
Fix selecting target directory when elevated server process is active
There is a disparency in the return value of QFileInfo::isFile() on Windows whether QFileInfo uses QFileSystemEngine directly (for local files, returns false) or with another file engine (QFSFileEngine in this case, returns true), when the file does not exist on disk. Installer registers its own file engine handler that handles file engine creation. It creates custom RemoteFileEngine instances suitable for writing into more restrictive locations when the connection to the elevated installer server process is active. When calling RemoteFileEngine::fileFlags() with TypesMask parameter, the returned combination of enum values includes FileFlag::FileType when the given file does not exist, this can be reproduced with both the active remote server connection that forwards the file engine calls to the server process, and when the composed QFSFileEngine object is used directly without the remote connection. Fix by adding a check if the given target directory path exists, if it doesn't we can assume it is a directory to be created by the installer. Also rename function to better match what it does. Task-number: QTIFW-2383 Change-Id: I906b0676802d9d94e70abeb2dea1f71866cbbec8 Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--src/libs/installer/packagemanagercore.cpp10
-rw-r--r--src/libs/installer/packagemanagercore.h2
-rw-r--r--src/libs/installer/packagemanagergui.cpp2
-rw-r--r--src/sdk/commandlineinterface.cpp2
4 files changed, 10 insertions, 6 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 9d594b2eb..75cd4a4cf 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -1030,8 +1030,9 @@ QString PackageManagerCore::fromNativeSeparators(const QString &path)
}
/*!
- Checks whether the target directory \a targetDirectory exists and has contents:
+ Checks whether installation is allowed to \a targetDirectory:
\list
+ \li Returns \c true if the directory does not exist.
\li Returns \c true if the directory exists and is empty.
\li Returns \c false if the directory already exists and contains an installation.
\li Returns \c false if the target is a file or a symbolic link.
@@ -1039,14 +1040,17 @@ QString PackageManagerCore::fromNativeSeparators(const QString &path)
choice that the end users make in the displayed message box.
\endlist
*/
-bool PackageManagerCore::checkTargetDir(const QString &targetDirectory)
+bool PackageManagerCore::installationAllowedToDirectory(const QString &targetDirectory)
{
+ const QFileInfo fi(targetDirectory);
+ if (!fi.exists())
+ return true;
+
const QDir dir(targetDirectory);
// the directory exists and is empty...
if (dir.exists() && dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty())
return true;
- const QFileInfo fi(targetDirectory);
if (fi.isDir()) {
QString fileName = settings().maintenanceToolName();
#if defined(Q_OS_MACOS)
diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h
index 6698155c3..6b5a04728 100644
--- a/src/libs/installer/packagemanagercore.h
+++ b/src/libs/installer/packagemanagercore.h
@@ -216,7 +216,7 @@ public:
Q_INVOKABLE QString toNativeSeparators(const QString &path);
Q_INVOKABLE QString fromNativeSeparators(const QString &path);
- bool checkTargetDir(const QString &targetDirectory);
+ bool installationAllowedToDirectory(const QString &targetDirectory);
QString targetDirWarning(const QString &targetDirectory) const;
public:
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index d28c5f7ca..a6481b863 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -2392,7 +2392,7 @@ bool TargetDirectoryPage::validatePage()
if (!QVariant(remove).toBool())
return true;
- return this->packageManagerCore()->checkTargetDir(targetDir());
+ return this->packageManagerCore()->installationAllowedToDirectory(targetDir());
}
/*!
diff --git a/src/sdk/commandlineinterface.cpp b/src/sdk/commandlineinterface.cpp
index 6b674364c..63deaf4d9 100644
--- a/src/sdk/commandlineinterface.cpp
+++ b/src/sdk/commandlineinterface.cpp
@@ -267,7 +267,7 @@ bool CommandLineInterface::setTargetDir()
targetDir = m_core->value(QInstaller::scTargetDir);
qCDebug(QInstaller::lcInstallerInstallLog) << "No target directory specified, using default value:" << targetDir;
}
- if (m_core->checkTargetDir(targetDir)) {
+ if (m_core->installationAllowedToDirectory(targetDir)) {
QString targetDirWarning = m_core->targetDirWarning(targetDir);
if (!targetDirWarning.isEmpty()) {
qCWarning(QInstaller::lcInstallerInstallLog) << m_core->targetDirWarning(targetDir);