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
59QT_BEGIN_NAMESPACE
60
61#define Q_RETURN_ON_INVALID_FILENAME(message, result) \
62 { \
63 QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning(message); \
64 errno = EINVAL; \
65 return (result); \
66 }
67
68inline bool qIsFilenameBroken(const QByteArray &name)
69{
70 return name.contains(c: '\0');
71}
72
73inline bool qIsFilenameBroken(const QString &name)
74{
75 return name.contains(c: QLatin1Char('\0'));
76}
77
78inline bool qIsFilenameBroken(const QFileSystemEntry &entry)
79{
80 return qIsFilenameBroken(name: entry.nativeFilePath());
81}
82
83#define Q_CHECK_FILE_NAME(name, result) \
84 do { \
85 if (Q_UNLIKELY((name).isEmpty())) \
86 Q_RETURN_ON_INVALID_FILENAME("Empty filename passed to function", (result)); \
87 if (Q_UNLIKELY(qIsFilenameBroken(name))) \
88 Q_RETURN_ON_INVALID_FILENAME("Broken filename passed to function", (result)); \
89 } while (false)
90
91class Q_AUTOTEST_EXPORT QFileSystemEngine
92{
93public:
94 static bool isCaseSensitive()
95 {
96#ifndef Q_OS_WIN
97 return true;
98#else
99 return false;
100#endif
101 }
102
103 static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data);
104 static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
105 static QFileSystemEntry absoluteName(const QFileSystemEntry &entry);
106 static QByteArray id(const QFileSystemEntry &entry);
107 static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
108 static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data);
109
110#if defined(Q_OS_UNIX)
111 static QString resolveUserName(uint userId);
112 static QString resolveGroupName(uint groupId);
113#endif
114
115#if defined(Q_OS_DARWIN)
116 static QString bundleName(const QFileSystemEntry &entry);
117#else
118 static QString bundleName(const QFileSystemEntry &entry) { Q_UNUSED(entry) return QString(); }
119#endif
120
121 static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data,
122 QFileSystemMetaData::MetaDataFlags what);
123#if defined(Q_OS_UNIX)
124 static bool cloneFile(int srcfd, int dstfd, const QFileSystemMetaData &knownData);
125 static bool fillMetaData(int fd, QFileSystemMetaData &data); // what = PosixStatFlags
126 static QByteArray id(int fd);
127 static bool setFileTime(int fd, const QDateTime &newDate,
128 QAbstractFileEngine::FileTime whatTime, QSystemError &error);
129 static bool setPermissions(int fd, QFile::Permissions permissions, QSystemError &error,
130 QFileSystemMetaData *data = nullptr);
131#endif
132#if defined(Q_OS_WIN)
133
134 static bool uncListSharesOnServer(const QString &server, QStringList *list); //Used also by QFSFileEngineIterator::hasNext()
135 static bool fillMetaData(int fd, QFileSystemMetaData &data,
136 QFileSystemMetaData::MetaDataFlags what);
137 static bool fillMetaData(HANDLE fHandle, QFileSystemMetaData &data,
138 QFileSystemMetaData::MetaDataFlags what);
139 static bool fillPermissions(const QFileSystemEntry &entry, QFileSystemMetaData &data,
140 QFileSystemMetaData::MetaDataFlags what);
141 static QByteArray id(HANDLE fHandle);
142 static bool setFileTime(HANDLE fHandle, const QDateTime &newDate,
143 QAbstractFileEngine::FileTime whatTime, QSystemError &error);
144 static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own);
145 static QString nativeAbsoluteFilePath(const QString &path);
146#endif
147 //homePath, rootPath and tempPath shall return clean paths
148 static QString homePath();
149 static QString rootPath();
150 static QString tempPath();
151
152 static bool createDirectory(const QFileSystemEntry &entry, bool createParents);
153 static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents);
154
155 static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
156
157 static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
158 static bool moveFileToTrash(const QFileSystemEntry &source, QFileSystemEntry &newLocation, QSystemError &error);
159 static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
160 static bool renameOverwriteFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error);
161 static bool removeFile(const QFileSystemEntry &entry, QSystemError &error);
162
163 static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error,
164 QFileSystemMetaData *data = nullptr);
165
166 // unused, therefore not implemented
167 static bool setFileTime(const QFileSystemEntry &entry, const QDateTime &newDate,
168 QAbstractFileEngine::FileTime whatTime, QSystemError &error);
169
170 static bool setCurrentPath(const QFileSystemEntry &entry);
171 static QFileSystemEntry currentPath();
172
173 static QAbstractFileEngine *resolveEntryAndCreateLegacyEngine(QFileSystemEntry &entry,
174 QFileSystemMetaData &data);
175private:
176 static QString slowCanonicalized(const QString &path);
177#if defined(Q_OS_WIN)
178 static void clearWinStatData(QFileSystemMetaData &data);
179#endif
180};
181
182QT_END_NAMESPACE
183
184#endif // include guard
185

source code of qtbase/src/corelib/io/qfilesystemengine_p.h