diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2025-01-21 01:26:01 +0200 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2025-02-27 00:12:07 +0200 |
| commit | 4275dfb7bfa78999bb8edf27ab18433f97cd3490 (patch) | |
| tree | 66f731f21441afca4d28c10cc58fb22c9663efad /src/corelib/io/qdir.cpp | |
| parent | 23981aae0e059d876d441bfffae9d9d0fd671bde (diff) | |
QDir: add mkpath/mkdir overloads taking std::optional<Permissions>
std::optional:
- it's already used in private API in QFileSystemEngine and
QAbstractFileEngine and its subclasses, so there is no extra overhead
- less code duplication as it lets the existing overloads call the new
ones with std::nullopt to make it use the platform default permissions
- adding a new enumerator, e.g. "PlatormDefault", wouldn't work:
- 0x0 is ambiguous with setting the permissions to nothing
- the new enumerator mustn't set any other permission bits, so it'll
have to be > std::numeric_limits<short>::max(), which is
potentially BiC as the underlying type of the enum will become int
[ChangeLog][QtCore][QDir] Added mkdir() method that takes a
std::optional<QFile::Permissions>; the new method transparently replaces
the older mkdir() overloads.
[ChangeLog][QtCore][QDir] Added mkpath() method that takes a
std::optional<QFile::Permissions>; this new method transparently
replaces the older mkpath() overload.
Task-number: QTBUG-132633
Change-Id: Ic2cd1e01e6ad1a2b6d3a6180c41b6a0b260a4e55
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdir.cpp')
| -rw-r--r-- | src/corelib/io/qdir.cpp | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 956236f95d5..4945d2b66ff 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1495,8 +1495,13 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter /*! Creates a sub-directory called \a dirName with the given \a permissions. + If \a permissions is \c std::nullopt (the default) this function will + set the default permissions. + Returns \c true on success; returns \c false if the operation failed or - the directory already existed. + \a dirName already existed. + + If \a dirName already existed, this method won't change its permissions. //! [dir-creation-mode-bits-unix] On POSIX systems \a permissions are modified by the @@ -1505,18 +1510,24 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter bits might be disabled. //! [dir-creation-mode-bits-unix] +//! [windows-permissions-acls] On Windows, by default, a new directory inherits its permissions from its parent directory. \a 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. +//! [windows-permissions-acls] - \sa rmdir(), mkpath(), rmpath() + \note Qt 6.10 added the \a permissions parameter. To get the old behavior + (using the default platform-specific permissions) of \c{mkdir(const QString &)} + set \a permissions to \c std::nullopt (the default). This new method also + transparently replaces the \c {mkdir(const QString &, QFile::Permissions)} + overload. - \since 6.3 + \sa rmdir(), mkpath(), rmpath() */ -bool QDir::mkdir(const QString &dirName, QFile::Permissions permissions) const +bool QDir::mkdir(const QString &dirName, std::optional<QFile::Permissions> permissions) const { Q_D(const QDir); @@ -1532,40 +1543,6 @@ bool QDir::mkdir(const QString &dirName, QFile::Permissions permissions) const } /*! - \overload - Creates a sub-directory called \a dirName with the platform-specific - default permissions. - - Returns \c true on success; returns \c false if the operation failed or - the directory already existed. - -//! [windows-permissions-acls] - On Windows, by default, a new directory inherits its permissions from its - parent directory. 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. -//! [windows-permissions-acls] - - \sa rmdir(), mkpath(), rmpath() -*/ -bool QDir::mkdir(const QString &dirName) const -{ - Q_D(const QDir); - - if (dirName.isEmpty()) { - qWarning("QDir::mkdir: Empty or null file name"); - return false; - } - - QString fn = filePath(dirName); - if (!d->fileEngine) - return QFileSystemEngine::mkdir(QFileSystemEntry(fn)); - return d->fileEngine->mkdir(fn, false); -} - -/*! Removes the directory specified by \a dirName. The directory must be empty for rmdir() to succeed. @@ -1594,16 +1571,28 @@ bool QDir::rmdir(const QString &dirName) const Creates a directory named \a dirPath. If \a dirPath doesn't already exist, this method will create it - along with - any nonexistent parent directories - with the default permissions. + any nonexistent parent directories - with \a permissions. + + If \a dirPath already existed, this method won't change its permissions; + the same goes for any already existing parent directories. + + If \a permissions is \c std::nullopt (the default value) this function will + set the default permissions. Returns \c true on success or if \a dirPath already existed; otherwise returns \c false. + \include qdir.cpp dir-creation-mode-bits-unix + \include qdir.cpp windows-permissions-acls + \note Qt 6.10 added the \a permissions parameter. To get the old behavior + (using the default platform-specific permissions) of \c{mkpath(const QString &)} + set \a permissions to \c std::nullopt (the default). + \sa rmpath(), mkdir(), rmdir() */ -bool QDir::mkpath(const QString &dirPath) const +bool QDir::mkpath(const QString &dirPath, std::optional<QFile::Permissions> permissions) const { Q_D(const QDir); @@ -1614,8 +1603,8 @@ bool QDir::mkpath(const QString &dirPath) const QString fn = filePath(dirPath); if (!d->fileEngine) - return QFileSystemEngine::mkpath(QFileSystemEntry(fn)); - return d->fileEngine->mkdir(fn, true); + return QFileSystemEngine::mkpath(QFileSystemEntry(fn), permissions); + return d->fileEngine->mkdir(fn, true, permissions); } /*! |
