diff options
author | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2021-11-10 16:52:07 +0100 |
---|---|---|
committer | Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> | 2021-11-26 03:39:33 +0100 |
commit | 174af05400f6344a11f4aa2228244c954cbbca97 (patch) | |
tree | df5edd252f5d0bd4b865c3ace2473fbbfb80d087 /src/corelib/io/qdir.cpp | |
parent | 8c9875893bbd7b1355e36d9501d8cb1f84cb6b4d (diff) |
QDir: Add support for setting directory permissions to mkdir()
This patch adds an overload of the QDir::mkdir() method that
accepts permissions. This allows setting of the directory
permissions at the time of its creation.
[ChangeLog][QtCore][QDir] Added QDir::mdkir() overload that
accepts permissions argument.
Task-number: QTBUG-79750
Change-Id: Ic9db723b94ff0d2da6e0b819ac2e5d1f9a4e2049
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/io/qdir.cpp')
-rw-r--r-- | src/corelib/io/qdir.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index fb34aa7382..9d540b2581 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1445,9 +1445,42 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter Returns \c true on success; otherwise returns \c false. - If the directory already exists when this function is called, it will return false. + If the directory already exists when this function is called, it will return \c false. + + The permissions of the created directory are set to \a{permissions}. + + On POSIX systems the permissions are influenced by the value of \c umask. + + On Windows the permissions are emulated using ACLs. These ACLs may be in non-canonical + order when the group is granted less permissions than others. Files and directories with + such permissions will generate warnings when the Security tab of the Properties dialog + is opened. Granting the group all permissions granted to others avoids such warnings. \sa rmdir() + + \since 6.3 +*/ +bool QDir::mkdir(const QString &dirName, QFile::Permissions permissions) const +{ + const QDirPrivate *d = d_ptr.constData(); + + if (dirName.isEmpty()) { + qWarning("QDir::mkdir: Empty or null file name"); + return false; + } + + QString fn = filePath(dirName); + if (!d->fileEngine) + return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false, permissions); + return d->fileEngine->mkdir(fn, false, permissions); +} + +/*! + \overload + Creates a sub-directory called \a dirName with default permissions. + + On POSIX systems the default is to grant all permissions allowed by \c umask. + On Windows, the new directory inherits its permissions from its parent directory. */ bool QDir::mkdir(const QString &dirName) const { |