QtBase  v6.3.1
qfilesystemengine_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QFILESYSTEMENGINE_P_H
41 #define QFILESYSTEMENGINE_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include "qfile.h"
55 #include "qfilesystementry_p.h"
56 #include "qfilesystemmetadata_p.h"
57 #include <QtCore/private/qsystemerror_p.h>
58 
59 #include <optional>
60 
62 
63 #define Q_RETURN_ON_INVALID_FILENAME(message, result) \
64  { \
65  QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning(message); \
66  errno = EINVAL; \
67  return (result); \
68  }
69 
70 inline bool qIsFilenameBroken(const QByteArray &name)
71 {
72  return name.contains('\0');
73 }
74 
75 inline bool qIsFilenameBroken(const QString &name)
76 {
77  return name.contains(QLatin1Char('\0'));
78 }
79 
81 {
82  return qIsFilenameBroken(entry.nativeFilePath());
83 }
84 
85 #define Q_CHECK_FILE_NAME(name, result) \
86  do { \
87  if (Q_UNLIKELY((name).isEmpty())) \
88  Q_RETURN_ON_INVALID_FILENAME("Empty filename passed to function", (result)); \
89  if (Q_UNLIKELY(qIsFilenameBroken(name))) \
90  Q_RETURN_ON_INVALID_FILENAME("Broken filename passed to function", (result)); \
91  } while (false)
92 
94 {
95 public:
96  static bool isCaseSensitive()
97  {
98 #ifndef Q_OS_WIN
99  return true;
100 #else
101  return false;
102 #endif
103  }
104 
105  static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data);
106  static QFileSystemEntry getJunctionTarget(const QFileSystemEntry &link, QFileSystemMetaData &data);
107  static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
108  static QFileSystemEntry absoluteName(const QFileSystemEntry &entry);
109  static QByteArray id(const QFileSystemEntry &entry);
110  static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
111  static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
112 
113 #if defined(Q_OS_UNIX)
114  static QString resolveUserName(uint userId);
115  static QString resolveGroupName(uint groupId);
116 #endif
117 
118 #if defined(Q_OS_DARWIN)
119  static QString bundleName(const QFileSystemEntry &entry);
120 #else
121  static QString bundleName(const QFileSystemEntry &) { return QString(); }
122 #endif
123 
124  static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data,
126 #if defined(Q_OS_UNIX)
127  static bool cloneFile(int srcfd, int dstfd, const QFileSystemMetaData &knownData);
128  static bool fillMetaData(int fd, QFileSystemMetaData &data); // what = PosixStatFlags
129  static QByteArray id(int fd);
130  static bool setFileTime(int fd, const QDateTime &newDate,
132  static bool setPermissions(int fd, QFile::Permissions permissions, QSystemError &error,
133  QFileSystemMetaData *data = nullptr);
134 #endif
135 #if defined(Q_OS_WIN)
136  static QFileSystemEntry junctionTarget(const QFileSystemEntry &link, QFileSystemMetaData &data);
137  static bool uncListSharesOnServer(const QString &server, QStringList *list); //Used also by QFSFileEngineIterator::hasNext()
138  static bool fillMetaData(int fd, QFileSystemMetaData &data,
140  static bool fillMetaData(HANDLE fHandle, QFileSystemMetaData &data,
142  static bool fillPermissions(const QFileSystemEntry &entry, QFileSystemMetaData &data,
144  static QByteArray id(HANDLE fHandle);
145  static bool setFileTime(HANDLE fHandle, const QDateTime &newDate,
148  static QString nativeAbsoluteFilePath(const QString &path);
149  static bool isDirPath(const QString &path, bool *existed);
150 #endif
151  //homePath, rootPath and tempPath shall return clean paths
152  static QString homePath();
153  static QString rootPath();
154  static QString tempPath();
155 
156  static bool createDirectory(const QFileSystemEntry &entry, bool createParents,
157  std::optional<QFile::Permissions> permissions = std::nullopt);
158  static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents);
159 
160  static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
161 
162  static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
163  static bool moveFileToTrash(const QFileSystemEntry &source, QFileSystemEntry &newLocation, QSystemError &error);
164  static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
165  static bool renameOverwriteFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
166  static bool removeFile(const QFileSystemEntry &entry, QSystemError &error);
167 
168  static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error,
169  QFileSystemMetaData *data = nullptr);
170 
171  // unused, therefore not implemented
172  static bool setFileTime(const QFileSystemEntry &entry, const QDateTime &newDate,
174 
175  static bool setCurrentPath(const QFileSystemEntry &entry);
176  static QFileSystemEntry currentPath();
177 
178  static QAbstractFileEngine *resolveEntryAndCreateLegacyEngine(QFileSystemEntry &entry,
180 private:
181  static QString slowCanonicalized(const QString &path);
182 #if defined(Q_OS_WIN)
183  static void clearWinStatData(QFileSystemMetaData &data);
184 #endif
185 };
186 
188 
189 #endif // include guard
FT_Error error
Definition: cffdrivr.c:657
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QDateTime class provides date and time functions.
Definition: qdatetime.h:238
static QString bundleName(const QFileSystemEntry &)
static bool isCaseSensitive()
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
void * HANDLE
Definition: qnamespace.h:1561
#define QString()
Definition: parse-defines.h:51
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
bool qIsFilenameBroken(const QByteArray &name)
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:579
unsigned int uint
Definition: qglobal.h:334
MetaDataFlags
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum target
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint64 GLenum GLint fd
GLuint name
GLsizei GLsizei GLchar * source
GLuint entry
Definition: qopenglext.h:11002
GLsizei const GLchar *const * path
Definition: qopenglext.h:4283
bool createDirectory(const QString &directory, QString *errorMessage)
Definition: utils.cpp:87
QStringList list
[0]
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:53