OSDN Git Service

implement specialized QAbstractFileEngine methods to fix enums overlapping
authorIvailo Monev <xakepa10@gmail.com>
Sun, 30 Oct 2022 05:24:26 +0000 (07:24 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 30 Oct 2022 05:27:16 +0000 (07:27 +0200)
some QFileSystemMetaData enums overlap with QFile::Permissions still but
that is on purpose

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qabstractfileengine.cpp
src/core/io/qabstractfileengine.h
src/core/io/qfile.cpp
src/core/io/qfilesystemengine_unix.cpp
src/core/io/qfilesystemmetadata_p.h
src/core/io/qtemporaryfile.cpp

index 82f5757..db09e0a 100644 (file)
@@ -172,55 +172,6 @@ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName)
 */
 
 /*!
-    \enum QAbstractFileEngine::FileFlag
-
-    The permissions and types of a file, suitable for OR'ing together.
-
-    \value ReadOwnerPerm The owner of the file has permission to read
-    it.
-    \value WriteOwnerPerm The owner of the file has permission to
-    write to it.
-    \value ExeOwnerPerm The owner of the file has permission to
-    execute it.
-    \value ReadUserPerm The current user has permission to read the
-    file.
-    \value WriteUserPerm The current user has permission to write to
-    the file.
-    \value ExeUserPerm The current user has permission to execute the
-    file.
-    \value ReadGroupPerm Members of the current user's group have
-    permission to read the file.
-    \value WriteGroupPerm Members of the current user's group have
-    permission to write to the file.
-    \value ExeGroupPerm Members of the current user's group have
-    permission to execute the file.
-    \value ReadOtherPerm All users have permission to read the file.
-    \value WriteOtherPerm All users have permission to write to the
-    file.
-    \value ExeOtherPerm All users have permission to execute the file.
-
-    \value LinkType The file is a link to another file (or link) in
-    the file system (i.e. not a file or directory).
-    \value FileType The file is a regular file to the file system
-    (i.e. not a link or directory)
-    \value DirectoryType The file is a directory in the file system
-    (i.e. not a link or file).
-
-    \value HiddenFlag The file is hidden.
-    \value ExistsFlag The file actually exists in the file system.
-    \value RootFlag  The file or the file pointed to is the root of the filesystem.
-    \value LocalDiskFlag The file resides on the local disk and can be passed to standard file functions.
-    \value Refresh Passing this flag will force the file engine to refresh all flags.
-
-    \omitvalue PermsMask
-    \omitvalue TypesMask
-    \omitvalue FlagsMask
-    \omitvalue FileInfoAll
-
-    \sa fileFlags(), setFileName()
-*/
-
-/*!
     \enum QAbstractFileEngine::FileTime
 
     These are used by the fileTime() function.
@@ -427,6 +378,7 @@ qint64 QAbstractFileEngine::size() const
 {
     Q_D(const QAbstractFileEngine);
 
+    d->metaData.clear();
     if (!d->doStat(QFileSystemMetaData::SizeAttribute))
         return 0;
     return d->metaData.size();
@@ -584,7 +536,7 @@ bool QAbstractFileEngine::setSize(qint64 size)
     relative path; otherwise return false.
 
     \sa setFileName()
- */
+*/
 bool QAbstractFileEngine::isRelativePath() const
 {
     Q_D(const QAbstractFileEngine);
@@ -592,67 +544,30 @@ bool QAbstractFileEngine::isRelativePath() const
 }
 
 /*!
-    Return the set of OR'd flags that are true for the file engine's
-    file, and that are in the \a type's OR'd members.
-
-    \sa setFileName()
+    Return true if the file referred to by this file engine exists;
+    otherwise return false.
 */
-QAbstractFileEngine::FileFlags QAbstractFileEngine::fileFlags(FileFlags type) const
+bool QAbstractFileEngine::exists() const
 {
     Q_D(const QAbstractFileEngine);
+    d->metaData.clear(); // always stat
+    if (!d->doStat(QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::FileType))
+        return false;
+    return d->metaData.exists() && d->metaData.isFile();
+}
 
