4#include "private/qabstractfileengine_p.h"
5#include "private/qfsfileengine_p.h"
6#ifdef QT_BUILD_CORE_LIB
7#include "private/qresource_p.h"
16#include <QtCore/private/qfilesystementry_p.h>
17#include <QtCore/private/qfilesystemmetadata_p.h>
18#include <QtCore/private/qfilesystemengine_p.h>
22using namespace Qt::StringLiterals;
26 if (!path.isEmpty() && !path.endsWith(u'/')
28 && !path.startsWith(
"content:/"_L1)
31 return QString{path + u'/'};
35QAbstractFileEnginePrivate::~QAbstractFileEnginePrivate()
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
84Q_CONSTINIT
static QBasicAtomicInt qt_file_engine_handlers_in_use = Q_BASIC_ATOMIC_INITIALIZER(
false);
87
88
89
90Q_GLOBAL_STATIC(QReadWriteLock, fileEngineHandlerMutex, QReadWriteLock::Recursive)
91Q_CONSTINIT
static bool qt_abstractfileenginehandlerlist_shutDown =
false;
100 QWriteLocker locker(fileEngineHandlerMutex());
101 qt_abstractfileenginehandlerlist_shutDown =
true;
104Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers)
107
108
109
110
111
112
113
114
115QAbstractFileEngineHandler::QAbstractFileEngineHandler()
117 QWriteLocker locker(fileEngineHandlerMutex());
118 qt_file_engine_handlers_in_use.storeRelaxed(
true);
119 fileEngineHandlers()->prepend(
this);
123
124
125
126QAbstractFileEngineHandler::~QAbstractFileEngineHandler()
128 QWriteLocker locker(fileEngineHandlerMutex());
130 if (!qt_abstractfileenginehandlerlist_shutDown) {
131 QAbstractFileEngineHandlerList *handlers = fileEngineHandlers();
132 handlers->removeOne(
this);
133 if (handlers->isEmpty())
134 qt_file_engine_handlers_in_use.storeRelaxed(
false);
139
140
141
142
143std::unique_ptr<QAbstractFileEngine> qt_custom_file_engine_handler_create(
const QString &path)
145 if (qt_file_engine_handlers_in_use.loadRelaxed()) {
146 QReadLocker locker(fileEngineHandlerMutex());
149 for (QAbstractFileEngineHandler *handler : std::as_const(*fileEngineHandlers())) {
150 if (
auto engine = handler->create(path))
159
160
161
162
163
164
165
166
167
168
169
170
173
174
175
176
177
178
179
180
181
182
183
184
185std::unique_ptr<QAbstractFileEngine> QAbstractFileEngine::create(
const QString &fileName)
187 QFileSystemEntry entry(fileName);
188 QFileSystemMetaData metaData;
189 auto engine = QFileSystemEngine::createLegacyEngine(entry, metaData);
191#ifndef QT_NO_FSFILEENGINE
193 engine = std::make_unique<QFSFileEngine>(entry.filePath());
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
311
312
313
314
315
316
317
320
321
322
323
324QAbstractFileEngine::QAbstractFileEngine() : d_ptr(
new QAbstractFileEnginePrivate(
this))
329
330
331
332
333QAbstractFileEngine::QAbstractFileEngine(QAbstractFileEnginePrivate &dd) : d_ptr(&dd)
335 Q_ASSERT(d_ptr->q_ptr ==
this);
339
340
341QAbstractFileEngine::~QAbstractFileEngine()
346
347
348
349
350
351
352
353
354
355
356
357
358bool QAbstractFileEngine::open(QIODevice::OpenMode openMode,
359 std::optional<QFile::Permissions> permissions)
362 Q_UNUSED(permissions);
367
368
369
370
371bool QAbstractFileEngine::close()
377
378
379
380
381
382
383
384bool QAbstractFileEngine::syncToDisk()
390
391
392
393
394
395bool QAbstractFileEngine::flush()
401
402
403qint64 QAbstractFileEngine::size()
const
409
410
411
412
413qint64 QAbstractFileEngine::pos()
const
419
420
421
422
423
424
425
426
427
428
429bool QAbstractFileEngine::seek(qint64 pos)
436
437
438
439
440
441
442bool QAbstractFileEngine::isSequential()
const
448
449
450
451
452
453bool QAbstractFileEngine::remove()
459
460
461
462bool QAbstractFileEngine::copy(
const QString &newName)
469
470
471
472
473
474
475bool QAbstractFileEngine::rename(
const QString &newName)
482
483
484
485
486
487
488
489
490
491bool QAbstractFileEngine::renameOverwrite(
const QString &newName)
498
499
500
501
502
503bool QAbstractFileEngine::link(
const QString &newName)
510
511
512
513
514
515
516
517
518
519
520
521
522bool QAbstractFileEngine::mkdir(
const QString &dirName,
bool createParentDirectories,
523 std::optional<QFile::Permissions> permissions)
const
526 Q_UNUSED(createParentDirectories);
527 Q_UNUSED(permissions);
532
533
534
535
536
537
538
539
540
541
542bool QAbstractFileEngine::rmdir(
const QString &dirName,
bool recurseParentDirectories)
const
545 Q_UNUSED(recurseParentDirectories);
550
551
552
553
554
555
556
557bool QAbstractFileEngine::setSize(qint64 size)
564
565
566
567bool QAbstractFileEngine::caseSensitive()
const
573
574
575
576
577
578bool QAbstractFileEngine::isRelativePath()
const
584
585
586
587
588
589
590
591
592
593
594QStringList QAbstractFileEngine::entryList(QDir::Filters filters,
const QStringList &filterNames)
const
597#ifdef QT_BOOTSTRAPPED
599 Q_UNUSED(filterNames);
600 Q_UNREACHABLE_RETURN(ret);
602 for (
const auto &dirEntry : QDirListing(fileName(), filterNames, filters.toInt()))
603 ret.emplace_back(dirEntry.fileName());
608QStringList QAbstractFileEngine::entryList(QDirListing::IteratorFlags filters,
609 const QStringList &filterNames)
const
612#ifdef QT_BOOTSTRAPPED
614 Q_UNUSED(filterNames);
615 Q_UNREACHABLE_RETURN(ret);
617 for (
const auto &dirEntry : QDirListing(fileName(), filterNames, filters))
618 ret.emplace_back(dirEntry.fileName());
624
625
626
627
628
629
630
631
632
633
634
635
636QAbstractFileEngine::FileFlags QAbstractFileEngine::fileFlags(FileFlags type)
const
643
644
645
646
647
648
649
650
651bool QAbstractFileEngine::setPermissions(uint perms)
658
659
660
661
662
663QByteArray QAbstractFileEngine::id()
const
669
670
671
672
673
674
675
676
677
678QString QAbstractFileEngine::fileName(FileName file)
const
685
686
687
688
689
690
691uint QAbstractFileEngine::ownerId(FileOwner owner)
const
698
699
700
701
702
703
704
705QString QAbstractFileEngine::owner(FileOwner owner)
const
713
714
715
716
717
718
719
720bool QAbstractFileEngine::setFileTime(
const QDateTime &newDate, QFile::FileTime time)
728
729
730
731
732
733
734
735
736
737QDateTime QAbstractFileEngine::fileTime(QFile::FileTime time)
const
744
745
746
747
748
749void QAbstractFileEngine::setFileName(
const QString &file)
755
756
757
758
759int QAbstractFileEngine::handle()
const
765
766
767
768
769
770
771
772
773
774
775
776bool QAbstractFileEngine::atEnd()
const
778 return const_cast<QAbstractFileEngine *>(
this)->extension(AtEndExtension);
782
783
784
785
786
787
788
789
790
791
792
793
794
795
797uchar *QAbstractFileEngine::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
799 const MapExtensionOption option(offset, size, flags);
800 MapExtensionReturn r;
801 if (!extension(MapExtension, &option, &r))
807
808
809
810
811
812
813
814
815
816
817
818bool QAbstractFileEngine::unmap(uchar *address)
820 const UnMapExtensionOption options(address);
821 return extension(UnMapExtension, &options);
825
826
827
828
829
830
831
832bool QAbstractFileEngine::cloneTo(QAbstractFileEngine *target)
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
896
897
898
899
900
903
904
905
906
907
908
911
912
913
914QAbstractFileEngineIterator::QAbstractFileEngineIterator(
const QString &path, QDir::Filters filters,
915 const QStringList &nameFilters)
916 : m_filters(filters),
917 m_nameFilters(nameFilters),
918 m_path(appendSlashIfNeeded(path))
922QAbstractFileEngineIterator::QAbstractFileEngineIterator(
const QString &path,
923 QDirListing::IteratorFlags filters,
924 const QStringList &nameFilters)
925 : m_listingFilters(filters),
926 m_nameFilters(nameFilters),
927 m_path(appendSlashIfNeeded(path))
932
933
934
935
936QAbstractFileEngineIterator::~QAbstractFileEngineIterator()
941
942
943
944
945
946
947QString QAbstractFileEngineIterator::path()
const
953
954
955
956
957QStringList QAbstractFileEngineIterator::nameFilters()
const
959 return m_nameFilters;
963
964
965
966
967QDir::Filters QAbstractFileEngineIterator::filters()
const
973
974
975
976
977
978
979
982
983
984
985
986
987QString QAbstractFileEngineIterator::currentFilePath()
const
989 QString name = currentFileName();
993 return path() + name;
997
998
999
1000
1001
1002
1003
1004
1005QFileInfo QAbstractFileEngineIterator::currentFileInfo()
const
1007 QString path = currentFilePath();
1008 if (m_fileInfo.filePath() != path)
1009 m_fileInfo.setFile(path);
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1029
1030
1031
1032
1033
1034
1035
1036QAbstractFileEngine::IteratorUniquePtr
1037QAbstractFileEngine::beginEntryList(
const QString &path, QDirListing::IteratorFlags filters,
1038 const QStringList &filterNames)
1042 Q_UNUSED(filterNames);
1047
1048
1049
1050
1051
1052
1053qint64 QAbstractFileEngine::read(
char *data, qint64 maxlen)
1061
1062
1063
1064qint64 QAbstractFileEngine::write(
const char *data, qint64 len)
1072
1073
1074
1075
1076qint64 QAbstractFileEngine::readLine(
char *data, qint64 maxlen)
1078 qint64 readSoFar = 0;
1079 while (readSoFar < maxlen) {
1081 qint64 readResult = read(&c, 1);
1082 if (readResult <= 0)
1083 return (readSoFar > 0) ? readSoFar : -1;
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1126
1127
1128
1129
1130
1131
1132
1133
1136
1137
1138
1139
1140
1141
1142
1143
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163bool QAbstractFileEngine::extension(Extension extension,
const ExtensionOption *option, ExtensionReturn *output)
1165 Q_UNUSED(extension);
1172
1173
1174
1175
1176
1177
1178
1179
1180bool QAbstractFileEngine::supportsExtension(Extension extension)
const
1182 Q_UNUSED(extension);
1187
1188
1189
1190
1191
1192
1193QFile::FileError QAbstractFileEngine::error()
const
1195 Q_D(
const QAbstractFileEngine);
1196 return d->fileError;
1200
1201
1202
1203
1204
1205
1206QString QAbstractFileEngine::errorString()
const
1208 Q_D(
const QAbstractFileEngine);
1209 return d->errorString;
1213
1214
1215
1216
1217
1218
1219void QAbstractFileEngine::setError(QFile::FileError error,
const QString &errorString)
1221 Q_D(QAbstractFileEngine);
1222 d->fileError = error;
1223 d->errorString = errorString;
~QAbstractFileEngineHandlerList()
Combined button and popup list for selecting options.
static QString appendSlashIfNeeded(const QString &path)