Windows: Do not return short path names for QDir::tempPath().
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>
Mon, 16 Jul 2012 13:35:58 +0000 (15:35 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 17 Jul 2012 13:56:15 +0000 (15:56 +0200)
WinAPI GetTempPath() sometimes returns short names
for C:/Users/<user>/AppData/Local/Temp.

Change-Id: I33f991acc06e652ccd484d36a5a384eb776f8395
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
src/corelib/io/qfilesystemengine_win.cpp
tests/auto/corelib/io/qdir/tst_qdir.cpp

index e7a949a..6041edb 100644 (file)
@@ -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);
index f7fa510..9bc6f80 100644 (file)
@@ -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
 }