From fd1066ad412cc2568a7055951224063d748aeabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Matysiak?= Date: Tue, 11 Jun 2024 16:13:07 +0200 Subject: [PATCH] Force requested permissions when calling mkdir on VxWorks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling mkdir with mode == 0 works just fine on Linux - it creates a directory and the permissions are set to 0. On VxWorks, calling mkdir with mode == 0 uses the default mode set in the system. This leads to a failing test (tst_QDir::mkdirWithPermissions(0000)) and potential confusion when the same code does not behave in the same way when called on Linux and VxWorks. To keep the same interface between unix-like systems, explicitly set the permissions to 0 when on VxWorks. Pick-to: 6.7 Task-number: QTBUG-115777 Change-Id: I75e429c086500cb7c19f9bb14693bb4266e18046 Reviewed-by: Thiago Macieira Reviewed-by: Michał Łoś (cherry picked from commit 90e79aea8e3f297de65a69d4e6c82a5d753b9c86) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemengine_unix.cpp | 27 ++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 2eb2909919d..0ca32a6b9f4 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -157,6 +157,15 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e } #endif +#ifdef Q_OS_VXWORKS +static inline void forceRequestedPermissionsOnVxWorks(QByteArray dirName, mode_t mode) +{ + if (mode == 0) { + chmod(dirName, 0); + } +} +#endif + namespace { namespace GetFileTimes { qint64 time_t_toMsecs(time_t t) @@ -1078,8 +1087,12 @@ static bool createDirectoryWithParents(const QByteArray &nativeName, mode_t mode return QT_STAT(nativeName.constData(), &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR; }; - if (shouldMkdirFirst && QT_MKDIR(nativeName, mode) == 0) + if (shouldMkdirFirst && QT_MKDIR(nativeName, mode) == 0) { +#ifdef Q_OS_VXWORKS + forceRequestedPermissionsOnVxWorks(nativeName, mode); +#endif return true; + } if (errno == EISDIR) return true; if (errno == EEXIST || errno == EROFS) @@ -1097,8 +1110,12 @@ static bool createDirectoryWithParents(const QByteArray &nativeName, mode_t mode return false; // try again - if (QT_MKDIR(nativeName, mode) == 0) + if (QT_MKDIR(nativeName, mode) == 0) { +#ifdef Q_OS_VXWORKS + forceRequestedPermissionsOnVxWorks(nativeName, mode); +#endif return true; + } return errno == EEXIST && isDir(nativeName); } @@ -1115,8 +1132,12 @@ bool QFileSystemEngine::createDirectory(const QFileSystemEntry &entry, bool crea // try to mkdir this directory mode_t mode = permissions ? QtPrivate::toMode_t(*permissions) : 0777; - if (QT_MKDIR(dirName, mode) == 0) + if (QT_MKDIR(dirName, mode) == 0) { +#ifdef Q_OS_VXWORKS + forceRequestedPermissionsOnVxWorks(dirName, mode); +#endif return true; + } if (!createParents) return false;