QDir::tempPath - use NSTemporaryDirectory on Darwin

Instead of hardcoded "/tmp".

Task-number: QTBUG-57165
Change-Id: I9d3ae157c22ce131281b8279149eea87a26244e8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Timur Pocheptsov 2016-11-17 16:10:11 +01:00
parent 53edaf0fb7
commit e2b856d562

View File

@ -59,6 +59,13 @@
#include <MobileCoreServices/MobileCoreServices.h>
#endif
#if defined(Q_OS_DARWIN)
// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but
// we need these declarations:
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
extern "C" NSString *NSTemporaryDirectory();
#endif
QT_BEGIN_NAMESPACE
#if defined(Q_OS_DARWIN)
@ -706,8 +713,17 @@ QString QFileSystemEngine::tempPath()
return QDir::cleanPath(temp);
#else
QString temp = QFile::decodeName(qgetenv("TMPDIR"));
if (temp.isEmpty())
temp = QLatin1String("/tmp");
if (temp.isEmpty()) {
#if defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
if (NSString *nsPath = NSTemporaryDirectory()) {
temp = QString::fromCFString((CFStringRef)nsPath);
} else {
#else
{
#endif
temp = QLatin1String("/tmp");
}
}
return QDir::cleanPath(temp);
#endif
}