diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 40ab67bb34f..5660f3c8adb 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1826,6 +1826,8 @@ static constexpr QLatin1StringView nativeTempPath() noexcept QLatin1StringView temp = _PATH_TMP ""_L1; static_assert(_PATH_TMP[0] == '/', "_PATH_TMP needs to be absolute"); static_assert(_PATH_TMP[1] != '\0', "Are you really sure _PATH_TMP should be the root dir??"); + if (temp.endsWith(u'/')) + temp.chop(1); return temp; } @@ -1835,17 +1837,12 @@ QString QFileSystemEngine::tempPath() return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1; #else QString temp = qEnvironmentVariable("TMPDIR"); - if (temp.isEmpty()) { - if (false) { -#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) - } else if (NSString *nsPath = NSTemporaryDirectory()) { - temp = QString::fromCFString((CFStringRef)nsPath); -#endif - } else { - constexpr auto nativeTemp = nativeTempPath(); - temp = nativeTemp; - } - } +# if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED) + if (NSString *nsPath; temp.isEmpty() && (nsPath = NSTemporaryDirectory())) + temp = QString::fromCFString((CFStringRef)nsPath); +# endif + if (temp.isEmpty()) + return nativeTempPath(); // the environment variable may also end in '/' if (temp.size() > 1 && temp.endsWith(u'/'))