From bb8d84c358eb4b324258b936bdeb211fdd90d7cd Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Fri, 15 Oct 2021 13:32:20 +0200 Subject: [PATCH] Make QDir::mkpath() return true when given an existing root path On macOs with APFS mkdir sets errno to EISDIR, so take the error code into account. Pick-to: 6.2 Fixes: QTBUG-97110 Change-Id: I8e7d10c95430a2802bdbfbf94dd65219bd9071a7 Reviewed-by: Volker Hilsheimer --- src/corelib/io/qfilesystemengine_unix.cpp | 2 ++ tests/auto/corelib/io/qdir/tst_qdir.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 150fb18527..054e9ed2fe 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1123,6 +1123,8 @@ static bool createDirectoryWithParents(const QByteArray &nativeName, bool should if (shouldMkdirFirst && QT_MKDIR(nativeName, 0777) == 0) return true; + if (errno == EISDIR) + return true; if (errno == EEXIST) return isDir(nativeName); if (errno != ENOENT) diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 7e77e22f67..8b6b390050 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -466,10 +466,10 @@ 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 + // the next line specifically targets Windows and macOS (QTBUG-85997, QTBUG-97110) + // calling mkpath on an existing drive name (Windows) or root path (macOS) shall pass + QVERIFY(QDir().mkpath(QDir::rootPath())); + QVERIFY(!QDir().mkdir(QDir::rootPath())); // Remove the directory and create a file with the same path QDir::current().rmdir(dirName);