From 71652ad4bf7b4cfe35473c3f93213c16e7653135 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Mon, 27 Sep 2021 22:58:57 +0200 Subject: [PATCH] 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 --- src/corelib/io/qfilesystemengine_win.cpp | 2 +- tests/auto/corelib/io/qdir/tst_qdir.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index d1a197698e5..9e009a05e7d 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -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); diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 3675e45f838..7e77e22f67e 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -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());