QFileSystemEngine::tempPath: simplify handling of fallbacks
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. Change-Id: I3e486f73276a3ae288d1fffdbfe20a74271f73f2 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit ae973dc2de5ce3b5a7d18018691479013d91053d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 17f5cdd39ed8a6e9cf25e99003478adfef572485)
This commit is contained in:
parent
e7216042c4
commit
777019525e
@ -1826,6 +1826,8 @@ static constexpr QLatin1StringView nativeTempPath() noexcept
|
|||||||
QLatin1StringView temp = _PATH_TMP ""_L1;
|
QLatin1StringView temp = _PATH_TMP ""_L1;
|
||||||
static_assert(_PATH_TMP[0] == '/', "_PATH_TMP needs to be absolute");
|
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??");
|
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;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1835,17 +1837,12 @@ QString QFileSystemEngine::tempPath()
|
|||||||
return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1;
|
return QT_UNIX_TEMP_PATH_OVERRIDE ""_L1;
|
||||||
#else
|
#else
|
||||||
QString temp = qEnvironmentVariable("TMPDIR");
|
QString temp = qEnvironmentVariable("TMPDIR");
|
||||||
if (temp.isEmpty()) {
|
# if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
|
||||||
if (false) {
|
if (NSString *nsPath; temp.isEmpty() && (nsPath = NSTemporaryDirectory()))
|
||||||
#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
|
temp = QString::fromCFString((CFStringRef)nsPath);
|
||||||
} else if (NSString *nsPath = NSTemporaryDirectory()) {
|
# endif
|
||||||
temp = QString::fromCFString((CFStringRef)nsPath);
|
if (temp.isEmpty())
|
||||||
#endif
|
return nativeTempPath();
|
||||||
} else {
|
|
||||||
constexpr auto nativeTemp = nativeTempPath();
|
|
||||||
temp = nativeTemp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the environment variable may also end in '/'
|
// the environment variable may also end in '/'
|
||||||
if (temp.size() > 1 && temp.endsWith(u'/'))
|
if (temp.size() > 1 && temp.endsWith(u'/'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user