From 0568511e84fb030791842dabceb64d46a044e36c Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Fri, 20 Sep 2024 08:13:00 +0200 Subject: [PATCH] wasm: Make sure QDir::mkpath("/") works on webassembly As described in bug QTBUG-127767 mkdir("/") returns ENOSPC on webassembly, and the code is not prepared to handle that. We solve it by explicitly checking for "/" which shall always be present. Fixes: QTBUG-127767 Change-Id: Icf86f0b681ac3bd8ddc97c1a4168c2faf02aa4a1 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_unix.cpp | 5 +++++ tests/auto/corelib/io/qdir/tst_qdir.cpp | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 4fa4af82f29..abcc82dd408 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1078,6 +1078,11 @@ bool QFileSystemEngine::cloneFile(int srcfd, int dstfd, const QFileSystemMetaDat static bool createDirectoryWithParents(const QByteArray &nativeName, mode_t mode, bool shouldMkdirFirst = true) { +#ifdef Q_OS_WASM + if (nativeName.length() == 1 && nativeName[0] == '/') + return true; +#endif + // helper function to check if a given path is a directory, since mkdir can // fail if the dir already exists (it may have been created by another // thread or another process) diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 892d442739f..da83ca898a0 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -522,9 +522,6 @@ void tst_QDir::makedirReturnCode() // 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 -#ifdef Q_OS_WASM - QEXPECT_FAIL("", "fails on wasm, see bug QTBUG-127767", Continue); -#endif QVERIFY(QDir().mkpath(QDir::rootPath())); QVERIFY(!QDir().mkdir(QDir::rootPath()));