-    if (type & Refresh)
-        d->metaData.clear();
-
-    QAbstractFileEngine::FileFlags ret = 0;
-
-    if (type & FlagsMask)
-        ret |= LocalDiskFlag;
-
-    QFileSystemMetaData::MetaDataFlags queryFlags =
-            QFileSystemMetaData::MetaDataFlags(uint(type))
-            & QFileSystemMetaData::Permissions;
-    queryFlags |= QFileSystemMetaData::LinkType;
-
-    if (type & TypesMask)
-        queryFlags |= QFileSystemMetaData::LinkType
-                | QFileSystemMetaData::FileType
-                | QFileSystemMetaData::DirectoryType;
-
-    if (type & FlagsMask)
-        queryFlags |= QFileSystemMetaData::HiddenAttribute
-                | QFileSystemMetaData::ExistsAttribute;
-
-    bool exists = d->doStat(queryFlags);
+/*!
+    Return the set of permissions for the file engine's file.
 
+    \sa setFileName()
+*/
+QFile::Permissions QAbstractFileEngine::permissions() const
+{
+    Q_D(const QAbstractFileEngine);
+    bool exists = d->doStat(QFileSystemMetaData::Permissions | QFileSystemMetaData::LinkType);
     if (!exists && !d->metaData.isLink())
-        return ret;
-
-    if (exists && (type & PermsMask))
-        ret |= FileFlags(uint(d->metaData.permissions()));
-
-    if (type & TypesMask) {
-        if ((type & LinkType) && d->metaData.isLink())
-            ret |= LinkType;
-        if (exists) {
-            if (d->metaData.isFile()) {
-                ret |= FileType;
-            } else if (d->metaData.isDirectory()) {
-                ret |= DirectoryType;
-            }
-        }
-    }
-
-    if (type & FlagsMask) {
-        if (exists)
-            ret |= ExistsFlag;
-        if (d->fileEntry.isRoot())
-            ret |= RootFlag;
-        else if (d->metaData.isHidden())
-            ret |= HiddenFlag;
-    }
-
-    return ret;
+        return 0;
+    return d->metaData.permissions();
 }
 
 /*!
index e3a2a29..4e9ae24 100644 (file)
@@ -22,7 +22,8 @@
 #ifndef QABSTRACTFILEENGINE_H
 #define QABSTRACTFILEENGINE_H
 
-#include <QtCore/qdir.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qdatetime.h>
 
 #ifdef open
 #error qabstractfileengine.h must be included before any header file that defines open
@@ -35,33 +36,6 @@ class QAbstractFileEnginePrivate;
 class Q_CORE_EXPORT QAbstractFileEngine
 {
 public:
-    enum FileFlag {
-        //perms (overlaps the QFile::Permission)
-        ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
-        ReadUserPerm  = 0x0400, WriteUserPerm  = 0x0200, ExeUserPerm  = 0x0100,
-        ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
-        ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
-
-        //types
-        LinkType      = 0x10000,
-        FileType      = 0x20000,
-        DirectoryType = 0x40000,
-
-        //flags
-        HiddenFlag     = 0x0100000,
-        LocalDiskFlag  = 0x0200000,
-        ExistsFlag     = 0x0400000,
-        RootFlag       = 0x0800000,
-        Refresh        = 0x1000000,
-
-        //masks
-        PermsMask  = 0x0000FFFF,
-        TypesMask  = 0x000F0000,
-        FlagsMask  = 0x0FF00000,
-        FileInfoAll = FlagsMask | PermsMask | TypesMask
-    };
-    Q_DECLARE_FLAGS(FileFlags, FileFlag)
-
     enum FileName {
         DefaultName,
         BaseName,
@@ -98,7 +72,8 @@ public:
     bool link(const QString &newName);
     bool setSize(qint64 size);
     bool isRelativePath() const;
-    FileFlags fileFlags(FileFlags type) const;
+    bool exists() const;
+    QFile::Permissions permissions() const;
     bool setPermissions(uint perms);
     QString fileName(FileName file) const;
     uint ownerId(FileOwner) const;
@@ -163,7 +138,6 @@ private:
 
     friend class QFilePrivate;
 };
-Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
 
 QT_END_NAMESPACE
 
index 110880f..0387da1 100644 (file)
@@ -418,12 +418,7 @@ QFile::decodeName(const QByteArray &localFileName)
 bool
 QFile::exists() const
 {
-    // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
-    const QAbstractFileEngine::FileFlags flags = fileEngine()->fileFlags(QAbstractFileEngine::Refresh
-        | QAbstractFileEngine::FlagsMask);
-    const QAbstractFileEngine::FileFlags type = fileEngine()->fileFlags(QAbstractFileEngine::Refresh
-        | QAbstractFileEngine::TypesMask);
-    return ((flags & QAbstractFileEngine::ExistsFlag) && (type & QAbstractFileEngine::FileType));
+    return fileEngine()->exists();
 }
 
 /*!
@@ -1008,8 +1003,7 @@ bool QFile::resize(const QString &fileName, qint64 sz)
 
 QFile::Permissions QFile::permissions() const
 {
-    QAbstractFileEngine::FileFlags perms = fileEngine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
-    return QFile::Permissions((int)perms); //ewww
+    return fileEngine()->permissions();
 }
 
 /*!
@@ -1107,9 +1101,7 @@ void QFile::close()
 
 qint64 QFile::size() const
 {
-    Q_D(const QFile);
-    fileEngine()->fileFlags(QAbstractFileEngine::Refresh);
-    return d->fileEngine->size();
+    return fileEngine()->size();
 }
 
 /*!
index 75e3bc1..0981f4c 100644 (file)
@@ -22,6 +22,7 @@
 #include "qplatformdefs.h"
 #include "qfilesystemengine_p.h"
 #include "qfile.h"
+#include "qdir.h"
 #include "qcore_unix_p.h"
 #include "qcorecommon_p.h"
 
index e1c3596..e8416b1 100644 (file)
@@ -82,15 +82,15 @@ public:
         LinkType            = 0x00010000,
         FileType            = 0x00020000,
         DirectoryType       = 0x00040000,
-        SequentialType      = 0x00800000,   // Note: overlaps with QAbstractFileEngine::RootFlag
+        SequentialType      = 0x00800000,
 
         // Attributes
         HiddenAttribute     = 0x00100000,
-        SizeAttribute       = 0x00200000,   // Note: overlaps with QAbstractFileEngine::LocalDiskFlag
+        SizeAttribute       = 0x00200000,
         ExistsAttribute     = 0x00400000,
 
         // Times
-        CreationTime        = 0x01000000,   // Note: overlaps with QAbstractFileEngine::Refresh
+        CreationTime        = 0x01000000,
         ModificationTime    = 0x02000000,
         AccessTime          = 0x04000000,
 
index 689e5e1..a9a1046 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef QT_NO_TEMPORARYFILE
 
 #include "qplatformdefs.h"
+#include "qdir.h"
 #include "qfile_p.h"
 #include "qabstractfileengine_p.h"
 #include "qfilesystemengine_p.h"