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 <thiago.macieira@intel.com>
This commit is contained in:
Even Oscar Andersen 2024-09-20 08:13:00 +02:00
parent cda53f290f
commit 0568511e84
2 changed files with 5 additions and 3 deletions

View File

@ -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)

View File

@ -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()));