diff options
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 11 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_win.cpp | 13 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdir/tst_qdir.cpp | 18 |
3 files changed, 29 insertions, 13 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index b18e32b29a..a7517b4c7f 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -510,11 +510,12 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea } if (slash) { const QByteArray chunk = QFile::encodeName(dirName.left(slash)); - QT_STATBUF st; - if (QT_STAT(chunk.constData(), &st) != -1) { - if ((st.st_mode & S_IFMT) != S_IFDIR) - return false; - } else if (QT_MKDIR(chunk.constData(), 0777) != 0) { + if (QT_MKDIR(chunk.constData(), 0777) != 0) { + if (errno == EEXIST) { + QT_STATBUF st; + if (QT_STAT(chunk.constData(), &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR) + continue; + } return false; } } diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index bee7689535..fdbd6e01e4 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -1044,14 +1044,13 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea } if (slash) { QString chunk = dirName.left(slash); - bool existed = false; - if (!isDirPath(chunk, &existed)) { - if (!existed) { - if (!mkDir(chunk)) - return false; - } else { - return false; + if (!mkDir(chunk)) { + if (GetLastError() == ERROR_ALREADY_EXISTS) { + bool existed = false; + if (isDirPath(chunk, &existed) && existed) + continue; } + return false; } } } diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index d44ef167b5..fbb21e4e9a 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -311,12 +311,28 @@ void tst_QDir::mkdir() void tst_QDir::makedirReturnCode() { QString dirName = QString::fromLatin1("makedirReturnCode"); - QDir::current().rmdir(dirName); // cleanup a previous run. + QFile f(QDir::current().filePath(dirName)); + + // cleanup a previous run. + f.remove(); + QDir::current().rmdir(dirName); + QDir dir(dirName); QVERIFY(!dir.exists()); QVERIFY(QDir::current().mkdir(dirName)); 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 + + // Remove the directory and create a file with the same path + QDir::current().rmdir(dirName); + QVERIFY(!f.exists()); + f.open(QIODevice::WriteOnly); + f.write("test"); + f.close(); + QVERIFY(f.exists()); + QVERIFY(!QDir::current().mkdir(dirName)); // calling mkdir on an existing file will fail. + QVERIFY(!QDir::current().mkpath(dirName)); // calling mkpath on an existing file will fail. + f.remove(); } void tst_QDir::rmdir_data() |