io/qdiriterator.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6template <class Iterator> -
7class QDirIteratorPrivateIteratorStack : public QStack<Iterator *> -
8{ -
9public: -
10 ~QDirIteratorPrivateIteratorStack() -
11 { -
12 qDeleteAll(*this); -
13 }
executed: }
Execution Count:7530
7530
14}; -
15 -
16class QDirIteratorPrivate -
17{ -
18public: -
19 QDirIteratorPrivate(const QFileSystemEntry &entry, const QStringList &nameFilters, -
20 QDir::Filters filters, QDirIterator::IteratorFlags flags, bool resolveEngine = true); -
21 -
22 void advance(); -
23 -
24 bool entryMatches(const QString & fileName, const QFileInfo &fileInfo); -
25 void pushDirectory(const QFileInfo &fileInfo); -
26 void checkAndPushDirectory(const QFileInfo &); -
27 bool matchesFilters(const QString &fileName, const QFileInfo &fi) const; -
28 -
29 QScopedPointer<QAbstractFileEngine> engine; -
30 -
31 QFileSystemEntry dirEntry; -
32 const QStringList nameFilters; -
33 const QDir::Filters filters; -
34 const QDirIterator::IteratorFlags iteratorFlags; -
35 -
36 -
37 QVector<QRegExp> nameRegExps; -
38 -
39 -
40 QDirIteratorPrivateIteratorStack<QAbstractFileEngineIterator> fileEngineIterators; -
41 -
42 QDirIteratorPrivateIteratorStack<QFileSystemIterator> nativeIterators; -
43 -
44 -
45 QFileInfo currentFileInfo; -
46 QFileInfo nextFileInfo; -
47 -
48 -
49 QSet<QString> visitedLinks; -
50}; -
51 -
52 -
53 -
54 -
55QDirIteratorPrivate::QDirIteratorPrivate(const QFileSystemEntry &entry, const QStringList &nameFilters, -
56 QDir::Filters filters, QDirIterator::IteratorFlags flags, bool resolveEngine) -
57 : dirEntry(entry) -
58 , nameFilters(nameFilters.contains(QLatin1String("*")) ? QStringList() : nameFilters) -
59 , filters(QDir::NoFilter == filters ? QDir::AllEntries : filters) -
60 , iteratorFlags(flags) -
61{ -
62 -
63 nameRegExps.reserve(nameFilters.size()); -
64 for (int i = 0; i < nameFilters.size(); ++i)
evaluated: i < nameFilters.size()
TRUEFALSE
yes
Evaluation Count:1251
yes
Evaluation Count:3765
1251-3765
65 nameRegExps.append( 1251
66 QRegExp(nameFilters.at(i), 1251
67 (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, 1251
68 QRegExp::Wildcard));
executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard));
Execution Count:1251
1251
69 -
70 QFileSystemMetaData metaData; -
71 if (resolveEngine)
evaluated: resolveEngine
TRUEFALSE
yes
Evaluation Count:3695
yes
Evaluation Count:70
70-3695
72 engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
executed: engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
Execution Count:3695
3695
73 QFileInfo fileInfo(new QFileInfoPrivate(dirEntry, metaData)); -
74 -
75 -
76 pushDirectory(fileInfo); -
77 advance(); -
78}
executed: }
Execution Count:3765
3765
79 -
80 -
81 -
82 -
83void QDirIteratorPrivate::pushDirectory(const QFileInfo &fileInfo) -
84{ -
85 QString path = fileInfo.filePath(); -
86 -
87 -
88 -
89 -
90 -
91 -
92 if (iteratorFlags & QDirIterator::FollowSymlinks)
evaluated: iteratorFlags & QDirIterator::FollowSymlinks
TRUEFALSE
yes
Evaluation Count:145
yes
Evaluation Count:5712
145-5712
93 visitedLinks << fileInfo.canonicalFilePath();
executed: visitedLinks << fileInfo.canonicalFilePath();
Execution Count:145
145
94 -
95 if (engine) {
evaluated: engine
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:5840
17-5840
96 engine->setFileName(path); -
97 QAbstractFileEngineIterator *it = engine->beginEntryList(filters, nameFilters); -
98 if (it) {
partially evaluated: it
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
99 it->setPath(path); -
100 fileEngineIterators << it; -
101 } else {
executed: }
Execution Count:17
17
102 -
103 }
never executed: }
0
104 } else { -
105 -
106 QFileSystemIterator *it = new QFileSystemIterator(fileInfo.d_ptr->fileEntry, -
107 filters, nameFilters, iteratorFlags); -
108 nativeIterators << it; -
109 -
110 }
executed: }
Execution Count:5840
5840
111} -
112 -
113inline bool QDirIteratorPrivate::entryMatches(const QString & fileName, const QFileInfo &fileInfo) -
114{ -
115 checkAndPushDirectory(fileInfo); -
116 -
117 if (matchesFilters(fileName, fileInfo)) {
evaluated: matchesFilters(fileName, fileInfo)
TRUEFALSE
yes
Evaluation Count:72685
yes
Evaluation Count:14335
14335-72685
118 currentFileInfo = nextFileInfo; -
119 nextFileInfo = fileInfo; -
120 -
121 -
122 return true;
executed: return true;
Execution Count:72694
72694
123 } -
124 -
125 return false;
executed: return false;
Execution Count:14335
14335
126} -
127 -
128 -
129 -
130 -
131void QDirIteratorPrivate::advance() -
132{ -
133 if (engine) {
evaluated: engine
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:76206
193-76206
134 while (!fileEngineIterators.isEmpty()) {
evaluated: !fileEngineIterators.isEmpty()
TRUEFALSE
yes
Evaluation Count:197
yes
Evaluation Count:13
13-197
135 -
136 QAbstractFileEngineIterator *it; -
137 while (it = fileEngineIterators.top(), it->hasNext()) {
evaluated: it = fileEngineIterators.top(), it->hasNext()
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:17
17-183
138 it->next(); -
139 if (entryMatches(it->currentFileName(), it->currentFileInfo()))
evaluated: entryMatches(it->currentFileName(), it->currentFileInfo())
TRUEFALSE
yes
Evaluation Count:180
yes
Evaluation Count:3
3-180
140 return;
executed: return;
Execution Count:180
180
141 }
executed: }
Execution Count:3
3
142 -
143 fileEngineIterators.pop(); -
144 delete it; -
145 }
executed: }
Execution Count:17
17
146 } else {
executed: }
Execution Count:13
13
147 -
148 QFileSystemEntry nextEntry; -
149 QFileSystemMetaData nextMetaData; -
150 -
151 while (!nativeIterators.isEmpty()) {
evaluated: !nativeIterators.isEmpty()
TRUEFALSE
yes
Evaluation Count:78293
yes
Evaluation Count:3700
3700-78293
152 -
153 QFileSystemIterator *it; -
154 while (it = nativeIterators.top(), it->advance(nextEntry, nextMetaData)) {
evaluated: it = nativeIterators.top(), it->advance(nextEntry, nextMetaData)
TRUEFALSE
yes
Evaluation Count:86823
yes
Evaluation Count:5787
5787-86823
155 QFileInfo info(new QFileInfoPrivate(nextEntry, nextMetaData)); -
156 -
157 if (entryMatches(nextEntry.fileName(), info))
evaluated: entryMatches(nextEntry.fileName(), info)
TRUEFALSE
yes
Evaluation Count:72511
yes
Evaluation Count:14332
14332-72511
158 return;
executed: return;
Execution Count:72511
72511
159 }
executed: }
Execution Count:14332
14332
160 -
161 nativeIterators.pop(); -
162 delete it; -
163 }
executed: }
Execution Count:5787
5787
164 -
165 }
executed: }
Execution Count:3700
3700
166 -
167 currentFileInfo = nextFileInfo; -
168 nextFileInfo = QFileInfo(); -
169}
executed: }
Execution Count:3713
3713
170 -
171 -
172 -
173 -
174void QDirIteratorPrivate::checkAndPushDirectory(const QFileInfo &fileInfo) -
175{ -
176 -
177 if (!(iteratorFlags & QDirIterator::Subdirectories))
evaluated: !(iteratorFlags & QDirIterator::Subdirectories)
TRUEFALSE
yes
Evaluation Count:78255
yes
Evaluation Count:8769
8769-78255
178 return;
executed: return;
Execution Count:78255
78255
179 -
180 -
181 if (!fileInfo.isDir())
evaluated: !fileInfo.isDir()
TRUEFALSE
yes
Evaluation Count:2113
yes
Evaluation Count:6656
2113-6656
182 return;
executed: return;
Execution Count:2113
2113
183 -
184 -
185 if (!(iteratorFlags & QDirIterator::FollowSymlinks) && fileInfo.isSymLink())
evaluated: !(iteratorFlags & QDirIterator::FollowSymlinks)
TRUEFALSE
yes
Evaluation Count:6201
yes
Evaluation Count:455
evaluated: fileInfo.isSymLink()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6200
1-6201
186 return;
executed: return;
Execution Count:1
1
187 -
188 -
189 QString fileName = fileInfo.fileName(); -
190 if (QLatin1String(".") == fileName || QLatin1String("..") == fileName)
evaluated: QLatin1String(".") == fileName
TRUEFALSE
yes
Evaluation Count:2235
yes
Evaluation Count:4420
evaluated: QLatin1String("..") == fileName
TRUEFALSE
yes
Evaluation Count:2233
yes
Evaluation Count:2187
2187-4420
191 return;
executed: return;
Execution Count:4468
4468
192 -
193 -
194 if (!(filters & QDir::AllDirs) && !(filters & QDir::Hidden) && fileInfo.isHidden())
evaluated: !(filters & QDir::AllDirs)
TRUEFALSE
yes
Evaluation Count:621
yes
Evaluation Count:1566
evaluated: !(filters & QDir::Hidden)
TRUEFALSE
yes
Evaluation Count:609
yes
Evaluation Count:12
evaluated: fileInfo.isHidden()
TRUEFALSE
yes
Evaluation Count:84
yes
Evaluation Count:525
12-1566
195 return;
executed: return;
Execution Count:84
84
196 -
197 -
198 if (!visitedLinks.isEmpty() &&
evaluated: !visitedLinks.isEmpty()
TRUEFALSE
yes
Evaluation Count:101
yes
Evaluation Count:2002
101-2002
199 visitedLinks.contains(fileInfo.canonicalFilePath()))
evaluated: visitedLinks.contains(fileInfo.canonicalFilePath())
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:90
11-90
200 return;
executed: return;
Execution Count:11
11
201 -
202 pushDirectory(fileInfo); -
203}
executed: }
Execution Count:2092
2092
204bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInfo &fi) const -
205{ -
206 qt_noop(); -
207 -
208 -
209 const int fileNameSize = fileName.size(); -
210 const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
evaluated: fileName[0] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:14543
yes
Evaluation Count:72482
14543-72482
211 && ((fileNameSize == 1)
evaluated: (fileNameSize == 1)
TRUEFALSE
yes
Evaluation Count:5816
yes
Evaluation Count:8727
5816-8727
212 ||(fileNameSize == 2 && fileName[1] == QLatin1Char('.')));
evaluated: fileNameSize == 2
TRUEFALSE
yes
Evaluation Count:6003
yes
Evaluation Count:2724
evaluated: fileName[1] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:5814
yes
Evaluation Count:189
189-6003
213 if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
evaluated: (filters & QDir::NoDot)
TRUEFALSE
yes
Evaluation Count:29395
yes
Evaluation Count:57633
evaluated: dotOrDotDot
TRUEFALSE
yes
Evaluation Count:10196
yes
Evaluation Count:19199
evaluated: fileNameSize == 1
TRUEFALSE
yes
Evaluation Count:5098
yes
Evaluation Count:5098
5098-57633
214 return false;
executed: return false;
Execution Count:5098
5098
215 if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
evaluated: (filters & QDir::NoDotDot)
TRUEFALSE
yes
Evaluation Count:24300
yes
Evaluation Count:57630
evaluated: dotOrDotDot
TRUEFALSE
yes
Evaluation Count:5101
yes
Evaluation Count:19199
evaluated: fileNameSize == 2
TRUEFALSE
yes
Evaluation Count:5098
yes
Evaluation Count:3
3-57630
216 return false;
executed: return false;
Execution Count:5098
5098
217 -
218 -
219 -
220 -
221 if (!nameFilters.isEmpty() && !((filters & QDir::AllDirs) && fi.isDir())) {
evaluated: !nameFilters.isEmpty()
TRUEFALSE
yes
Evaluation Count:3040
yes
Evaluation Count:73788
evaluated: (filters & QDir::AllDirs)
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:3023
evaluated: fi.isDir()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:10
7-73788
222 bool matched = false; -
223 for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(), -
224 end = nameRegExps.constEnd(); -
225 iter != end; ++iter) {
evaluated: iter != end
TRUEFALSE
yes
Evaluation Count:3329
yes
Evaluation Count:1632
1632-3329
226 -
227 QRegExp copy = *iter; -
228 if (copy.exactMatch(fileName)) {
evaluated: copy.exactMatch(fileName)
TRUEFALSE
yes
Evaluation Count:1401
yes
Evaluation Count:1928
1401-1928
229 matched = true; -
230 break;
executed: break;
Execution Count:1401
1401
231 } -
232 }
executed: }
Execution Count:1928
1928
233 if (!matched)
evaluated: !matched
TRUEFALSE
yes
Evaluation Count:1632
yes
Evaluation Count:1401
1401-1632
234 return false;
executed: return false;
Execution Count:1632
1632
235 }
executed: }
Execution Count:1401
1401
236 -
237 -
238 const bool skipSymlinks = (filters & QDir::NoSymLinks); -
239 const bool includeSystem = (filters & QDir::System); -
240 if(skipSymlinks && fi.isSymLink()) {
evaluated: skipSymlinks
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:75134
evaluated: fi.isSymLink()
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:46
17-75134
241 -
242 if(!includeSystem || fi.exists())
partially evaluated: !includeSystem
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
never evaluated: fi.exists()
0-17
243 return false;
executed: return false;
Execution Count:17
17
244 }
never executed: }
0
245 -
246 -
247 const bool includeHidden = (filters & QDir::Hidden); -
248 if (!includeHidden && !dotOrDotDot && fi.isHidden())
evaluated: !includeHidden
TRUEFALSE
yes
Evaluation Count:21190
yes
Evaluation Count:53993
evaluated: !dotOrDotDot
TRUEFALSE
yes
Evaluation Count:20584
yes
Evaluation Count:606
evaluated: fi.isHidden()
TRUEFALSE
yes
Evaluation Count:1582
yes
Evaluation Count:19002
606-53993
249 return false;
executed: return false;
Execution Count:1582
1582
250 -
251 -
252 if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink())
evaluated: !includeSystem
TRUEFALSE
yes
Evaluation Count:20360
yes
Evaluation Count:53241
evaluated: fi.isFile()
TRUEFALSE
yes
Evaluation Count:11937
yes
Evaluation Count:8423
evaluated: fi.isDir()
TRUEFALSE
yes
Evaluation Count:7966
yes
Evaluation Count:457
evaluated: fi.isSymLink()
TRUEFALSE
yes
Evaluation Count:297
yes
Evaluation Count:160
160-53241
253 || (!fi.exists() && fi.isSymLink())))
evaluated: !fi.exists()
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:20076
partially evaluated: fi.isSymLink()
TRUEFALSE
yes
Evaluation Count:124
no
Evaluation Count:0
0-20076
254 return false;
executed: return false;
Execution Count:284
284
255 -
256 -
257 const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs)); -
258 if (skipDirs && fi.isDir())
evaluated: skipDirs
TRUEFALSE
yes
Evaluation Count:3944
yes
Evaluation Count:69364
evaluated: fi.isDir()
TRUEFALSE
yes
Evaluation Count:539
yes
Evaluation Count:3405
539-69364
259 return false;
executed: return false;
Execution Count:539
539
260 -
261 -
262 const bool skipFiles = !(filters & QDir::Files); -
263 if (skipFiles && fi.isFile())
evaluated: skipFiles
TRUEFALSE
yes
Evaluation Count:413
yes
Evaluation Count:72356
evaluated: fi.isFile()
TRUEFALSE
yes
Evaluation Count:83
yes
Evaluation Count:330
83-72356
264 -
265 return false;
executed: return false;
Execution Count:83
83
266 -
267 -
268 const bool filterPermissions = ((filters & QDir::PermissionMask)
evaluated: (filters & QDir::PermissionMask)
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:72600
87-72600
269 && (filters & QDir::PermissionMask) != QDir::PermissionMask);
partially evaluated: (filters & QDir::PermissionMask) != QDir::PermissionMask
TRUEFALSE
yes
Evaluation Count:87
no
Evaluation Count:0
0-87
270 const bool doWritable = !filterPermissions || (filters & QDir::Writable);
evaluated: !filterPermissions
TRUEFALSE
yes
Evaluation Count:72600
yes
Evaluation Count:87
evaluated: (filters & QDir::Writable)
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:80
7-72600
271 const bool doExecutable = !filterPermissions || (filters & QDir::Executable);
evaluated: !filterPermissions
TRUEFALSE
yes
Evaluation Count:72600
yes
Evaluation Count:87
partially evaluated: (filters & QDir::Executable)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:87
0-72600
272 const bool doReadable = !filterPermissions || (filters & QDir::Readable);
evaluated: !filterPermissions
TRUEFALSE
yes
Evaluation Count:72600
yes
Evaluation Count:87
evaluated: (filters & QDir::Readable)
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:7
7-72600
273 if (filterPermissions
evaluated: filterPermissions
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:72600
87-72600
274 && ((doReadable && !fi.isReadable())
evaluated: doReadable
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:7
partially evaluated: !fi.isReadable()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:80
0-80
275 || (doWritable && !fi.isWritable())
evaluated: doWritable
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:80
evaluated: !fi.isWritable()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:5
2-80
276 || (doExecutable && !fi.isExecutable()))) {
partially evaluated: doExecutable
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:85
never evaluated: !fi.isExecutable()
0-85
277 return false;
executed: return false;
Execution Count:2
2
278 } -
279 -
280 return true;
executed: return true;
Execution Count:72685
72685
281} -
282QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags) -
283{ -
284 const QDirPrivate *other = dir.d_ptr.constData(); -
285 d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull())); -
286}
executed: }
Execution Count:73
73
287QDirIterator::QDirIterator(const QString &path, QDir::Filters filters, IteratorFlags flags) -
288 : d(new QDirIteratorPrivate(QFileSystemEntry(path), QStringList(), filters, flags)) -
289{ -
290}
executed: }
Execution Count:2519
2519
291QDirIterator::QDirIterator(const QString &path, IteratorFlags flags) -
292 : d(new QDirIteratorPrivate(QFileSystemEntry(path), QStringList(), QDir::NoFilter, flags)) -
293{ -
294}
executed: }
Execution Count:4
4
295QDirIterator::QDirIterator(const QString &path, const QStringList &nameFilters, -
296 QDir::Filters filters, IteratorFlags flags) -
297 : d(new QDirIteratorPrivate(QFileSystemEntry(path), nameFilters, filters, flags)) -
298{ -
299}
executed: }
Execution Count:1169
1169
300 -
301 -
302 -
303 -
304QDirIterator::~QDirIterator() -
305{ -
306} -
307QString QDirIterator::next() -
308{ -
309 d->advance(); -
310 return filePath();
executed: return filePath();
Execution Count:72641
72641
311} -
312 -
313 -
314 -
315 -
316 -
317 -
318 -
319bool QDirIterator::hasNext() const -
320{ -
321 if (d->engine)
evaluated: d->engine
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:76162
193-76162
322 return !d->fileEngineIterators.isEmpty();
executed: return !d->fileEngineIterators.isEmpty();
Execution Count:193
193
323 else -
324 -
325 return !d->nativeIterators.isEmpty();
executed: return !d->nativeIterators.isEmpty();
Execution Count:76162
76162
326 -
327 -
328 -
329} -
330QString QDirIterator::fileName() const -
331{ -
332 return d->currentFileInfo.fileName();
executed: return d->currentFileInfo.fileName();
Execution Count:44
44
333} -
334 -
335 -
336 -
337 -
338 -
339 -
340QString QDirIterator::filePath() const -
341{ -
342 return d->currentFileInfo.filePath();
executed: return d->currentFileInfo.filePath();
Execution Count:75271
75271
343} -
344 -
345 -
346 -
347 -
348 -
349 -
350QFileInfo QDirIterator::fileInfo() const -
351{ -
352 return d->currentFileInfo;
executed: return d->currentFileInfo;
Execution Count:70198
70198
353} -
354 -
355 -
356 -
357 -
358QString QDirIterator::path() const -
359{ -
360 return d->dirEntry.filePath();
executed: return d->dirEntry.filePath();
Execution Count:44
44
361} -
362 -
363 -
364 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial