Windows: Capture last error right after CreateDirectory() in QFileSystemEngine.
Custom allocators invoked by freeing the QString contents might change it. Task-number: QTBUG-34046 Task-number: QTBUG-32314 Change-Id: Ied5305c21fcce228448fe565899163997536ea7a Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>bb10
parent
27316e097f
commit
73e3d2f6cb
|
|
@ -965,8 +965,10 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
|
|||
return data.hasFlags(what);
|
||||
}
|
||||
|
||||
static inline bool mkDir(const QString &path)
|
||||
static inline bool mkDir(const QString &path, DWORD *lastError = 0)
|
||||
{
|
||||
if (lastError)
|
||||
*lastError = 0;
|
||||
#if defined(Q_OS_WINCE)
|
||||
// Unfortunately CreateDirectory returns true for paths longer than
|
||||
// 256, but does not create a directory. It starts to fail, when
|
||||
|
|
@ -986,7 +988,11 @@ static inline bool mkDir(const QString &path)
|
|||
if (platformId == 1 && QFSFileEnginePrivate::longFileName(path).size() > 256)
|
||||
return false;
|
||||
#endif
|
||||
return ::CreateDirectory((wchar_t*)QFSFileEnginePrivate::longFileName(path).utf16(), 0);
|
||||
const QString longPath = QFSFileEnginePrivate::longFileName(path);
|
||||
const bool result = ::CreateDirectory((wchar_t*)longPath.utf16(), 0);
|
||||
if (lastError) // Capture lastError before any QString is freed since custom allocators might change it.
|
||||
*lastError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline bool rmDir(const QString &path)
|
||||
|
|
@ -1051,9 +1057,9 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
|
|||
slash = dirName.length();
|
||||
}
|
||||
if (slash) {
|
||||
DWORD lastError;
|
||||
QString chunk = dirName.left(slash);
|
||||
if (!mkDir(chunk)) {
|
||||
const DWORD lastError = GetLastError();
|
||||
if (!mkDir(chunk, &lastError)) {
|
||||
if (lastError == ERROR_ALREADY_EXISTS || lastError == ERROR_ACCESS_DENIED) {
|
||||
bool existed = false;
|
||||
if (isDirPath(chunk, &existed) && existed)
|
||||
|
|
|
|||
Loading…
Reference in New Issue