6#include <QtCore/qdir.h>
7#include <QtCore/qset.h>
8#include <QtCore/qstringbuilder.h>
9#include <QtCore/private/qabstractfileengine_p.h>
10#ifdef QT_BUILD_CORE_LIB
11#include <QtCore/private/qresource_p.h>
13#include <QtCore/private/qduplicatetracker_p.h>
18
19
20
21
22
23
24
25
26
27
28
29
30
33
34
35
36
37
38QString QFileSystemEngine::slowCanonicalized(
const QString &path)
44 const QChar slash(u'/');
45 QString tmpPath = path;
46 qsizetype separatorPos = 0;
47 QSet<QString> nonSymlinks;
48 QDuplicateTracker<QString> known;
50 (
void)known.hasSeen(path);
53 if (separatorPos == 0) {
54 if (tmpPath.size() >= 2 && tmpPath.at(0) == slash && tmpPath.at(1) == slash) {
56 separatorPos = tmpPath.indexOf(slash, 2);
57 }
else if (tmpPath.size() >= 3 && tmpPath.at(1) == u':' && tmpPath.at(2) == slash) {
62 if (separatorPos != -1)
64 separatorPos = tmpPath.indexOf(slash, separatorPos + 1);
65 QString prefix = separatorPos == -1 ? tmpPath : tmpPath.left(separatorPos);
66 if (!nonSymlinks.contains(prefix)) {
69 QString target = fi.symLinkTarget();
70 if (separatorPos != -1) {
71 if (fi.isDir() && !target.endsWith(slash))
73 target.append(QStringView{tmpPath}.mid(separatorPos));
75 tmpPath = QDir::cleanPath(target);
78 if (known.hasSeen(tmpPath))
81 nonSymlinks.insert(prefix);
84 }
while (separatorPos != -1);
86 return QDir::cleanPath(tmpPath);
89static inline bool _q_checkEntry(QFileSystemEntry &entry, QFileSystemMetaData &data,
bool resolvingEntry)
92 if (!QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute)
102static inline bool _q_checkEntry(std::unique_ptr<QAbstractFileEngine> &engine,
bool resolvingEntry)
104 if (resolvingEntry) {
105 if (!(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::ExistsFlag)) {
115 std::unique_ptr<QAbstractFileEngine> &engine,
116 bool resolvingEntry =
false)
118 QString
const &filePath = entry.filePath();
119 if ((engine = qt_custom_file_engine_handler_create(filePath)))
120 return _q_checkEntry(engine, resolvingEntry);
122#if defined(QT_BUILD_CORE_LIB)
123 for (qsizetype prefixSeparator = 0; prefixSeparator < filePath.size(); ++prefixSeparator) {
124 QChar
const ch = filePath[prefixSeparator];
129 if (prefixSeparator == 0) {
130 engine = std::make_unique<QResourceFileEngine>(filePath);
131 return _q_checkEntry(engine, resolvingEntry);
134 if (prefixSeparator == 1)
137 const QStringList &paths = QDir::searchPaths(filePath.left(prefixSeparator));
138 for (
int i = 0; i < paths.size(); i++) {
139 entry = QFileSystemEntry(QDir::cleanPath(
140 paths.at(i) % u'/' % QStringView{filePath}.mid(prefixSeparator + 1)));
142 if (_q_createLegacyEngine_recursive(entry, data, engine,
true))
159 return _q_checkEntry(entry, data, resolvingEntry);
165 return QFileSystemEngine::isCaseSensitive(entry, data);
169
170
171
172
173
174
175
176
177
178std::unique_ptr<QAbstractFileEngine>
179QFileSystemEngine::createLegacyEngine(QFileSystemEntry &entry, QFileSystemMetaData &data)
181 QFileSystemEntry copy = entry;
182 std::unique_ptr<QAbstractFileEngine> engine;
184 if (_q_createLegacyEngine_recursive(copy, data, engine))
194QString QFileSystemEngine::resolveUserName(
const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
198 return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerUser);
200 if (!metaData.hasFlags(QFileSystemMetaData::UserId))
201 QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::UserId);
202 if (!metaData.exists())
204 return resolveUserName(metaData.userId());
209QString QFileSystemEngine::resolveGroupName(
const QFileSystemEntry &entry, QFileSystemMetaData &metaData)
213 return QFileSystemEngine::owner(entry, QAbstractFileEngine::OwnerGroup);
215 if (!metaData.hasFlags(QFileSystemMetaData::GroupId))
216 QFileSystemEngine::fillMetaData(entry, metaData, QFileSystemMetaData::GroupId);
217 if (!metaData.exists())
219 return resolveGroupName(metaData.groupId());
224QFileSystemEntry QFileSystemEngine::getJunctionTarget(
const QFileSystemEntry &link,
225 QFileSystemMetaData &data)
228 return junctionTarget(link, data);
static bool _q_createLegacyEngine_recursive(QFileSystemEntry &entry, QFileSystemMetaData &data, std::unique_ptr< QAbstractFileEngine > &engine, bool resolvingEntry=false)
static bool _q_checkEntry(QFileSystemEntry &entry, QFileSystemMetaData &data, bool resolvingEntry)
static bool _q_checkEntry(std::unique_ptr< QAbstractFileEngine > &engine, bool resolvingEntry)
Q_CORE_EXPORT bool qt_isCaseSensitive(const QFileSystemEntry &entry, QFileSystemMetaData &data)