diff options
-rw-r--r-- | src/corelib/io/qfilesystemengine_win.cpp | 12 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdir/tst_qdir.cpp | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index e7a949a77a..6041edb252 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -1060,9 +1060,19 @@ QString QFileSystemEngine::tempPath() { QString ret; wchar_t tempPath[MAX_PATH]; - DWORD len = GetTempPath(MAX_PATH, tempPath); + const DWORD len = GetTempPath(MAX_PATH, tempPath); +#ifdef Q_OS_WINCE if (len) ret = QString::fromWCharArray(tempPath, len); +#else + if (len) { // GetTempPath() can return short names, expand. + wchar_t longTempPath[MAX_PATH]; + const DWORD longLen = GetLongPathName(tempPath, longTempPath, MAX_PATH); + ret = longLen && longLen < MAX_PATH ? + QString::fromWCharArray(longTempPath, longLen) : + QString::fromWCharArray(tempPath, len); + } +#endif if (!ret.isEmpty()) { while (ret.endsWith(QLatin1Char('\\'))) ret.chop(1); diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index f7fa510a0e..9bc6f80f5b 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -1370,6 +1370,8 @@ void tst_QDir::tempPath() #elif defined(Q_OS_WIN) if (path.length() > 3) // root dir = "c:/"; "//" is not really valid... QVERIFY(!path.endsWith('/')); + QVERIFY2(!path.contains(QLatin1Char('~')), + qPrintable(QString::fromLatin1("Temp path (%1) must not be a short name.").arg(path))); #endif } |