diff options
Diffstat (limited to 'src/corelib/io/qfile.h')
-rw-r--r-- | src/corelib/io/qfile.h | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h index 53b69dd8b1..058b2fa236 100644 --- a/src/corelib/io/qfile.h +++ b/src/corelib/io/qfile.h @@ -11,7 +11,7 @@ #if QT_CONFIG(cxx17_filesystem) #include <filesystem> -#elif defined(Q_CLANG_QDOC) +#elif defined(Q_QDOC) namespace std { namespace filesystem { class path { @@ -26,6 +26,34 @@ namespace std { QT_BEGIN_NAMESPACE +#if defined(Q_OS_WIN) || defined(Q_QDOC) + +#if QT_DEPRECATED_SINCE(6,6) +QT_DEPRECATED_VERSION_X_6_6("Use QNtfsPermissionCheckGuard RAII class instead.") +Q_CORE_EXPORT extern int qt_ntfs_permission_lookup; // defined in qfilesystemengine_win.cpp +#endif + +Q_CORE_EXPORT bool qEnableNtfsPermissionChecks() noexcept; +Q_CORE_EXPORT bool qDisableNtfsPermissionChecks() noexcept; +Q_CORE_EXPORT bool qAreNtfsPermissionChecksEnabled() noexcept; + +class QNtfsPermissionCheckGuard +{ + Q_DISABLE_COPY_MOVE(QNtfsPermissionCheckGuard) +public: + Q_NODISCARD_CTOR + QNtfsPermissionCheckGuard() + { + qEnableNtfsPermissionChecks(); + } + + ~QNtfsPermissionCheckGuard() + { + qDisableNtfsPermissionChecks(); + } +}; +#endif // Q_OS_WIN + #if QT_CONFIG(cxx17_filesystem) namespace QtPrivate { inline QString fromFilesystemPath(const std::filesystem::path &path) @@ -54,6 +82,13 @@ using ForceFilesystemPath = typename std::enable_if_t<std::is_same_v<std::filesy class QTemporaryFile; class QFilePrivate; +// ### Qt 7: remove this, and make constructors always explicit. +#if (QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)) || defined(QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH) +# define QFILE_MAYBE_EXPLICIT explicit +#else +# define QFILE_MAYBE_EXPLICIT Q_IMPLICIT +#endif + class Q_CORE_EXPORT QFile : public QFileDevice { #ifndef QT_NO_QOBJECT @@ -63,12 +98,12 @@ class Q_CORE_EXPORT QFile : public QFileDevice public: QFile(); - QFile(const QString &name); -#ifdef Q_CLANG_QDOC - QFile(const std::filesystem::path &name); + QFILE_MAYBE_EXPLICIT QFile(const QString &name); +#ifdef Q_QDOC + QFILE_MAYBE_EXPLICIT QFile(const std::filesystem::path &name); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> - QFile(const T &name) : QFile(QtPrivate::fromFilesystemPath(name)) + QFILE_MAYBE_EXPLICIT QFile(const T &name) : QFile(QtPrivate::fromFilesystemPath(name)) { } #endif // QT_CONFIG(cxx17_filesystem) @@ -77,7 +112,7 @@ public: explicit QFile(QObject *parent); QFile(const QString &name, QObject *parent); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC QFile(const std::filesystem::path &path, QObject *parent); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> @@ -89,12 +124,12 @@ public: ~QFile(); QString fileName() const override; -#if QT_CONFIG(cxx17_filesystem) || defined(Q_CLANG_QDOC) +#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC) std::filesystem::path filesystemFileName() const { return QtPrivate::toFilesystemPath(fileName()); } #endif void setFileName(const QString &name); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC void setFileName(const std::filesystem::path &name); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> @@ -136,7 +171,7 @@ public: bool exists() const; static bool exists(const QString &fileName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC static bool exists(const std::filesystem::path &fileName); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> @@ -148,7 +183,7 @@ public: QString symLinkTarget() const; static QString symLinkTarget(const QString &fileName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC std::filesystem::path filesystemSymLinkTarget() const; static std::filesystem::path filesystemSymLinkTarget(const std::filesystem::path &fileName); #elif QT_CONFIG(cxx17_filesystem) @@ -165,7 +200,7 @@ public: bool remove(); static bool remove(const QString &fileName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC static bool remove(const std::filesystem::path &fileName); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> @@ -177,7 +212,7 @@ public: bool moveToTrash(); static bool moveToTrash(const QString &fileName, QString *pathInTrash = nullptr); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC static bool moveToTrash(const std::filesystem::path &fileName, QString *pathInTrash = nullptr); #elif QT_CONFIG(cxx17_filesystem) template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> @@ -189,7 +224,7 @@ public: bool rename(const QString &newName); static bool rename(const QString &oldName, const QString &newName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC bool rename(const std::filesystem::path &newName); static bool rename(const std::filesystem::path &oldName, const std::filesystem::path &newName); @@ -209,7 +244,7 @@ public: bool link(const QString &newName); static bool link(const QString &fileName, const QString &newName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC bool link(const std::filesystem::path &newName); static bool link(const std::filesystem::path &fileName, const std::filesystem::path &newName); @@ -229,7 +264,7 @@ public: bool copy(const QString &newName); static bool copy(const QString &fileName, const QString &newName); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC bool copy(const std::filesystem::path &newName); static bool copy(const std::filesystem::path &fileName, const std::filesystem::path &newName); @@ -247,10 +282,10 @@ public: } #endif // QT_CONFIG(cxx17_filesystem) - bool open(OpenMode flags) override; - bool open(OpenMode flags, Permissions permissions); - bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); - bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); + QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override; + QFILE_MAYBE_NODISCARD bool open(OpenMode flags, Permissions permissions); + QFILE_MAYBE_NODISCARD bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); + QFILE_MAYBE_NODISCARD bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); qint64 size() const override; @@ -261,7 +296,7 @@ public: static Permissions permissions(const QString &filename); bool setPermissions(Permissions permissionSpec) override; static bool setPermissions(const QString &filename, Permissions permissionSpec); -#ifdef Q_CLANG_QDOC +#ifdef Q_QDOC static Permissions permissions(const std::filesystem::path &filename); static bool setPermissions(const std::filesystem::path &filename, Permissions permissionSpec); #elif QT_CONFIG(cxx17_filesystem) |