5#include "private/qabstractfileengine_p.h"
6#include "private/qfsfileengine_p.h"
7#ifdef QT_BUILD_CORE_LIB
8#include "private/qresource_p.h"
17#include <QtCore/private/qfilesystementry_p.h>
18#include <QtCore/private/qfilesystemmetadata_p.h>
19#include <QtCore/private/qfilesystemengine_p.h>
23using namespace Qt::StringLiterals;
27 if (!path.isEmpty() && !path.endsWith(u'/')
29 && !path.startsWith(
"content:/"_L1)
32 return QString{path + u'/'};
36QAbstractFileEnginePrivate::~QAbstractFileEnginePrivate()
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
83
85Q_CONSTINIT
static QBasicAtomicInt qt_file_engine_handlers_in_use = Q_BASIC_ATOMIC_INITIALIZER(
false);
88
89
90
91Q_GLOBAL_STATIC(QReadWriteLock, fileEngineHandlerMutex, QReadWriteLock::Recursive)
92Q_CONSTINIT
static bool qt_abstractfileenginehandlerlist_shutDown =
false;
101 QWriteLocker locker(fileEngineHandlerMutex());
102 qt_abstractfileenginehandlerlist_shutDown =
true;
105Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers)
108
109
110
111
112
113
114
115
116QAbstractFileEngineHandler::QAbstractFileEngineHandler()
118 QWriteLocker locker(fileEngineHandlerMutex());
119 qt_file_engine_handlers_in_use.storeRelaxed(
true);
120 fileEngineHandlers()->prepend(
this);
124
125
126
127QAbstractFileEngineHandler::~QAbstractFileEngineHandler()
129 QWriteLocker locker(fileEngineHandlerMutex());
131 if (!qt_abstractfileenginehandlerlist_shutDown) {
132 QAbstractFileEngineHandlerList *handlers = fileEngineHandlers();
133 handlers->removeOne(
this);
134 if (handlers->isEmpty())
135 qt_file_engine_handlers_in_use.storeRelaxed(
false);
140
141
142
143
144std::unique_ptr<QAbstractFileEngine> qt_custom_file_engine_handler_create(
const QString &path)
146 if (qt_file_engine_handlers_in_use.loadRelaxed()) {
147 QReadLocker locker(fileEngineHandlerMutex());
150 for (QAbstractFileEngineHandler *handler : std::as_const(*fileEngineHandlers())) {
151 if (
auto engine = handler->create(path))
160
161
162
163
164
165
166
167
168
169
170
171
174
175
176
177
178
179
180
181
182
183
184
185
186std::unique_ptr<QAbstractFileEngine> QAbstractFileEngine::create(
const QString &fileName)
188 QFileSystemEntry entry(fileName);
189 QFileSystemMetaData metaData;
190 auto engine = QFileSystemEngine::createLegacyEngine(entry, metaData);
192#ifndef QT_NO_FSFILEENGINE
194 engine = std::make_unique<QFSFileEngine>(entry.filePath());
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
230
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
259
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
309
312
313
314
315
316
317
318
321
322
323
324
325QAbstractFileEngine::QAbstractFileEngine() : d_ptr(
new QAbstractFileEnginePrivate(
this))
330
331
332
333
334QAbstractFileEngine::QAbstractFileEngine(QAbstractFileEnginePrivate &dd) : d_ptr(&dd)
336 Q_ASSERT(d_ptr->q_ptr ==
this);
340
341
342QAbstractFileEngine::~QAbstractFileEngine()
347
348
349
350
351
352
353
354
355
356
357
358
359bool QAbstractFileEngine::open(QIODevice::OpenMode openMode,
360 std::optional<QFile::Permissions> permissions)
363 Q_UNUSED(permissions);
368
369
370
371
372bool QAbstractFileEngine::close()
378
379
380
381
382
383
384
385bool QAbstractFileEngine::syncToDisk()
391
392
393
394
395
396bool QAbstractFileEngine::flush()
402
403
404qint64 QAbstractFileEngine::size()
const
410
411
412
413
414qint64 QAbstractFileEngine::pos()
const
420
421
422
423
424
425
426
427
428
429
430bool QAbstractFileEngine::seek(qint64 pos)
437
438
439
440
441
442
443bool QAbstractFileEngine::isSequential()
const
449
450
451
452
453
454bool QAbstractFileEngine::remove()
460
461
462
463bool QAbstractFileEngine::copy(
const QString &newName)
470
471
472
473
474
475
476bool QAbstractFileEngine::rename(
const QString &newName)
483
484
485
486
487
488
489
490
491
492bool QAbstractFileEngine::renameOverwrite(
const QString &newName)
499
500
501
502
503
504bool QAbstractFileEngine::link(
const QString &newName)
511
512
513
514
515
516
517
518
519
520
521
522
523bool QAbstractFileEngine::mkdir(
const QString &dirName,
bool createParentDirectories,
524 std::optional<QFile::Permissions> permissions)
const
527 Q_UNUSED(createParentDirectories);
528 Q_UNUSED(permissions);
533
534
535
536
537
538
539
540
541
542
543bool QAbstractFileEngine::rmdir(
const QString &dirName,
bool recurseParentDirectories)
const
546 Q_UNUSED(recurseParentDirectories);
551
552
553
554
555
556
557
558bool QAbstractFileEngine::setSize(qint64 size)
565
566
567
568bool QAbstractFileEngine::caseSensitive()
const
574
575
576
577
578
579bool QAbstractFileEngine::isRelativePath()
const
585
586
587
588
589
590
591
592
593
594
595
596
597QAbstractFileEngine::FileFlags QAbstractFileEngine::fileFlags(FileFlags type)
const
604
605
606
607
608
609
610
611
612bool QAbstractFileEngine::setPermissions(uint perms)
619
620
621
622
623
624QByteArray QAbstractFileEngine::id()
const
630
631
632
633
634
635
636
637
638
639QString QAbstractFileEngine::fileName(FileName file)
const
646
647
648
649
650
651
652uint QAbstractFileEngine::ownerId(FileOwner owner)
const
659
660
661
662
663
664
665
666QString QAbstractFileEngine::owner(FileOwner owner)
const
674
675
676
677
678
679
680
681bool QAbstractFileEngine::setFileTime(
const QDateTime &newDate, QFile::FileTime time)
689
690
691
692
693
694
695
696
697
698QDateTime QAbstractFileEngine::fileTime(QFile::FileTime time)
const
705
706
707
708
709
710void QAbstractFileEngine::setFileName(
const QString &file)
716
717
718
719
720int QAbstractFileEngine::handle()
const
726
727
728
729
730
731
732
733
734
735
736
737bool QAbstractFileEngine::atEnd()
const
739 return const_cast<QAbstractFileEngine *>(
this)->extension(AtEndExtension);
743
744
745
746
747
748
749
750
751
752
753
754
755
756
758uchar *QAbstractFileEngine::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
760 const MapExtensionOption option(offset, size, flags);
761 MapExtensionReturn r;
762 if (!extension(MapExtension, &option, &r))
768
769
770
771
772
773
774
775
776
777
778
779bool QAbstractFileEngine::unmap(uchar *address)
781 const UnMapExtensionOption options(address);
782 return extension(UnMapExtension, &options);
786
787
788
789
790
791
792
793QAbstractFileEngine::TriStateResult QAbstractFileEngine::cloneTo(QAbstractFileEngine *target)
796 return TriStateResult::NotSupported;
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
857
858
859
860
861
864
865
866
867
868
869
872
873
874
875QAbstractFileEngineIterator::QAbstractFileEngineIterator(
const QString &path, QDir::Filters filters,
876 const QStringList &nameFilters)
877 : m_filters(filters),
878 m_nameFilters(nameFilters),
879 m_path(appendSlashIfNeeded(path))
883QAbstractFileEngineIterator::QAbstractFileEngineIterator(
const QString &path,
884 QDirListing::IteratorFlags filters,
885 const QStringList &nameFilters)
886 : m_listingFilters(filters),
887 m_nameFilters(nameFilters),
888 m_path(appendSlashIfNeeded(path))
893
894
895
896
897QAbstractFileEngineIterator::~QAbstractFileEngineIterator()
902
903
904
905
906
907
908QString QAbstractFileEngineIterator::path()
const
914
915
916
917
918QStringList QAbstractFileEngineIterator::nameFilters()
const
920 return m_nameFilters;
924
925
926
927
928QDir::Filters QAbstractFileEngineIterator::filters()
const
934
935
936
937
938
939
940
943
944
945
946
947
948QString QAbstractFileEngineIterator::currentFilePath()
const
950 QString name = currentFileName();
954 return path() + name;
958
959
960
961
962
963
964
965
966QFileInfo QAbstractFileEngineIterator::currentFileInfo()
const
968 QString path = currentFilePath();
969 if (m_fileInfo.filePath() != path)
970 m_fileInfo.setFile(path);
977
978
979
980
981
982
983
984
985
986
987
990
991
992
993
994
995
996
997QAbstractFileEngine::IteratorUniquePtr
998QAbstractFileEngine::beginEntryList(
const QString &path, QDirListing::IteratorFlags filters,
999 const QStringList &filterNames)
1003 Q_UNUSED(filterNames);
1008
1009
1010
1011
1012
1013
1014qint64 QAbstractFileEngine::read(
char *data, qint64 maxlen)
1022
1023
1024
1025qint64 QAbstractFileEngine::write(
const char *data, qint64 len)
1033
1034
1035
1036
1037qint64 QAbstractFileEngine::readLine(
char *data, qint64 maxlen)
1039 qint64 readSoFar = 0;
1040 while (readSoFar < maxlen) {
1042 qint64 readResult = read(&c, 1);
1043 if (readResult <= 0)
1044 return (readSoFar > 0) ? readSoFar : -1;
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1087
1088
1089
1090
1091
1092
1093
1094
1097
1098
1099
1100
1101
1102
1103
1104
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124bool QAbstractFileEngine::extension(Extension extension,
const ExtensionOption *option, ExtensionReturn *output)
1126 Q_UNUSED(extension);
1133
1134
1135
1136
1137
1138
1139
1140
1141bool QAbstractFileEngine::supportsExtension(Extension extension)
const
1143 Q_UNUSED(extension);
1148
1149
1150
1151
1152
1153
1154QFile::FileError QAbstractFileEngine::error()
const
1156 Q_D(
const QAbstractFileEngine);
1157 return d->fileError;
1161
1162
1163
1164
1165
1166
1167QString QAbstractFileEngine::errorString()
const
1169 Q_D(
const QAbstractFileEngine);
1170 return d->errorString;
1174
1175
1176
1177
1178
1179
1180void QAbstractFileEngine::setError(QFile::FileError error,
const QString &errorString)
1182 Q_D(QAbstractFileEngine);
1183 d->fileError = error;
1184 d->errorString = errorString;
~QAbstractFileEngineHandlerList()
static QString appendSlashIfNeeded(const QString &path)