From d594fbf12a59a7ddf592cff406d941ca40134d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Matysiak?= Date: Tue, 4 Jun 2024 16:03:44 +0200 Subject: [PATCH] Make createDirectoryWithParents return true for existing dirs on read only fs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the filesystem is mounted in a read only mode, Linux returns true on an attempt to create a dir that already exists on that fs. However not every platform behaves that way. VxWorks is not a fully unix-like system. It is possible to enable a component that provides a virtual root file system (VRFS) so that devices and paths can be managed using "/" as a root. The root itself is not an actual path that can be used like on other systems. It is not possible to store files directly in "/". On Linux, mkdir on "/" returns EEXIST. On VxWorks, it returns EROFS (read only file system). That leads to a failing test (tst_QDir::makedirReturnCode). It also leads to a broken contract, since the doc for QDir::mkpath states that: `If the path already exists when this function is called, it will return true.` The doc for createDirectoryWithParents has no such comment and it is used by other functions that also do not promise such things, but the implementation behaves that way anyway: when errno == EEXIST -> return true if the target path is an existing directory. Since the existing unix implementation already returns true for existing dirs (without checking if it was called in the context of `mkpath` or any other function), fix the problem by checking if errno == EROFS after a call to mkdir and then checking if the target path already exists and is a directory Pick-to: 6.7 Task-number: QTBUG-115777 Change-Id: I849bca56618bf675933cccc5a9d5313e0014628b Reviewed-by: Thiago Macieira Reviewed-by: Karim Pinter Reviewed-by: Jarno Lämsä (cherry picked from commit 8915ae3a75c4a356d94962dd9b31e1458f2a506f) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemengine_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index fb48f22bc6c..2eb2909919d 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -1082,7 +1082,7 @@ static bool createDirectoryWithParents(const QByteArray &nativeName, mode_t mode return true; if (errno == EISDIR) return true; - if (errno == EEXIST) + if (errno == EEXIST || errno == EROFS) return isDir(nativeName); if (errno != ENOENT) return false;