diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-07-16 15:35:58 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-17 15:56:15 +0200 |
commit | fe4adec894a8294516cd6aa02c5cbae2e7d8e8db (patch) | |
tree | 2ab61c463a3dfb1d7392ea80269c8fc0369a1b6f | |
parent | dc4cd551c66111a9d3876dc324f7e52fc3cca2a6 (diff) |
Windows: Do not return short path names for QDir::tempPath().
WinAPI GetTempPath() sometimes returns short names
for C:/Users/<user>/AppData/Local/Temp.
Change-Id: I33f991acc06e652ccd484d36a5a384eb776f8395
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
-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 } |