io/qdiriterator.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42/*! -
43 \since 4.3 -
44 \class QDirIterator -
45 \inmodule QtCore -
46 \brief The QDirIterator class provides an iterator for directory entrylists. -
47 -
48 You can use QDirIterator to navigate entries of a directory one at a time. -
49 It is similar to QDir::entryList() and QDir::entryInfoList(), but because -
50 it lists entries one at a time instead of all at once, it scales better -
51 and is more suitable for large directories. It also supports listing -
52 directory contents recursively, and following symbolic links. Unlike -
53 QDir::entryList(), QDirIterator does not support sorting. -
54 -
55 The QDirIterator constructor takes a QDir or a directory as -
56 argument. After construction, the iterator is located before the first -
57 directory entry. Here's how to iterate over all the entries sequentially: -
58 -
59 \snippet code/src_corelib_io_qdiriterator.cpp 0 -
60 -
61 The next() function returns the path to the next directory entry and -
62 advances the iterator. You can also call filePath() to get the current -
63 file path without advancing the iterator. The fileName() function returns -
64 only the name of the file, similar to how QDir::entryList() works. You can -
65 also call fileInfo() to get a QFileInfo for the current entry. -
66 -
67 Unlike Qt's container iterators, QDirIterator is uni-directional (i.e., -
68 you cannot iterate directories in reverse order) and does not allow random -
69 access. -
70 -
71 \sa QDir, QDir::entryList() -
72*/ -
73 -
74/*! \enum QDirIterator::IteratorFlag -
75 -
76 This enum describes flags that you can combine to configure the behavior -
77 of QDirIterator. -
78 -
79 \value NoIteratorFlags The default value, representing no flags. The -
80 iterator will return entries for the assigned path. -
81 -
82 \value Subdirectories List entries inside all subdirectories as well. -
83 -
84 \value FollowSymlinks When combined with Subdirectories, this flag -
85 enables iterating through all subdirectories of the assigned path, -
86 following all symbolic links. Symbolic link loops (e.g., "link" => "." or -
87 "link" => "..") are automatically detected and ignored. -
88*/ -
89 -
90#include "qdiriterator.h" -
91#include "qdir_p.h" -
92#include "qabstractfileengine_p.h" -
93 -
94#include <QtCore/qset.h> -
95#include <QtCore/qstack.h> -
96#include <QtCore/qvariant.h> -
97 -
98#include <QtCore/private/qfilesystemiterator_p.h> -
99#include <QtCore/private/qfilesystementry_p.h> -
100#include <QtCore/private/qfilesystemmetadata_p.h> -
101#include <QtCore/private/qfilesystemengine_p.h> -
102#include <QtCore/private/qfileinfo_p.h> -
103 -
104QT_BEGIN_NAMESPACE -
105 -
106template <class Iterator> -
107class QDirIteratorPrivateIteratorStack : public QStack<Iterator *> -
108{ -
109public: -
110 ~QDirIteratorPrivateIteratorStack() -
111 { -
112 qDeleteAll(*this);
executed (the execution status of this line is deduced): qDeleteAll(*this);
-
113 }
executed: }
Execution Count:7530
7530
114}; -
115 -
116class QDirIteratorPrivate -
117{ -
118public: -
119 QDirIteratorPrivate(const QFileSystemEntry &entry, const QStringList &nameFilters, -
120 QDir::Filters filters, QDirIterator::IteratorFlags flags, bool resolveEngine = true); -
121 -
122 void advance(); -
123 -
124 bool entryMatches(const QString & fileName, const QFileInfo &fileInfo); -
125 void pushDirectory(const QFileInfo &fileInfo); -
126 void checkAndPushDirectory(const QFileInfo &); -
127 bool matchesFilters(const QString &fileName, const QFileInfo &fi) const; -
128 -
129 QScopedPointer<QAbstractFileEngine> engine; -
130 -
131 QFileSystemEntry dirEntry; -
132 const QStringList nameFilters; -
133 const QDir::Filters filters; -
134 const QDirIterator::IteratorFlags iteratorFlags; -
135 -
136#ifndef QT_NO_REGEXP -
137 QVector<QRegExp> nameRegExps; -
138#endif -
139 -
140 QDirIteratorPrivateIteratorStack<QAbstractFileEngineIterator> fileEngineIterators; -
141#ifndef QT_NO_FILESYSTEMITERATOR -
142 QDirIteratorPrivateIteratorStack<QFileSystemIterator> nativeIterators; -
143#endif -
144 -
145 QFileInfo currentFileInfo; -
146 QFileInfo nextFileInfo; -
147 -
148 // Loop protection -
149 QSet<QString> visitedLinks; -
150}; -
151 -
152/*! -
153 \internal -
154*/ -
155QDirIteratorPrivate::QDirIteratorPrivate(const QFileSystemEntry &entry, const QStringList &nameFilters, -
156 QDir::Filters filters, QDirIterator::IteratorFlags flags, bool resolveEngine) -
157 : dirEntry(entry) -
158 , nameFilters(nameFilters.contains(QLatin1String("*")) ? QStringList() : nameFilters) -
159 , filters(QDir::NoFilter == filters ? QDir::AllEntries : filters) -
160 , iteratorFlags(flags) -
161{ -
162#ifndef QT_NO_REGEXP -
163 nameRegExps.reserve(nameFilters.size());
executed (the execution status of this line is deduced): nameRegExps.reserve(nameFilters.size());
-
164 for (int i = 0; i < nameFilters.size(); ++i)
evaluated: i < nameFilters.size()
TRUEFALSE
yes
Evaluation Count:1251
yes
Evaluation Count:3765
1251-3765
165 nameRegExps.append(
executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard));
Execution Count:1251
1251
166 QRegExp(nameFilters.at(i),
executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard));
Execution Count:1251
1251
167 (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive,
executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard));
Execution Count:1251
1251
168 QRegExp::Wildcard));
executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard));
Execution Count:1251
1251
169#endif -
170 QFileSystemMetaData metaData;
executed (the execution status of this line is deduced): QFileSystemMetaData metaData;
-
171 if (resolveEngine)
evaluated: resolveEngine
TRUEFALSE
yes
Evaluation Count:3695
yes
Evaluation Count:70
70-3695
172 engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
executed: engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
Execution Count:3695
3695
173 QFileInfo fileInfo(new QFileInfoPrivate(dirEntry, metaData));
executed (the execution status of this line is deduced): QFileInfo fileInfo(new QFileInfoPrivate(dirEntry, metaData));
-
174 -
175 // Populate fields for hasNext() and next() -
176 pushDirectory(fileInfo);
executed (the execution status of this line is deduced): pushDirectory(fileInfo);
-
177 advance();
executed (the execution status of this line is deduced): advance();
-
178}
executed: }
Execution Count:3765
3765
179 -
180/*! -
181 \internal -
182*/ -
183void QDirIteratorPrivate::pushDirectory(const QFileInfo &fileInfo) -
184{ -
185 QString path = fileInfo.filePath();
executed (the execution status of this line is deduced): QString path = fileInfo.filePath();
-
186 -
187#ifdef Q_OS_WIN -
188 if (fileInfo.isSymLink()) -
189 path = fileInfo.canonicalFilePath(); -
190#endif -
191 -
192 if (iteratorFlags & QDirIterator::FollowSymlinks)
evaluated: iteratorFlags & QDirIterator::FollowSymlinks
TRUEFALSE
yes
Evaluation Count:145
yes
Evaluation Count:5712
145-5712
193 visitedLinks << fileInfo.canonicalFilePath();
executed: visitedLinks << fileInfo.canonicalFilePath();
Execution Count:145
145
194 -
195 if (engine) {
evaluated: engine
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:5840
17-5840
196 engine->setFileName(path);
executed (the execution status of this line is deduced): engine->setFileName(path);
-
197 QAbstractFileEngineIterator *it = engine->beginEntryList(filters, nameFilters);
executed (the execution status of this line is deduced): QAbstractFileEngineIterator *it = engine->beginEntryList(filters, nameFilters);
-
198 if (it) {
partially evaluated: it
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
199 it->setPath(path);
executed (the execution status of this line is deduced): it->setPath(path);
-
200 fileEngineIterators << it;
executed (the execution status of this line is deduced): fileEngineIterators << it;
-
201 } else {
executed: }
Execution Count:17
17
202 // No iterator; no entry list. -
203 }
never executed: }
0
204 } else { -
205#ifndef QT_NO_FILESYSTEMITERATOR -
206 QFileSystemIterator *it = new QFileSystemIterator(fileInfo.d_ptr->fileEntry,
executed (the execution status of this line is deduced): QFileSystemIterator *it = new QFileSystemIterator(fileInfo.d_ptr->fileEntry,
-
207 filters, nameFilters, iteratorFlags);
executed (the execution status of this line is deduced): filters, nameFilters, iteratorFlags);
-
208 nativeIterators << it;
executed (the execution status of this line is deduced): nativeIterators << it;
-
209#endif -
210 }
executed: }
Execution Count:5840
5840
211} -
212 -
213inline bool QDirIteratorPrivate::entryMatches(const QString & fileName, const QFileInfo &fileInfo) -
214{ -
215 checkAndPushDirectory(fileInfo);
executed (the execution status of this line is deduced): checkAndPushDirectory(fileInfo);
-
216 -
217 if (matchesFilters(fileName, fileInfo)) {
evaluated: matchesFilters(fileName, fileInfo)
TRUEFALSE
yes
Evaluation Count:72685
yes
Evaluation Count:14335
14335-72685
218 currentFileInfo = nextFileInfo;
executed (the execution status of this line is deduced): currentFileInfo = nextFileInfo;
-
219 nextFileInfo = fileInfo;
executed (the execution status of this line is deduced): nextFileInfo = fileInfo;
-
220 -
221 //We found a matching entry. -
222 return true;
executed: return true;
Execution Count:72694
72694
223 } -
224 -
225 return false;
executed: return false;
Execution Count:14335
14335
226} -
227 -
228/*! -
229 \internal -
230*/ -
231void QDirIteratorPrivate::advance() -
232{ -
233 if (engine) {
evaluated: engine
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:76206
193-76206
234 while (!fileEngineIterators.isEmpty()) {
evaluated: !fileEngineIterators.isEmpty()
TRUEFALSE
yes
Evaluation Count:197
yes
Evaluation Count:13
13-197
235 // Find the next valid iterator that matches the filters. -
236 QAbstractFileEngineIterator *it;
executed (the execution status of this line is deduced): QAbstractFileEngineIterator *it;
-
237 while (it = fileEngineIterators.top(), it->hasNext()) {
evaluated: it = fileEngineIterators.top(), it->hasNext()
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:17
17-183
238 it->next();
executed (the execution status of this line is deduced): it->next();
-
239 if (entryMatches(it->currentFileName(), it->currentFileInfo()))
evaluated: entryMatches(it->currentFileName(), it->currentFileInfo())
TRUEFALSE
yes
Evaluation Count:180
yes
Evaluation Count:3
3-180
240 return;
executed: return;
Execution Count:180
180
241 }
executed: }
Execution Count:3
3
242 -
243 fileEngineIterators.pop();
executed (the execution status of this line is deduced): fileEngineIterators.pop();
-
244 delete it;
executed (the execution status of this line is deduced): delete it;
-
245 }
executed: }
Execution Count:17
17
246 } else {
executed: }
Execution Count:13
13
247#ifndef QT_NO_FILESYSTEMITERATOR -
248 QFileSystemEntry nextEntry;
executed (the execution status of this line is deduced): QFileSystemEntry nextEntry;
-
249 QFileSystemMetaData nextMetaData;
executed (the execution status of this line is deduced): QFileSystemMetaData nextMetaData;
-
250 -
251 while (!nativeIterators.isEmpty()) {
evaluated: !nativeIterators.isEmpty()
TRUEFALSE
yes
Evaluation Count:78293
yes
Evaluation Count:3700
3700-78293
252 // Find the next valid iterator that matches the filters. -
253 QFileSystemIterator *it;
executed (the execution status of this line is deduced): QFileSystemIterator *it;
-
254 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
255 QFileInfo info(new QFileInfoPrivate(nextEntry, nextMetaData));
executed (the execution status of this line is deduced): QFileInfo info(new QFileInfoPrivate(nextEntry, nextMetaData));
-
256 -
257 if (entryMatches(nextEntry.fileName(), info))
evaluated: entryMatches(nextEntry.fileName(), info)
TRUEFALSE
yes
Evaluation Count:72511
yes
Evaluation Count:14332
14332-72511
258 return;
executed: return;
Execution Count:72511
72511
259 }
executed: }
Execution Count:14332
14332
260 -
261 nativeIterators.pop();
executed (the execution status of this line is deduced): nativeIterators.pop();
-
262 delete it;
executed (the execution status of this line is deduced): delete it;
-
263 }
executed: }
Execution Count:5787
5787
264#endif -
265 }
executed: }
Execution Count:3700
3700
266 -
267 currentFileInfo = nextFileInfo;
executed (the execution status of this line is deduced): currentFileInfo = nextFileInfo;
-
268 nextFileInfo = QFileInfo();
executed (the execution status of this line is deduced): nextFileInfo = QFileInfo();
-
269}
executed: }
Execution Count:3713
3713
270 -
271/*! -
272 \internal -
273 */ -
274void QDirIteratorPrivate::checkAndPushDirectory(const QFileInfo &fileInfo) -
275{ -
276 // If we're doing flat iteration, we're done. -
277 if (!(iteratorFlags & QDirIterator::Subdirectories))
evaluated: !(iteratorFlags & QDirIterator::Subdirectories)
TRUEFALSE
yes
Evaluation Count:78255
yes
Evaluation Count:8769
8769-78255
278 return;
executed: return;
Execution Count:78255
78255
279 -
280 // Never follow non-directory entries -
281 if (!fileInfo.isDir())
evaluated: !fileInfo.isDir()
TRUEFALSE
yes
Evaluation Count:2113
yes
Evaluation Count:6656
2113-6656
282 return;
executed: return;
Execution Count:2113
2113
283 -
284 // Follow symlinks only when asked -
285 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
286 return;
executed: return;
Execution Count:1
1
287 -
288 // Never follow . and .. -
289 QString fileName = fileInfo.fileName();
executed (the execution status of this line is deduced): QString fileName = fileInfo.fileName();
-
290 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
291 return;
executed: return;
Execution Count:4468
4468
292 -
293 // No hidden directories unless requested -
294 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
295 return;
executed: return;
Execution Count:84
84
296 -
297 // Stop link loops -
298 if (!visitedLinks.isEmpty() &&
evaluated: !visitedLinks.isEmpty()
TRUEFALSE
yes
Evaluation Count:101
yes
Evaluation Count:2002
101-2002
299 visitedLinks.contains(fileInfo.canonicalFilePath()))
evaluated: visitedLinks.contains(fileInfo.canonicalFilePath())
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:90
11-90
300 return;
executed: return;
Execution Count:11
11
301 -
302 pushDirectory(fileInfo);
executed (the execution status of this line is deduced): pushDirectory(fileInfo);
-
303}
executed: }
Execution Count:2092
2092
304 -
305/*! -
306 \internal -
307 -
308 This convenience function implements the iterator's filtering logics and -
309 applies then to the current directory entry. -
310 -
311 It returns true if the current entry matches the filters (i.e., the -
312 current entry will be returned as part of the directory iteration); -
313 otherwise, false is returned. -
314*/ -
315 -
316bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInfo &fi) const -
317{ -
318 Q_ASSERT(!fileName.isEmpty());
executed (the execution status of this line is deduced): qt_noop();
-
319 -
320 // filter . and ..? -
321 const int fileNameSize = fileName.size();
executed (the execution status of this line is deduced): const int fileNameSize = fileName.size();
-
322 const bool dotOrDotDot = fileName[0] == QLatin1Char('.')
evaluated: fileName[0] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:14543
yes
Evaluation Count:72482
14543-72482
323 && ((fileNameSize == 1)
evaluated: (fileNameSize == 1)
TRUEFALSE
yes
Evaluation Count:5816
yes
Evaluation Count:8727
5816-8727
324 ||(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
325 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
326 return false;
executed: return false;
Execution Count:5098
5098
327 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
328 return false;
executed: return false;
Execution Count:5098
5098
329 -
330 // name filter -
331#ifndef QT_NO_REGEXP -
332 // Pass all entries through name filters, except dirs if the AllDirs -
333 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
334 bool matched = false;
executed (the execution status of this line is deduced): bool matched = false;
-
335 for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(),
executed (the execution status of this line is deduced): for (QVector<QRegExp>::const_iterator iter = nameRegExps.constBegin(),
-
336 end = nameRegExps.constEnd();
executed (the execution status of this line is deduced): end = nameRegExps.constEnd();
-
337 iter != end; ++iter) {
evaluated: iter != end
TRUEFALSE
yes
Evaluation Count:3329
yes
Evaluation Count:1632
1632-3329
338 -
339 QRegExp copy = *iter;
executed (the execution status of this line is deduced): QRegExp copy = *iter;
-
340 if (copy.exactMatch(fileName)) {
evaluated: copy.exactMatch(fileName)
TRUEFALSE
yes
Evaluation Count:1401
yes
Evaluation Count:1928
1401-1928
341 matched = true;
executed (the execution status of this line is deduced): matched = true;
-
342 break;
executed: break;
Execution Count:1401
1401
343 } -
344 }
executed: }
Execution Count:1928
1928
345 if (!matched)
evaluated: !matched
TRUEFALSE
yes
Evaluation Count:1632
yes
Evaluation Count:1401
1401-1632
346 return false;
executed: return false;
Execution Count:1632
1632
347 }
executed: }
Execution Count:1401
1401
348#endif -
349 // skip symlinks -
350 const bool skipSymlinks = (filters & QDir::NoSymLinks);
executed (the execution status of this line is deduced): const bool skipSymlinks = (filters & QDir::NoSymLinks);
-
351 const bool includeSystem = (filters & QDir::System);
executed (the execution status of this line is deduced): const bool includeSystem = (filters & QDir::System);
-
352 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
353 // The only reason to save this file is if it is a broken link and we are requesting system files. -
354 if(!includeSystem || fi.exists())
partially evaluated: !includeSystem
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
never evaluated: fi.exists()
0-17
355 return false;
executed: return false;
Execution Count:17
17
356 }
never executed: }
0
357 -
358 // filter hidden -
359 const bool includeHidden = (filters & QDir::Hidden);
executed (the execution status of this line is deduced): const bool includeHidden = (filters & QDir::Hidden);
-
360 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
361 return false;
executed: return false;
Execution Count:1582
1582
362 -
363 // filter system files -
364 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
365 || (!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
366 return false;
executed: return false;
Execution Count:284
284
367 -
368 // skip directories -
369 const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
executed (the execution status of this line is deduced): const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
-
370 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
371 return false;
executed: return false;
Execution Count:539
539
372 -
373 // skip files -
374 const bool skipFiles = !(filters & QDir::Files);
executed (the execution status of this line is deduced): const bool skipFiles = !(filters & QDir::Files);
-
375 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
376 // Basically we need a reason not to exclude this file otherwise we just eliminate it. -
377 return false;
executed: return false;
Execution Count:83
83
378 -
379 // filter permissions -
380 const bool filterPermissions = ((filters & QDir::PermissionMask)
evaluated: (filters & QDir::PermissionMask)
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:72600
87-72600
381 && (filters & QDir::PermissionMask) != QDir::PermissionMask);
partially evaluated: (filters & QDir::PermissionMask) != QDir::PermissionMask
TRUEFALSE
yes
Evaluation Count:87
no
Evaluation Count:0
0-87
382 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
383 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
384 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
385 if (filterPermissions
evaluated: filterPermissions
TRUEFALSE
yes
Evaluation Count:87
yes
Evaluation Count:72600
87-72600
386 && ((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
387 || (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
388 || (doExecutable && !fi.isExecutable()))) {
partially evaluated: doExecutable
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:85
never evaluated: !fi.isExecutable()
0-85
389 return false;
executed: return false;
Execution Count:2
2
390 } -
391 -
392 return true;
executed: return true;
Execution Count:72685
72685
393} -
394 -
395/*! -
396 Constructs a QDirIterator that can iterate over \a dir's entrylist, using -
397 \a dir's name filters and regular filters. You can pass options via \a -
398 flags to decide how the directory should be iterated. -
399 -
400 By default, \a flags is NoIteratorFlags, which provides the same behavior -
401 as in QDir::entryList(). -
402 -
403 The sorting in \a dir is ignored. -
404 -
405 \note To list symlinks that point to non existing files, QDir::System must be -
406 passed to the flags. -
407 -
408 \sa hasNext(), next(), IteratorFlags -
409*/ -
410QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags) -
411{ -
412 const QDirPrivate *other = dir.d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate *other = dir.d_ptr.constData();
-
413 d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull()));
executed (the execution status of this line is deduced): d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull()));
-
414}
executed: }
Execution Count:73
73
415 -
416/*! -
417 Constructs a QDirIterator that can iterate over \a path, with no name -
418 filtering and \a filters for entry filtering. You can pass options via \a -
419 flags to decide how the directory should be iterated. -
420 -
421 By default, \a filters is QDir::NoFilter, and \a flags is NoIteratorFlags, -
422 which provides the same behavior as in QDir::entryList(). -
423 -
424 \note To list symlinks that point to non existing files, QDir::System must be -
425 passed to the flags. -
426 -
427 \sa hasNext(), next(), IteratorFlags -
428*/ -
429QDirIterator::QDirIterator(const QString &path, QDir::Filters filters, IteratorFlags flags) -
430 : d(new QDirIteratorPrivate(QFileSystemEntry(path), QStringList(), filters, flags)) -
431{ -
432}
executed: }
Execution Count:2519
2519
433 -
434/*! -
435 Constructs a QDirIterator that can iterate over \a path. You can pass -
436 options via \a flags to decide how the directory should be iterated. -
437 -
438 By default, \a flags is NoIteratorFlags, which provides the same behavior -
439 as in QDir::entryList(). -
440 -
441 \note To list symlinks that point to non existing files, QDir::System must be -
442 passed to the flags. -
443 -
444 \sa hasNext(), next(), IteratorFlags -
445*/ -
446QDirIterator::QDirIterator(const QString &path, IteratorFlags flags) -
447 : d(new QDirIteratorPrivate(QFileSystemEntry(path), QStringList(), QDir::NoFilter, flags)) -
448{ -
449}
executed: }
Execution Count:4
4
450 -
451/*! -
452 Constructs a QDirIterator that can iterate over \a path, using \a -
453 nameFilters and \a filters. You can pass options via \a flags to decide -
454 how the directory should be iterated. -
455 -
456 By default, \a flags is NoIteratorFlags, which provides the same behavior -
457 as QDir::entryList(). -
458 -
459 \note To list symlinks that point to non existing files, QDir::System must be -
460 passed to the flags. -
461 -
462 \sa hasNext(), next(), IteratorFlags -
463*/ -
464QDirIterator::QDirIterator(const QString &path, const QStringList &nameFilters, -
465 QDir::Filters filters, IteratorFlags flags) -
466 : d(new QDirIteratorPrivate(QFileSystemEntry(path), nameFilters, filters, flags)) -
467{ -
468}
executed: }
Execution Count:1169
1169
469 -
470/*! -
471 Destroys the QDirIterator. -
472*/ -
473QDirIterator::~QDirIterator() -
474{ -
475} -
476 -
477/*! -
478 Advances the iterator to the next entry, and returns the file path of this -
479 new entry. If hasNext() returns false, this function does nothing, and -
480 returns a null QString. -
481 -
482 You can call fileName() or filePath() to get the current entry file name -
483 or path, or fileInfo() to get a QFileInfo for the current entry. -
484 -
485 \sa hasNext(), fileName(), filePath(), fileInfo() -
486*/ -
487QString QDirIterator::next() -
488{ -
489 d->advance();
executed (the execution status of this line is deduced): d->advance();
-
490 return filePath();
executed: return filePath();
Execution Count:72641
72641
491} -
492 -
493/*! -
494 Returns true if there is at least one more entry in the directory; -
495 otherwise, false is returned. -
496 -
497 \sa next(), fileName(), filePath(), fileInfo() -
498*/ -
499bool QDirIterator::hasNext() const -
500{ -
501 if (d->engine)
evaluated: d->engine
TRUEFALSE
yes
Evaluation Count:193
yes
Evaluation Count:76162
193-76162
502 return !d->fileEngineIterators.isEmpty();
executed: return !d->fileEngineIterators.isEmpty();
Execution Count:193
193
503 else -
504#ifndef QT_NO_FILESYSTEMITERATOR -
505 return !d->nativeIterators.isEmpty();
executed: return !d->nativeIterators.isEmpty();
Execution Count:76162
76162
506#else -
507 return false; -
508#endif -
509} -
510 -
511/*! -
512 Returns the file name for the current directory entry, without the path -
513 prepended. -
514 -
515 This function is convenient when iterating a single directory. When using -
516 the QDirIterator::Subdirectories flag, you can use filePath() to get the -
517 full path. -
518 -
519 \sa filePath(), fileInfo() -
520*/ -
521QString QDirIterator::fileName() const -
522{ -
523 return d->currentFileInfo.fileName();
executed: return d->currentFileInfo.fileName();
Execution Count:44
44
524} -
525 -
526/*! -
527 Returns the full file path for the current directory entry. -
528 -
529 \sa fileInfo(), fileName() -
530*/ -
531QString QDirIterator::filePath() const -
532{ -
533 return d->currentFileInfo.filePath();
executed: return d->currentFileInfo.filePath();
Execution Count:75271
75271
534} -
535 -
536/*! -
537 Returns a QFileInfo for the current directory entry. -
538 -
539 \sa filePath(), fileName() -
540*/ -
541QFileInfo QDirIterator::fileInfo() const -
542{ -
543 return d->currentFileInfo;
executed: return d->currentFileInfo;
Execution Count:70198
70198
544} -
545 -
546/*! -
547 Returns the base directory of the iterator. -
548*/ -
549QString QDirIterator::path() const -
550{ -
551 return d->dirEntry.filePath();
executed: return d->dirEntry.filePath();
Execution Count:44
44
552} -
553 -
554QT_END_NAMESPACE -
555 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial