Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qfilesystemengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtCore/qdir.h>
6#include <QtCore/qset.h>
7#include <QtCore/qstringbuilder.h>
8#include <QtCore/private/qabstractfileengine_p.h>
9#ifdef QT_BUILD_CORE_LIB
10#include <QtCore/private/qresource_p.h>
11#endif
12#include <QtCore/private/qduplicatetracker_p.h>
13
15
22QString QFileSystemEngine::slowCanonicalized(const QString &path)
23{
24 if (path.isEmpty())
25 return path;
26
28 const QChar slash(u'/');
29 QString tmpPath = path;
30 qsizetype separatorPos = 0;
31 QSet<QString> nonSymlinks;
33
34 (void)known.hasSeen(path);
35 do {
36#ifdef Q_OS_WIN
37 if (separatorPos == 0) {
38 if (tmpPath.size() >= 2 && tmpPath.at(0) == slash && tmpPath.at(1) == slash) {
39 // UNC, skip past the first two elements
40 separatorPos = tmpPath.indexOf(slash, 2);
41 } else if (tmpPath.size() >= 3 && tmpPath.at(1) == u':' && tmpPath.at(2) == slash) {
42 // volume root, skip since it can not be a symlink
43 separatorPos = 2;
44 }
45 }
46 if (separatorPos != -1)
47#endif
48 separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
49 QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
50 if (!nonSymlinks.contains(prefix)) {
51 fi.setFile(prefix);
52 if (fi.isSymLink()) {
54 if (separatorPos != -1) {
55 if (fi.isDir() && !target.endsWith(slash))
56 target.append(slash);
57 target.append(QStringView{tmpPath}.mid(separatorPos));
58 }
59 tmpPath = QDir::cleanPath(target);
60 separatorPos = 0;
61
62 if (known.hasSeen(tmpPath))
63 return QString();
64 } else {
65 nonSymlinks.insert(prefix);
66 }
67 }
68 } while (separatorPos != -1);
69
70 return QDir::cleanPath(tmpPath);
71}
72
73static inline bool _q_checkEntry(QFileSystemEntry &entry, QFileSystemMetaData &data, bool resolvingEntry)
74{
75 if (resolvingEntry) {
77 || !data.exists()) {
78 data.clear();
79 return false;
80 }
81 }
82
83 return true;
84}
85
86static inline bool _q_checkEntry(QAbstractFileEngine *&engine, bool resolvingEntry)
87{
88 if (resolvingEntry) {
90 delete engine;
91 engine = nullptr;
92 return false;
93 }
94 }
95
96 return true;
97}
98
100 QAbstractFileEngine *&engine, bool resolvingEntry = false)
101{
102 QString const &filePath = entry.filePath();
104 return _q_checkEntry(engine, resolvingEntry);
105
106#if defined(QT_BUILD_CORE_LIB)
107 for (qsizetype prefixSeparator = 0; prefixSeparator < filePath.size(); ++prefixSeparator) {
108 QChar const ch = filePath[prefixSeparator];
109 if (ch == u'/')
110 break;
111
112 if (ch == u':') {
113 if (prefixSeparator == 0) {
114 engine = new QResourceFileEngine(filePath);
115 return _q_checkEntry(engine, resolvingEntry);
116 }
117
118 if (prefixSeparator == 1)
119 break;
120
121 const QStringList &paths = QDir::searchPaths(filePath.left(prefixSeparator));
122 for (int i = 0; i < paths.size(); i++) {
124 paths.at(i) % u'/' % QStringView{filePath}.mid(prefixSeparator + 1)));
125 // Recurse!
127 return true;
128 }
129
130 // entry may have been clobbered at this point.
131 return false;
132 }
133
134 // There's no need to fully validate the prefix here. Consulting the
135 // unicode tables could be expensive and validation is already
136 // performed in QDir::setSearchPaths.
137 //
138 // if (!ch.isLetterOrNumber())
139 // break;
140 }
141#endif // defined(QT_BUILD_CORE_LIB)
142
143 return _q_checkEntry(entry, data, resolvingEntry);
144}
145
159 QAbstractFileEngine *engine = nullptr;
160
162 // Reset entry to resolved copy.
163 entry = copy;
164 else
165 data.clear();
166
167 return engine;
168}
169
170//static
172{
173#if defined(Q_OS_WIN)
174 Q_UNUSED(metaData);
175 return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerUser);
176#else //(Q_OS_UNIX)
179 if (!metaData.exists())
180 return QString();
181 return resolveUserName(metaData.userId());
182#endif
183}
184
185//static
187{
188#if defined(Q_OS_WIN)
189 Q_UNUSED(metaData);
190 return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerGroup);
191#else //(Q_OS_UNIX)
194 if (!metaData.exists())
195 return QString();
196 return resolveGroupName(metaData.groupId());
197#endif
198}
199
200//static
203{
204#if defined(Q_OS_WIN)
205 return junctionTarget(link, data);
206#else
207 Q_UNUSED(link);
208 Q_UNUSED(data);
209 return {};
210#endif
211}
212
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qchar.h:48
static QStringList searchPaths(const QString &prefix)
Definition qdir.cpp:1156
static QString cleanPath(const QString &path)
Returns path with directory separators normalized (that is, platform-native separators converted to "...
Definition qdir.cpp:2395
bool hasSeen(const T &s)
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString symLinkTarget() const
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
static QAbstractFileEngine * resolveEntryAndCreateLegacyEngine(QFileSystemEntry &entry, QFileSystemMetaData &data)
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
static QFileSystemEntry getJunctionTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
bool hasFlags(MetaDataFlags flags) const
uint userId() const
uint groupId() const
Definition qset.h:18
bool contains(const T &value) const
Definition qset.h:71
iterator insert(const T &value)
Definition qset.h:155
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:76
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
Definition qstring.cpp:5204
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
QString & append(QChar c)
Definition qstring.cpp:3227
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
Definition qstring.cpp:5161
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4420
Combined button and popup list for selecting options.
QAbstractFileEngine * qt_custom_file_engine_handler_create(const QString &path)
static jboolean copy(JNIEnv *, jobject)
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 void
static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &entry, QFileSystemMetaData &data, QAbstractFileEngine *&engine, bool resolvingEntry=false)
static bool _q_checkEntry(QFileSystemEntry &entry, QFileSystemMetaData &data, bool resolvingEntry)
GLsizei const GLuint * paths
GLenum target
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint entry
GLsizei const GLchar *const * path
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:70
QFileInfo fi("c:/temp/foo")
[newstuff]
QJSEngine engine
[0]