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>
This commit is contained in:
parent
dc4cd551c6
commit
fe4adec894
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user