Make QDir::mkpath() return true when given an existing drive name

Commit ed48391c592e8ba68c723e3017ac384f0c7a7c23 removed the check for
ERROR_ACCESS_DENIED reported by the Windows CreateDirectory(...)
function in case an existing windows drive name was passed as argument.
This restores the behavior of the function which broke after 5.15.

Pick-to: 6.2
Fixes: QTBUG-85997
Change-Id: Ie86188100766f7364acee57b15a250f4a2720b9f
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
This commit is contained in:
Karsten Heimrich 2021-09-27 22:58:57 +02:00
parent 57ec47921e
commit 71652ad4bf
2 changed files with 6 additions and 1 deletions

View File

@ -1180,7 +1180,7 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea
// mkpath should return true, if the directory already exists, mkdir false.
if (!createParents)
return false;
if (lastError == ERROR_ALREADY_EXISTS)
if (lastError == ERROR_ALREADY_EXISTS || lastError == ERROR_ACCESS_DENIED)
return isDirPath(dirName, nullptr);
return createDirectoryWithParents(dirName, false);

View File

@ -466,6 +466,11 @@ void tst_QDir::makedirReturnCode()
QVERIFY(!QDir::current().mkdir(dirName)); // calling mkdir on an existing dir will fail.
QVERIFY(QDir::current().mkpath(dirName)); // calling mkpath on an existing dir will pass
#ifdef Q_OS_WIN
// the next line specifically targets Windows, see QTBUG-85997
QVERIFY(QDir().mkpath(QDir::rootPath())); // calling mkpath on an existing drive name will pass
#endif
// Remove the directory and create a file with the same path
QDir::current().rmdir(dirName);
QVERIFY(!f.exists());