Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2012 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 | | - |
104 | QT_BEGIN_NAMESPACE | - |
105 | | - |
106 | template <class Iterator> | - |
107 | class QDirIteratorPrivateIteratorStack : public QStack<Iterator *> | - |
108 | { | - |
109 | public: | - |
110 | ~QDirIteratorPrivateIteratorStack() | - |
111 | { | - |
112 | qDeleteAll(*this); executed (the execution status of this line is deduced): qDeleteAll(*this); | - |
113 | } executed: } Execution Count:7454 | 7454 |
114 | }; | - |
115 | | - |
116 | class QDirIteratorPrivate | - |
117 | { | - |
118 | public: | - |
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 | */ | - |
155 | QDirIteratorPrivate::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() yes Evaluation Count:1246 | yes Evaluation Count:3727 |
| 1246-3727 |
165 | nameRegExps.append( executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard)); Execution Count:1246 | 1246 |
166 | QRegExp(nameFilters.at(i), executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard)); Execution Count:1246 | 1246 |
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:1246 | 1246 |
168 | QRegExp::Wildcard)); executed: nameRegExps.append( QRegExp(nameFilters.at(i), (filters & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive, QRegExp::Wildcard)); Execution Count:1246 | 1246 |
169 | #endif | - |
170 | QFileSystemMetaData metaData; executed (the execution status of this line is deduced): QFileSystemMetaData metaData; | - |
171 | if (resolveEngine) evaluated: resolveEngine yes Evaluation Count:3657 | yes Evaluation Count:70 |
| 70-3657 |
172 | engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData)); executed: engine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData)); Execution Count:3657 | 3657 |
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:3727 | 3727 |
179 | | - |
180 | /*! | - |
181 | \internal | - |
182 | */ | - |
183 | void 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 yes Evaluation Count:145 | yes Evaluation Count:5674 |
| 145-5674 |
193 | visitedLinks << fileInfo.canonicalFilePath(); executed: visitedLinks << fileInfo.canonicalFilePath(); Execution Count:145 | 145 |
194 | | - |
195 | if (engine) { evaluated: engine yes Evaluation Count:17 | yes Evaluation Count:5802 |
| 17-5802 |
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 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 | } | 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:5802 | 5802 |
211 | } | - |
212 | | - |
213 | inline 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) yes Evaluation Count:26581 | yes Evaluation Count:14179 |
| 14179-26581 |
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:26581 | 26581 |
223 | } | - |
224 | | - |
225 | return false; executed: return false; Execution Count:14179 | 14179 |
226 | } | - |
227 | | - |
228 | /*! | - |
229 | \internal | - |
230 | */ | - |
231 | void QDirIteratorPrivate::advance() | - |
232 | { | - |
233 | if (engine) { evaluated: engine yes Evaluation Count:193 | yes Evaluation Count:30105 |
| 193-30105 |
234 | while (!fileEngineIterators.isEmpty()) { evaluated: !fileEngineIterators.isEmpty() 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() 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()) 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() yes Evaluation Count:32192 | yes Evaluation Count:3704 |
| 3704-32192 |
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) yes Evaluation Count:40577 | yes Evaluation Count:5791 |
| 5791-40577 |
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) yes Evaluation Count:26401 | yes Evaluation Count:14176 |
| 14176-26401 |
258 | return; executed: return; Execution Count:26401 | 26401 |
259 | } executed: } Execution Count:14176 | 14176 |
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:5791 | 5791 |
264 | #endif | - |
265 | } executed: } Execution Count:3704 | 3704 |
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:3717 | 3717 |
270 | | - |
271 | /*! | - |
272 | \internal | - |
273 | */ | - |
274 | void 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) yes Evaluation Count:32018 | yes Evaluation Count:8742 |
| 8742-32018 |
278 | return; executed: return; Execution Count:32018 | 32018 |
279 | | - |
280 | // Never follow non-directory entries | - |
281 | if (!fileInfo.isDir()) evaluated: !fileInfo.isDir() yes Evaluation Count:2086 | yes Evaluation Count:6656 |
| 2086-6656 |
282 | return; executed: return; Execution Count:2086 | 2086 |
283 | | - |
284 | // Follow symlinks only when asked | - |
285 | if (!(iteratorFlags & QDirIterator::FollowSymlinks) && fileInfo.isSymLink()) evaluated: !(iteratorFlags & QDirIterator::FollowSymlinks) yes Evaluation Count:6201 | yes Evaluation Count:455 |
evaluated: fileInfo.isSymLink() 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 yes Evaluation Count:2235 | yes Evaluation Count:4420 |
evaluated: QLatin1String("..") == fileName 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) yes Evaluation Count:621 | yes Evaluation Count:1566 |
evaluated: !(filters & QDir::Hidden) yes Evaluation Count:609 | yes Evaluation Count:12 |
evaluated: fileInfo.isHidden() 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() yes Evaluation Count:101 | yes Evaluation Count:2002 |
| 101-2002 |
299 | visitedLinks.contains(fileInfo.canonicalFilePath())) evaluated: visitedLinks.contains(fileInfo.canonicalFilePath()) 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 | | - |
316 | bool 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('.') yes Evaluation Count:14323 | yes Evaluation Count:26437 |
| 14323-26437 |
323 | && ((fileNameSize == 1) evaluated: (fileNameSize == 1) yes Evaluation Count:5776 | yes Evaluation Count:8547 |
| 5776-8547 |
324 | ||(fileNameSize == 2 && fileName[1] == QLatin1Char('.'))); evaluated: fileNameSize == 2 yes Evaluation Count:5963 | yes Evaluation Count:2584 |
evaluated: fileName[1] == QLatin1Char('.') yes Evaluation Count:5774 | yes Evaluation Count:189 |
| 189-5963 |
325 | if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1) evaluated: (filters & QDir::NoDot) yes Evaluation Count:25614 | yes Evaluation Count:15146 |
evaluated: dotOrDotDot yes Evaluation Count:10180 | yes Evaluation Count:15434 |
evaluated: fileNameSize == 1 yes Evaluation Count:5090 | yes Evaluation Count:5090 |
| 5090-25614 |
326 | return false; executed: return false; Execution Count:5090 | 5090 |
327 | if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2) evaluated: (filters & QDir::NoDotDot) yes Evaluation Count:20527 | yes Evaluation Count:15143 |
evaluated: dotOrDotDot yes Evaluation Count:5093 | yes Evaluation Count:15434 |
evaluated: fileNameSize == 2 yes Evaluation Count:5090 | yes Evaluation Count:3 |
| 3-20527 |
328 | return false; executed: return false; Execution Count:5090 | 5090 |
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() yes Evaluation Count:3035 | yes Evaluation Count:27545 |
evaluated: (filters & QDir::AllDirs) yes Evaluation Count:17 | yes Evaluation Count:3018 |
evaluated: fi.isDir() yes Evaluation Count:7 | yes Evaluation Count:10 |
| 7-27545 |
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 yes Evaluation Count:3324 | yes Evaluation Count:1627 |
| 1627-3324 |
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) yes Evaluation Count:1401 | yes Evaluation Count:1923 |
| 1401-1923 |
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:1923 | 1923 |
345 | if (!matched) evaluated: !matched yes Evaluation Count:1627 | yes Evaluation Count:1401 |
| 1401-1627 |
346 | return false; executed: return false; Execution Count:1627 | 1627 |
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 yes Evaluation Count:63 | yes Evaluation Count:28890 |
evaluated: fi.isSymLink() yes Evaluation Count:17 | yes Evaluation Count:46 |
| 17-28890 |
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 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 | } | 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 yes Evaluation Count:17370 | yes Evaluation Count:11566 |
evaluated: !dotOrDotDot yes Evaluation Count:16774 | yes Evaluation Count:596 |
evaluated: fi.isHidden() yes Evaluation Count:1458 | yes Evaluation Count:15316 |
| 596-17370 |
361 | return false; executed: return false; Execution Count:1458 | 1458 |
362 | | - |
363 | // filter system files | - |
364 | if (!includeSystem && (!(fi.isFile() || fi.isDir() || fi.isSymLink()) evaluated: !includeSystem yes Evaluation Count:16649 | yes Evaluation Count:10829 |
evaluated: fi.isFile() yes Evaluation Count:8365 | yes Evaluation Count:8284 |
evaluated: fi.isDir() yes Evaluation Count:7830 | yes Evaluation Count:454 |
evaluated: fi.isSymLink() yes Evaluation Count:296 | yes Evaluation Count:158 |
| 158-16649 |
365 | || (!fi.exists() && fi.isSymLink()))) evaluated: !fi.exists() yes Evaluation Count:123 | yes Evaluation Count:16368 |
partially evaluated: fi.isSymLink() yes Evaluation Count:123 | no Evaluation Count:0 |
| 0-16368 |
366 | return false; executed: return false; Execution Count:281 | 281 |
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 yes Evaluation Count:3881 | yes Evaluation Count:23316 |
evaluated: fi.isDir() yes Evaluation Count:531 | yes Evaluation Count:3350 |
| 531-23316 |
371 | return false; executed: return false; Execution Count:531 | 531 |
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 yes Evaluation Count:413 | yes Evaluation Count:26253 |
evaluated: fi.isFile() yes Evaluation Count:83 | yes Evaluation Count:330 |
| 83-26253 |
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) yes Evaluation Count:87 | yes Evaluation Count:26496 |
| 87-26496 |
381 | && (filters & QDir::PermissionMask) != QDir::PermissionMask); partially evaluated: (filters & QDir::PermissionMask) != QDir::PermissionMask yes Evaluation Count:87 | no Evaluation Count:0 |
| 0-87 |
382 | const bool doWritable = !filterPermissions || (filters & QDir::Writable); evaluated: !filterPermissions yes Evaluation Count:26496 | yes Evaluation Count:87 |
evaluated: (filters & QDir::Writable) yes Evaluation Count:7 | yes Evaluation Count:80 |
| 7-26496 |
383 | const bool doExecutable = !filterPermissions || (filters & QDir::Executable); evaluated: !filterPermissions yes Evaluation Count:26496 | yes Evaluation Count:87 |
partially evaluated: (filters & QDir::Executable) no Evaluation Count:0 | yes Evaluation Count:87 |
| 0-26496 |
384 | const bool doReadable = !filterPermissions || (filters & QDir::Readable); evaluated: !filterPermissions yes Evaluation Count:26496 | yes Evaluation Count:87 |
evaluated: (filters & QDir::Readable) yes Evaluation Count:80 | yes Evaluation Count:7 |
| 7-26496 |
385 | if (filterPermissions evaluated: filterPermissions yes Evaluation Count:87 | yes Evaluation Count:26496 |
| 87-26496 |
386 | && ((doReadable && !fi.isReadable()) evaluated: doReadable yes Evaluation Count:80 | yes Evaluation Count:7 |
partially evaluated: !fi.isReadable() no Evaluation Count:0 | yes Evaluation Count:80 |
| 0-80 |
387 | || (doWritable && !fi.isWritable()) evaluated: doWritable yes Evaluation Count:7 | yes Evaluation Count:80 |
evaluated: !fi.isWritable() yes Evaluation Count:2 | yes Evaluation Count:5 |
| 2-80 |
388 | || (doExecutable && !fi.isExecutable()))) { partially evaluated: doExecutable 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:26581 | 26581 |
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 | */ | - |
410 | QDirIterator::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 | */ | - |
429 | QDirIterator::QDirIterator(const QString &path, QDir::Filters filters, IteratorFlags flags) | - |
430 | : d(new QDirIteratorPrivate(QFileSystemEntry(path), QStringList(), filters, flags)) | - |
431 | { | - |
432 | } executed: } Execution Count:2486 | 2486 |
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 | */ | - |
446 | QDirIterator::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 | */ | - |
464 | QDirIterator::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:1164 | 1164 |
469 | | - |
470 | /*! | - |
471 | Destroys the QDirIterator. | - |
472 | */ | - |
473 | QDirIterator::~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 | */ | - |
487 | QString 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:26571 | 26571 |
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 | */ | - |
499 | bool QDirIterator::hasNext() const | - |
500 | { | - |
501 | if (d->engine) evaluated: d->engine yes Evaluation Count:193 | yes Evaluation Count:30103 |
| 193-30103 |
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:30103 | 30103 |
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 | */ | - |
521 | QString 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 | */ | - |
531 | QString QDirIterator::filePath() const | - |
532 | { | - |
533 | return d->currentFileInfo.filePath(); executed: return d->currentFileInfo.filePath(); Execution Count:29193 | 29193 |
534 | } | - |
535 | | - |
536 | /*! | - |
537 | Returns a QFileInfo for the current directory entry. | - |
538 | | - |
539 | \sa filePath(), fileName() | - |
540 | */ | - |
541 | QFileInfo QDirIterator::fileInfo() const | - |
542 | { | - |
543 | return d->currentFileInfo; executed: return d->currentFileInfo; Execution Count:24154 | 24154 |
544 | } | - |
545 | | - |
546 | /*! | - |
547 | Returns the base directory of the iterator. | - |
548 | */ | - |
549 | QString QDirIterator::path() const | - |
550 | { | - |
551 | return d->dirEntry.filePath(); executed: return d->dirEntry.filePath(); Execution Count:44 | 44 |
552 | } | - |
553 | | - |
554 | QT_END_NAMESPACE | - |
555 | | - |
| | |