diff options
author | Thiago Macieira <[email protected]> | 2025-05-28 22:26:46 -0300 |
---|---|---|
committer | Ahmad Samir <[email protected]> | 2025-06-03 11:54:38 +0000 |
commit | ae973dc2de5ce3b5a7d18018691479013d91053d (patch) | |
tree | 862899c901da95127eeb49e02917ec7955460268 | |
parent | 7bd7df5aa170c240061144a9210a13b62949935c (diff) |
If the environment variable is empty, we have a couple of fallbacks, one
for Apple Darwin systems and one for everyone else. A non-absolute path
in the environment or the Apple API makes no sense, but this code
retains this defensive measure for them; for _PATH_TMP from <paths.h>,
we assume it is absolute.
Pick-to: 6.10 6.9
Change-Id: I3e486f73276a3ae288d1fffdbfe20a74271f73f2
Reviewed-by: Ahmad Samir <[email protected]>
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 61b7ecbde17..c02fb102247 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1864,6 +1864,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; } @@ -1873,17 +1875,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'/')) |