io/qdir.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#include "qplatformdefs.h" -
43#include "qdir.h" -
44#include "qdir_p.h" -
45#include "qabstractfileengine_p.h" -
46#include "qfsfileengine_p.h" -
47#ifndef QT_NO_DEBUG_STREAM -
48#include "qdebug.h" -
49#endif -
50#include "qdiriterator.h" -
51#include "qdatetime.h" -
52#include "qstring.h" -
53#include "qregexp.h" -
54#include "qvector.h" -
55#include "qalgorithms.h" -
56#include "qvarlengtharray.h" -
57#include "qfilesystementry_p.h" -
58#include "qfilesystemmetadata_p.h" -
59#include "qfilesystemengine_p.h" -
60#include <qstringbuilder.h> -
61 -
62#ifdef QT_BUILD_CORE_LIB -
63# include "qresource.h" -
64# include "private/qcoreglobaldata_p.h" -
65#endif -
66 -
67#include <stdlib.h> -
68 -
69QT_BEGIN_NAMESPACE -
70 -
71#if defined(Q_OS_WIN) -
72static QString driveSpec(const QString &path) -
73{ -
74 if (path.size() < 2) -
75 return QString(); -
76 char c = path.at(0).toLatin1(); -
77 if (c < 'a' && c > 'z' && c < 'A' && c > 'Z') -
78 return QString(); -
79 if (path.at(1).toLatin1() != ':') -
80 return QString(); -
81 return path.mid(0, 2); -
82} -
83#endif -
84 -
85//************* QDirPrivate -
86QDirPrivate::QDirPrivate(const QString &path, const QStringList &nameFilters_, QDir::SortFlags sort_, QDir::Filters filters_) -
87 : QSharedData() -
88 , nameFilters(nameFilters_) -
89 , sort(sort_) -
90 , filters(filters_) -
91 , fileListsInitialized(false) -
92{ -
93 setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
executed (the execution status of this line is deduced): setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
-
94 -
95 bool empty = nameFilters.isEmpty();
executed (the execution status of this line is deduced): bool empty = nameFilters.isEmpty();
-
96 if (!empty) {
evaluated: !empty
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:9517
27-9517
97 empty = true;
executed (the execution status of this line is deduced): empty = true;
-
98 for (int i = 0; i < nameFilters.size(); ++i) {
partially evaluated: i < nameFilters.size()
TRUEFALSE
yes
Evaluation Count:27
no
Evaluation Count:0
0-27
99 if (!nameFilters.at(i).isEmpty()) {
partially evaluated: !nameFilters.at(i).isEmpty()
TRUEFALSE
yes
Evaluation Count:27
no
Evaluation Count:0
0-27
100 empty = false;
executed (the execution status of this line is deduced): empty = false;
-
101 break;
executed: break;
Execution Count:27
27
102 } -
103 }
never executed: }
0
104 }
executed: }
Execution Count:27
27
105 if (empty)
evaluated: empty
TRUEFALSE
yes
Evaluation Count:9517
yes
Evaluation Count:27
27-9517
106 nameFilters = QStringList(QString::fromLatin1("*"));
executed: nameFilters = QStringList(QString::fromLatin1("*"));
Execution Count:9517
9517
107}
executed: }
Execution Count:9544
9544
108 -
109QDirPrivate::QDirPrivate(const QDirPrivate &copy) -
110 : QSharedData(copy) -
111 , nameFilters(copy.nameFilters) -
112 , sort(copy.sort) -
113 , filters(copy.filters) -
114 , fileListsInitialized(false) -
115 , dirEntry(copy.dirEntry) -
116 , metaData(copy.metaData) -
117{ -
118}
executed: }
Execution Count:287
287
119 -
120bool QDirPrivate::exists() const -
121{ -
122 if (fileEngine.isNull()) {
evaluated: fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:2960
yes
Evaluation Count:7
7-2960
123 QFileSystemEngine::fillMetaData(dirEntry, metaData,
executed (the execution status of this line is deduced): QFileSystemEngine::fillMetaData(dirEntry, metaData,
-
124 QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
executed (the execution status of this line is deduced): QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType);
-
125 return metaData.exists() && metaData.isDirectory();
executed: return metaData.exists() && metaData.isDirectory();
Execution Count:2960
2960
126 } -
127 const QAbstractFileEngine::FileFlags info =
executed (the execution status of this line is deduced): const QAbstractFileEngine::FileFlags info =
-
128 fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
executed (the execution status of this line is deduced): fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
-
129 | QAbstractFileEngine::ExistsFlag
executed (the execution status of this line is deduced): | QAbstractFileEngine::ExistsFlag
-
130 | QAbstractFileEngine::Refresh);
executed (the execution status of this line is deduced): | QAbstractFileEngine::Refresh);
-
131 if (!(info & QAbstractFileEngine::DirectoryType))
evaluated: !(info & QAbstractFileEngine::DirectoryType)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
1-6
132 return false;
executed: return false;
Execution Count:1
1
133 return info & QAbstractFileEngine::ExistsFlag;
executed: return info & QAbstractFileEngine::ExistsFlag;
Execution Count:6
6
134} -
135 -
136// static -
137inline QChar QDirPrivate::getFilterSepChar(const QString &nameFilter) -
138{ -
139 QChar sep(QLatin1Char(';'));
executed (the execution status of this line is deduced): QChar sep(QLatin1Char(';'));
-
140 int i = nameFilter.indexOf(sep, 0);
executed (the execution status of this line is deduced): int i = nameFilter.indexOf(sep, 0);
-
141 if (i == -1 && nameFilter.indexOf(QLatin1Char(' '), 0) != -1)
evaluated: i == -1
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:3
partially evaluated: nameFilter.indexOf(QLatin1Char(' '), 0) != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
0-29
142 sep = QChar(QLatin1Char(' '));
never executed: sep = QChar(QLatin1Char(' '));
0
143 return sep;
executed: return sep;
Execution Count:32
32
144} -
145 -
146// static -
147inline QStringList QDirPrivate::splitFilters(const QString &nameFilter, QChar sep) -
148{ -
149 if (sep == 0)
partially evaluated: sep == 0
TRUEFALSE
yes
Evaluation Count:32
no
Evaluation Count:0
0-32
150 sep = getFilterSepChar(nameFilter);
executed: sep = getFilterSepChar(nameFilter);
Execution Count:32
32
151 QStringList ret = nameFilter.split(sep);
executed (the execution status of this line is deduced): QStringList ret = nameFilter.split(sep);
-
152 for (int i = 0; i < ret.count(); ++i)
evaluated: i < ret.count()
TRUEFALSE
yes
Evaluation Count:35
yes
Evaluation Count:32
32-35
153 ret[i] = ret[i].trimmed();
executed: ret[i] = ret[i].trimmed();
Execution Count:35
35
154 return ret;
executed: return ret;
Execution Count:32
32
155} -
156 -
157inline void QDirPrivate::setPath(const QString &path) -
158{ -
159 QString p = QDir::fromNativeSeparators(path);
executed (the execution status of this line is deduced): QString p = QDir::fromNativeSeparators(path);
-
160 if (p.endsWith(QLatin1Char('/'))
evaluated: p.endsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:335
yes
Evaluation Count:9569
335-9569
161 && p.length() > 1
evaluated: p.length() > 1
TRUEFALSE
yes
Evaluation Count:185
yes
Evaluation Count:150
150-185
162#if defined(Q_OS_WIN) -
163 && (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter())) -
164#endif -
165 ) { -
166 p.truncate(p.length() - 1);
executed (the execution status of this line is deduced): p.truncate(p.length() - 1);
-
167 }
executed: }
Execution Count:185
185
168 -
169 dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath());
executed (the execution status of this line is deduced): dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath());
-
170 metaData.clear();
executed (the execution status of this line is deduced): metaData.clear();
-
171 initFileEngine();
executed (the execution status of this line is deduced): initFileEngine();
-
172 clearFileLists();
executed (the execution status of this line is deduced): clearFileLists();
-
173 absoluteDirEntry = QFileSystemEntry();
executed (the execution status of this line is deduced): absoluteDirEntry = QFileSystemEntry();
-
174}
executed: }
Execution Count:9904
9904
175 -
176inline void QDirPrivate::clearFileLists() -
177{ -
178 fileListsInitialized = false;
executed (the execution status of this line is deduced): fileListsInitialized = false;
-
179 files.clear();
executed (the execution status of this line is deduced): files.clear();
-
180 fileInfos.clear();
executed (the execution status of this line is deduced): fileInfos.clear();
-
181}
executed: }
Execution Count:10404
10404
182 -
183inline void QDirPrivate::resolveAbsoluteEntry() const -
184{ -
185 if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty())
evaluated: !absoluteDirEntry.isEmpty()
TRUEFALSE
yes
Evaluation Count:2833
yes
Evaluation Count:5882
partially evaluated: dirEntry.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5882
0-5882
186 return;
executed: return;
Execution Count:2833
2833
187 -
188 QString absoluteName;
executed (the execution status of this line is deduced): QString absoluteName;
-
189 if (fileEngine.isNull()) {
evaluated: fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:5877
yes
Evaluation Count:5
5-5877
190 if (!dirEntry.isRelative() && dirEntry.isClean()) {
evaluated: !dirEntry.isRelative()
TRUEFALSE
yes
Evaluation Count:5552
yes
Evaluation Count:325
evaluated: dirEntry.isClean()
TRUEFALSE
yes
Evaluation Count:5467
yes
Evaluation Count:85
85-5552
191 absoluteDirEntry = dirEntry;
executed (the execution status of this line is deduced): absoluteDirEntry = dirEntry;
-
192 return;
executed: return;
Execution Count:5467
5467
193 } -
194 -
195 absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
executed (the execution status of this line is deduced): absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
-
196 } else {
executed: }
Execution Count:410
410
197 absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
executed (the execution status of this line is deduced): absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
-
198 }
executed: }
Execution Count:5
5
199 -
200 absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName), QFileSystemEntry::FromInternalPath());
executed (the execution status of this line is deduced): absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName), QFileSystemEntry::FromInternalPath());
-
201}
executed: }
Execution Count:415
415
202 -
203/* For sorting */ -
204struct QDirSortItem -
205{ -
206 mutable QString filename_cache; -
207 mutable QString suffix_cache; -
208 QFileInfo item; -
209}; -
210 -
211 -
212class QDirSortItemComparator -
213{ -
214 int qt_cmp_si_sort_flags; -
215public: -
216 QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {}
executed: }
Execution Count:883
883
217 bool operator()(const QDirSortItem &, const QDirSortItem &); -
218}; -
219 -
220bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortItem &n2) -
221{ -
222 const QDirSortItem* f1 = &n1;
executed (the execution status of this line is deduced): const QDirSortItem* f1 = &n1;
-
223 const QDirSortItem* f2 = &n2;
executed (the execution status of this line is deduced): const QDirSortItem* f2 = &n2;
-
224 -
225 if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir()))
evaluated: (qt_cmp_si_sort_flags & QDir::DirsFirst)
TRUEFALSE
yes
Evaluation Count:10323
yes
Evaluation Count:87810
evaluated: (f1->item.isDir() != f2->item.isDir())
TRUEFALSE
yes
Evaluation Count:1463
yes
Evaluation Count:8860
1463-87810
226 return f1->item.isDir();
executed: return f1->item.isDir();
Execution Count:1463
1463
227 if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir()))
evaluated: (qt_cmp_si_sort_flags & QDir::DirsLast)
TRUEFALSE
yes
Evaluation Count:218
yes
Evaluation Count:96452
evaluated: (f1->item.isDir() != f2->item.isDir())
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:180
38-96452
228 return !f1->item.isDir();
executed: return !f1->item.isDir();
Execution Count:38
38
229 -
230 int r = 0;
executed (the execution status of this line is deduced): int r = 0;
-
231 int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask)
executed (the execution status of this line is deduced): int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask)
-
232 | (qt_cmp_si_sort_flags & QDir::Type);
executed (the execution status of this line is deduced): | (qt_cmp_si_sort_flags & QDir::Type);
-
233 -
234 switch (sortBy) { -
235 case QDir::Time: { -
236 QDateTime firstModified = f1->item.lastModified();
executed (the execution status of this line is deduced): QDateTime firstModified = f1->item.lastModified();
-
237 QDateTime secondModified = f2->item.lastModified();
executed (the execution status of this line is deduced): QDateTime secondModified = f2->item.lastModified();
-
238 -
239 // QDateTime by default will do all sorts of conversions on these to -
240 // find timezones, which is incredibly expensive. As we aren't -
241 // presenting these to the user, we don't care (at all) about the -
242 // local timezone, so force them to UTC to avoid that conversion. -
243 firstModified.setTimeSpec(Qt::UTC);
executed (the execution status of this line is deduced): firstModified.setTimeSpec(Qt::UTC);
-
244 secondModified.setTimeSpec(Qt::UTC);
executed (the execution status of this line is deduced): secondModified.setTimeSpec(Qt::UTC);
-
245 -
246 r = firstModified.secsTo(secondModified);
executed (the execution status of this line is deduced): r = firstModified.secsTo(secondModified);
-
247 break;
executed: break;
Execution Count:627
627
248 } -
249 case QDir::Size: -
250 r = int(qBound<qint64>(-1, f2->item.size() - f1->item.size(), 1));
executed (the execution status of this line is deduced): r = int(qBound<qint64>(-1, f2->item.size() - f1->item.size(), 1));
-
251 break;
executed: break;
Execution Count:833
833
252 case QDir::Type: -
253 { -
254 bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
executed (the execution status of this line is deduced): bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
-
255 -
256 if (f1->suffix_cache.isNull())
evaluated: f1->suffix_cache.isNull()
TRUEFALSE
yes
Evaluation Count:729
yes
Evaluation Count:358
358-729
257 f1->suffix_cache = ic ? f1->item.suffix().toLower()
executed: f1->suffix_cache = ic ? f1->item.suffix().toLower() : f1->item.suffix();
Execution Count:729
evaluated: ic
TRUEFALSE
yes
Evaluation Count:591
yes
Evaluation Count:138
138-729
258 : f1->item.suffix();
executed: f1->suffix_cache = ic ? f1->item.suffix().toLower() : f1->item.suffix();
Execution Count:729
729
259 if (f2->suffix_cache.isNull())
evaluated: f2->suffix_cache.isNull()
TRUEFALSE
yes
Evaluation Count:731
yes
Evaluation Count:356
356-731
260 f2->suffix_cache = ic ? f2->item.suffix().toLower()
executed: f2->suffix_cache = ic ? f2->item.suffix().toLower() : f2->item.suffix();
Execution Count:731
evaluated: ic
TRUEFALSE
yes
Evaluation Count:594
yes
Evaluation Count:137
137-731
261 : f2->item.suffix();
executed: f2->suffix_cache = ic ? f2->item.suffix().toLower() : f2->item.suffix();
Execution Count:731
731
262 -
263 r = qt_cmp_si_sort_flags & QDir::LocaleAware
partially evaluated: qt_cmp_si_sort_flags & QDir::LocaleAware
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1087
0-1087
264 ? f1->suffix_cache.localeAwareCompare(f2->suffix_cache)
executed (the execution status of this line is deduced): ? f1->suffix_cache.localeAwareCompare(f2->suffix_cache)
-
265 : f1->suffix_cache.compare(f2->suffix_cache);
executed (the execution status of this line is deduced): : f1->suffix_cache.compare(f2->suffix_cache);
-
266 } -
267 break;
executed: break;
Execution Count:1087
1087
268 default: -
269 ; -
270 }
executed: }
Execution Count:94085
94085
271 -
272 if (r == 0 && sortBy != QDir::Unsorted) {
evaluated: r == 0
TRUEFALSE
yes
Evaluation Count:95626
yes
Evaluation Count:1006
partially evaluated: sortBy != QDir::Unsorted
TRUEFALSE
yes
Evaluation Count:95626
no
Evaluation Count:0
0-95626
273 // Still not sorted - sort by name -
274 bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
executed (the execution status of this line is deduced): bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase;
-
275 -
276 if (f1->filename_cache.isNull())
evaluated: f1->filename_cache.isNull()
TRUEFALSE
yes
Evaluation Count:9282
yes
Evaluation Count:86344
9282-86344
277 f1->filename_cache = ic ? f1->item.fileName().toLower()
executed: f1->filename_cache = ic ? f1->item.fileName().toLower() : f1->item.fileName();
Execution Count:9282
evaluated: ic
TRUEFALSE
yes
Evaluation Count:3954
yes
Evaluation Count:5328
3954-9282
278 : f1->item.fileName();
executed: f1->filename_cache = ic ? f1->item.fileName().toLower() : f1->item.fileName();
Execution Count:9282
9282
279 if (f2->filename_cache.isNull())
evaluated: f2->filename_cache.isNull()
TRUEFALSE
yes
Evaluation Count:5702
yes
Evaluation Count:89924
5702-89924
280 f2->filename_cache = ic ? f2->item.fileName().toLower()
executed: f2->filename_cache = ic ? f2->item.fileName().toLower() : f2->item.fileName();
Execution Count:5702
evaluated: ic
TRUEFALSE
yes
Evaluation Count:2307
yes
Evaluation Count:3395
2307-5702
281 : f2->item.fileName();
executed: f2->filename_cache = ic ? f2->item.fileName().toLower() : f2->item.fileName();
Execution Count:5702
5702
282 -
283 r = qt_cmp_si_sort_flags & QDir::LocaleAware
partially evaluated: qt_cmp_si_sort_flags & QDir::LocaleAware
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:95626
0-95626
284 ? f1->filename_cache.localeAwareCompare(f2->filename_cache)
executed (the execution status of this line is deduced): ? f1->filename_cache.localeAwareCompare(f2->filename_cache)
-
285 : f1->filename_cache.compare(f2->filename_cache);
executed (the execution status of this line is deduced): : f1->filename_cache.compare(f2->filename_cache);
-
286 }
executed: }
Execution Count:95626
95626
287 if (r == 0) // Enforce an order - the order the items appear in the array
evaluated: r == 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:96630
2-96630
288 r = (&n1) - (&n2);
executed: r = (&n1) - (&n2);
Execution Count:2
2
289 if (qt_cmp_si_sort_flags & QDir::Reversed)
evaluated: qt_cmp_si_sort_flags & QDir::Reversed
TRUEFALSE
yes
Evaluation Count:1043
yes
Evaluation Count:95589
1043-95589
290 return r > 0;
executed: return r > 0;
Execution Count:1043
1043
291 return r < 0;
executed: return r < 0;
Execution Count:95589
95589
292} -
293 -
294inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, -
295 QStringList *names, QFileInfoList *infos) -
296{ -
297 // names and infos are always empty lists or 0 here -
298 int n = l.size();
executed (the execution status of this line is deduced): int n = l.size();
-
299 if (n > 0) {
evaluated: n > 0
TRUEFALSE
yes
Evaluation Count:950
yes
Evaluation Count:262
262-950
300 if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) {
evaluated: n == 1
TRUEFALSE
yes
Evaluation Count:67
yes
Evaluation Count:883
partially evaluated: (sort & QDir::SortByMask) == QDir::Unsorted
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:883
0-883
301 if (infos)
evaluated: infos
TRUEFALSE
yes
Evaluation Count:49
yes
Evaluation Count:18
18-49
302 *infos = l;
executed: *infos = l;
Execution Count:49
49
303 if (names) {
evaluated: names
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:47
20-47
304 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:20
20
305 names->append(l.at(i).fileName());
executed: names->append(l.at(i).fileName());
Execution Count:20
20
306 }
executed: }
Execution Count:20
20
307 } else {
executed: }
Execution Count:67
67
308 QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]);
executed (the execution status of this line is deduced): QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]);
-
309 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:15195
yes
Evaluation Count:883
883-15195
310 si[i].item = l.at(i);
executed: si[i].item = l.at(i);
Execution Count:15195
15195
311 qSort(si.data(), si.data() + n, QDirSortItemComparator(sort));
executed (the execution status of this line is deduced): qSort(si.data(), si.data() + n, QDirSortItemComparator(sort));
-
312 // put them back in the list(s) -
313 if (infos) {
evaluated: infos
TRUEFALSE
yes
Evaluation Count:704
yes
Evaluation Count:179
179-704
314 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:12043
yes
Evaluation Count:704
704-12043
315 infos->append(si[i].item);
executed: infos->append(si[i].item);
Execution Count:12043
12043
316 }
executed: }
Execution Count:704
704
317 if (names) {
evaluated: names
TRUEFALSE
yes
Evaluation Count:238
yes
Evaluation Count:645
238-645
318 for (int i = 0; i < n; ++i)
evaluated: i < n
TRUEFALSE
yes
Evaluation Count:3461
yes
Evaluation Count:238
238-3461
319 names->append(si[i].item.fileName());
executed: names->append(si[i].item.fileName());
Execution Count:3461
3461
320 }
executed: }
Execution Count:238
238
321 }
executed: }
Execution Count:883
883
322 } -
323}
executed: }
Execution Count:1212
1212
324inline void QDirPrivate::initFileLists(const QDir &dir) const -
325{ -
326 if (!fileListsInitialized) {
evaluated: !fileListsInitialized
TRUEFALSE
yes
Evaluation Count:65
yes
Evaluation Count:30
30-65
327 QFileInfoList l;
executed (the execution status of this line is deduced): QFileInfoList l;
-
328 QDirIterator it(dir);
executed (the execution status of this line is deduced): QDirIterator it(dir);
-
329 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:311
yes
Evaluation Count:65
65-311
330 it.next();
executed (the execution status of this line is deduced): it.next();
-
331 l.append(it.fileInfo());
executed (the execution status of this line is deduced): l.append(it.fileInfo());
-
332 }
executed: }
Execution Count:311
311
333 sortFileList(sort, l, &files, &fileInfos);
executed (the execution status of this line is deduced): sortFileList(sort, l, &files, &fileInfos);
-
334 fileListsInitialized = true;
executed (the execution status of this line is deduced): fileListsInitialized = true;
-
335 }
executed: }
Execution Count:65
65
336}
executed: }
Execution Count:95
95
337 -
338inline void QDirPrivate::initFileEngine() -
339{ -
340 fileEngine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
executed (the execution status of this line is deduced): fileEngine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
-
341}
executed: }
Execution Count:10404
10404
342 -
343/*! -
344 \class QDir -
345 \inmodule QtCore -
346 \brief The QDir class provides access to directory structures and their contents. -
347 -
348 \ingroup io -
349 \ingroup shared -
350 \reentrant -
351 -
352 -
353 A QDir is used to manipulate path names, access information -
354 regarding paths and files, and manipulate the underlying file -
355 system. It can also be used to access Qt's \l{resource system}. -
356 -
357 Qt uses "/" as a universal directory separator in the same way -
358 that "/" is used as a path separator in URLs. If you always use -
359 "/" as a directory separator, Qt will translate your paths to -
360 conform to the underlying operating system. -
361 -
362 A QDir can point to a file using either a relative or an absolute -
363 path. Absolute paths begin with the directory separator -
364 (optionally preceded by a drive specification under Windows). -
365 Relative file names begin with a directory name or a file name and -
366 specify a path relative to the current directory. -
367 -
368 Examples of absolute paths: -
369 -
370 \snippet code/src_corelib_io_qdir.cpp 0 -
371 -
372 On Windows, the second example above will be translated to -
373 \c{C:\Documents and Settings} when used to access files. -
374 -
375 Examples of relative paths: -
376 -
377 \snippet code/src_corelib_io_qdir.cpp 1 -
378 -
379 You can use the isRelative() or isAbsolute() functions to check if -
380 a QDir is using a relative or an absolute file path. Call -
381 makeAbsolute() to convert a relative QDir to an absolute one. -
382 -
383 \section1 Navigation and Directory Operations -
384 -
385 A directory's path can be obtained with the path() function, and -
386 a new path set with the setPath() function. The absolute path to -
387 a directory is found by calling absolutePath(). -
388 -
389 The name of a directory is found using the dirName() function. This -
390 typically returns the last element in the absolute path that specifies -
391 the location of the directory. However, it can also return "." if -
392 the QDir represents the current directory. -
393 -
394 \snippet code/src_corelib_io_qdir.cpp 2 -
395 -
396 The path for a directory can also be changed with the cd() and cdUp() -
397 functions, both of which operate like familiar shell commands. -
398 When cd() is called with the name of an existing directory, the QDir -
399 object changes directory so that it represents that directory instead. -
400 The cdUp() function changes the directory of the QDir object so that -
401 it refers to its parent directory; i.e. cd("..") is equivalent to -
402 cdUp(). -
403 -
404 Directories can be created with mkdir(), renamed with rename(), and -
405 removed with rmdir(). -
406 -
407 You can test for the presence of a directory with a given name by -
408 using exists(), and the properties of a directory can be tested with -
409 isReadable(), isAbsolute(), isRelative(), and isRoot(). -
410 -
411 The refresh() function re-reads the directory's data from disk. -
412 -
413 \section1 Files and Directory Contents -
414 -
415 Directories contain a number of entries, representing files, -
416 directories, and symbolic links. The number of entries in a -
417 directory is returned by count(). -
418 A string list of the names of all the entries in a directory can be -
419 obtained with entryList(). If you need information about each -
420 entry, use entryInfoList() to obtain a list of QFileInfo objects. -
421 -
422 Paths to files and directories within a directory can be -
423 constructed using filePath() and absoluteFilePath(). -
424 The filePath() function returns a path to the specified file -
425 or directory relative to the path of the QDir object; -
426 absoluteFilePath() returns an absolute path to the specified -
427 file or directory. Neither of these functions checks for the -
428 existence of files or directory; they only construct paths. -
429 -
430 \snippet code/src_corelib_io_qdir.cpp 3 -
431 -
432 Files can be removed by using the remove() function. Directories -
433 cannot be removed in the same way as files; use rmdir() to remove -
434 them instead. -
435 -
436 It is possible to reduce the number of entries returned by -
437 entryList() and entryInfoList() by applying filters to a QDir object. -
438 You can apply a name filter to specify a pattern with wildcards that -
439 file names need to match, an attribute filter that selects properties -
440 of entries and can distinguish between files and directories, and a -
441 sort order. -
442 -
443 Name filters are lists of strings that are passed to setNameFilters(). -
444 Attribute filters consist of a bitwise OR combination of Filters, and -
445 these are specified when calling setFilter(). -
446 The sort order is specified using setSorting() with a bitwise OR -
447 combination of SortFlags. -
448 -
449 You can test to see if a filename matches a filter using the match() -
450 function. -
451 -
452 Filter and sort order flags may also be specified when calling -
453 entryList() and entryInfoList() in order to override previously defined -
454 behavior. -
455 -
456 \section1 The Current Directory and Other Special Paths -
457 -
458 Access to some common directories is provided with a number of static -
459 functions that return QDir objects. There are also corresponding functions -
460 for these that return strings: -
461 -
462 \table -
463 \header \li QDir \li QString \li Return Value -
464 \row \li current() \li currentPath() \li The application's working directory -
465 \row \li home() \li homePath() \li The user's home directory -
466 \row \li root() \li rootPath() \li The root directory -
467 \row \li temp() \li tempPath() \li The system's temporary directory -
468 \endtable -
469 -
470 The setCurrent() static function can also be used to set the application's -
471 working directory. -
472 -
473 If you want to find the directory containing the application's executable, -
474 see \l{QCoreApplication::applicationDirPath()}. -
475 -
476 The drives() static function provides a list of root directories for each -
477 device that contains a filing system. On Unix systems this returns a list -
478 containing a single root directory "/"; on Windows the list will usually -
479 contain \c{C:/}, and possibly other drive letters such as \c{D:/}, depending -
480 on the configuration of the user's system. -
481 -
482 \section1 Path Manipulation and Strings -
483 -
484 Paths containing "." elements that reference the current directory at that -
485 point in the path, ".." elements that reference the parent directory, and -
486 symbolic links can be reduced to a canonical form using the canonicalPath() -
487 function. -
488 -
489 Paths can also be simplified by using cleanPath() to remove redundant "/" -
490 and ".." elements. -
491 -
492 It is sometimes necessary to be able to show a path in the native -
493 representation for the user's platform. The static toNativeSeparators() -
494 function returns a copy of the specified path in which each directory -
495 separator is replaced by the appropriate separator for the underlying -
496 operating system. -
497 -
498 \section1 Examples -
499 -
500 Check if a directory exists: -
501 -
502 \snippet code/src_corelib_io_qdir.cpp 4 -
503 -
504 (We could also use the static convenience function -
505 QFile::exists().) -
506 -
507 Traversing directories and reading a file: -
508 -
509 \snippet code/src_corelib_io_qdir.cpp 5 -
510 -
511 A program that lists all the files in the current directory -
512 (excluding symbolic links), sorted by size, smallest first: -
513 -
514 \snippet qdir-listfiles/main.cpp 0 -
515 -
516 \sa QFileInfo, QFile, QFileDialog, QCoreApplication::applicationDirPath(), {Find Files Example} -
517*/ -
518 -
519/*! -
520 \internal -
521*/ -
522QDir::QDir(QDirPrivate &p) : d_ptr(&p) -
523{ -
524}
never executed: }
0
525 -
526/*! -
527 Constructs a QDir pointing to the given directory \a path. If path -
528 is empty the program's working directory, ("."), is used. -
529 -
530 \sa currentPath() -
531*/ -
532QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(path)) -
533{ -
534}
executed: }
Execution Count:9517
9517
535 -
536/*! -
537 Constructs a QDir with path \a path, that filters its entries by -
538 name using \a nameFilter and by attributes using \a filters. It -
539 also sorts the names using \a sort. -
540 -
541 The default \a nameFilter is an empty string, which excludes -
542 nothing; the default \a filters is \l AllEntries, which also means -
543 exclude nothing. The default \a sort is \l Name | \l IgnoreCase, -
544 i.e. sort by name case-insensitively. -
545 -
546 If \a path is an empty string, QDir uses "." (the current -
547 directory). If \a nameFilter is an empty string, QDir uses the -
548 name filter "*" (all files). -
549 -
550 Note that \a path need not exist. -
551 -
552 \sa exists(), setPath(), setNameFilters(), setFilter(), setSorting() -
553*/ -
554QDir::QDir(const QString &path, const QString &nameFilter, -
555 SortFlags sort, Filters filters) -
556 : d_ptr(new QDirPrivate(path, QDir::nameFiltersFromString(nameFilter), sort, filters)) -
557{ -
558}
executed: }
Execution Count:27
27
559 -
560/*! -
561 Constructs a QDir object that is a copy of the QDir object for -
562 directory \a dir. -
563 -
564 \sa operator=() -
565*/ -
566QDir::QDir(const QDir &dir) -
567 : d_ptr(dir.d_ptr) -
568{ -
569}
executed: }
Execution Count:246
246
570 -
571/*! -
572 Destroys the QDir object frees up its resources. This has no -
573 effect on the underlying directory in the file system. -
574*/ -
575QDir::~QDir() -
576{ -
577} -
578 -
579/*! -
580 Sets the path of the directory to \a path. The path is cleaned of -
581 redundant ".", ".." and of multiple separators. No check is made -
582 to see whether a directory with this path actually exists; but you -
583 can check for yourself using exists(). -
584 -
585 The path can be either absolute or relative. Absolute paths begin -
586 with the directory separator "/" (optionally preceded by a drive -
587 specification under Windows). Relative file names begin with a -
588 directory name or a file name and specify a path relative to the -
589 current directory. An example of an absolute path is the string -
590 "/tmp/quartz", a relative path might look like "src/fatlib". -
591 -
592 \sa path(), absolutePath(), exists(), cleanPath(), dirName(), -
593 absoluteFilePath(), isRelative(), makeAbsolute() -
594*/ -
595void QDir::setPath(const QString &path) -
596{ -
597 d_ptr->setPath(path);
executed (the execution status of this line is deduced): d_ptr->setPath(path);
-
598}
executed: }
Execution Count:317
317
599 -
600/*! -
601 Returns the path. This may contain symbolic links, but never -
602 contains redundant ".", ".." or multiple separators. -
603 -
604 The returned path can be either absolute or relative (see -
605 setPath()). -
606 -
607 \sa setPath(), absolutePath(), exists(), cleanPath(), dirName(), -
608 absoluteFilePath(), toNativeSeparators(), makeAbsolute() -
609*/ -
610QString QDir::path() const -
611{ -
612 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
613 return d->dirEntry.filePath();
executed: return d->dirEntry.filePath();
Execution Count:11265
11265
614} -
615 -
616/*! -
617 Returns the absolute path (a path that starts with "/" or with a -
618 drive specification), which may contain symbolic links, but never -
619 contains redundant ".", ".." or multiple separators. -
620 -
621 \sa setPath(), canonicalPath(), exists(), cleanPath(), -
622 dirName(), absoluteFilePath() -
623*/ -
624QString QDir::absolutePath() const -
625{ -
626 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
627 d->resolveAbsoluteEntry();
executed (the execution status of this line is deduced): d->resolveAbsoluteEntry();
-
628 return d->absoluteDirEntry.filePath();
executed: return d->absoluteDirEntry.filePath();
Execution Count:8214
8214
629} -
630 -
631/*! -
632 Returns the canonical path, i.e. a path without symbolic links or -
633 redundant "." or ".." elements. -
634 -
635 On systems that do not have symbolic links this function will -
636 always return the same string that absolutePath() returns. If the -
637 canonical path does not exist (normally due to dangling symbolic -
638 links) canonicalPath() returns an empty string. -
639 -
640 Example: -
641 -
642 \snippet code/src_corelib_io_qdir.cpp 6 -
643 -
644 \sa path(), absolutePath(), exists(), cleanPath(), dirName(), -
645 absoluteFilePath() -
646*/ -
647QString QDir::canonicalPath() const -
648{ -
649 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
650 if (d->fileEngine.isNull()) {
evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:653
yes
Evaluation Count:1
1-653
651 QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
executed (the execution status of this line is deduced): QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
-
652 return answer.filePath();
executed: return answer.filePath();
Execution Count:653
653
653 } -
654 return d->fileEngine->fileName(QAbstractFileEngine::CanonicalName);
executed: return d->fileEngine->fileName(QAbstractFileEngine::CanonicalName);
Execution Count:1
1
655} -
656 -
657/*! -
658 Returns the name of the directory; this is \e not the same as the -
659 path, e.g. a directory with the name "mail", might have the path -
660 "/var/spool/mail". If the directory has no name (e.g. it is the -
661 root directory) an empty string is returned. -
662 -
663 No check is made to ensure that a directory with this name -
664 actually exists; but see exists(). -
665 -
666 \sa path(), filePath(), absolutePath(), absoluteFilePath() -
667*/ -
668QString QDir::dirName() const -
669{ -
670 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
671 return d->dirEntry.fileName();
executed: return d->dirEntry.fileName();
Execution Count:22
22
672} -
673 -
674/*! -
675 Returns the path name of a file in the directory. Does \e not -
676 check if the file actually exists in the directory; but see -
677 exists(). If the QDir is relative the returned path name will also -
678 be relative. Redundant multiple separators or "." and ".." -
679 directories in \a fileName are not removed (see cleanPath()). -
680 -
681 \sa dirName(), absoluteFilePath(), isRelative(), canonicalPath() -
682*/ -
683QString QDir::filePath(const QString &fileName) const -
684{ -
685 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
686 if (isAbsolutePath(fileName))
evaluated: isAbsolutePath(fileName)
TRUEFALSE
yes
Evaluation Count:3583
yes
Evaluation Count:3151
3151-3583
687 return QString(fileName);
executed: return QString(fileName);
Execution Count:3583
3583
688 -
689 QString ret = d->dirEntry.filePath();
executed (the execution status of this line is deduced): QString ret = d->dirEntry.filePath();
-
690 if (!fileName.isEmpty()) {
evaluated: !fileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:3148
yes
Evaluation Count:3
3-3148
691 if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/'))
partially evaluated: !ret.isEmpty()
TRUEFALSE
yes
Evaluation Count:3148
no
Evaluation Count:0
evaluated: ret[(int)ret.length()-1] != QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:3147
yes
Evaluation Count:1
partially evaluated: fileName[0] != QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:3147
no
Evaluation Count:0
0-3148
692 ret += QLatin1Char('/');
executed: ret += QLatin1Char('/');
Execution Count:3147
3147
693 ret += fileName;
executed (the execution status of this line is deduced): ret += fileName;
-
694 }
executed: }
Execution Count:3148
3148
695 return ret;
executed: return ret;
Execution Count:3151
3151
696} -
697 -
698/*! -
699 Returns the absolute path name of a file in the directory. Does \e -
700 not check if the file actually exists in the directory; but see -
701 exists(). Redundant multiple separators or "." and ".." -
702 directories in \a fileName are not removed (see cleanPath()). -
703 -
704 \sa relativeFilePath(), filePath(), canonicalPath() -
705*/ -
706QString QDir::absoluteFilePath(const QString &fileName) const -
707{ -
708 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
709 if (isAbsolutePath(fileName))
evaluated: isAbsolutePath(fileName)
TRUEFALSE
yes
Evaluation Count:121
yes
Evaluation Count:492
121-492
710 return fileName;
executed: return fileName;
Execution Count:121
121
711 -
712 d->resolveAbsoluteEntry();
executed (the execution status of this line is deduced): d->resolveAbsoluteEntry();
-
713 if (fileName.isEmpty())
evaluated: fileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:491
1-491
714 return d->absoluteDirEntry.filePath();
executed: return d->absoluteDirEntry.filePath();
Execution Count:1
1
715 if (!d->absoluteDirEntry.isRoot())
evaluated: !d->absoluteDirEntry.isRoot()
TRUEFALSE
yes
Evaluation Count:490
yes
Evaluation Count:1
1-490
716 return d->absoluteDirEntry.filePath() % QLatin1Char('/') % fileName;
executed: return d->absoluteDirEntry.filePath() % QLatin1Char('/') % fileName;
Execution Count:490
490
717 return d->absoluteDirEntry.filePath() % fileName;
executed: return d->absoluteDirEntry.filePath() % fileName;
Execution Count:1
1
718} -
719 -
720/*! -
721 Returns the path to \a fileName relative to the directory. -
722 -
723 \snippet code/src_corelib_io_qdir.cpp 7 -
724 -
725 \sa absoluteFilePath(), filePath(), canonicalPath() -
726*/ -
727QString QDir::relativeFilePath(const QString &fileName) const -
728{ -
729 QString dir = cleanPath(absolutePath());
executed (the execution status of this line is deduced): QString dir = cleanPath(absolutePath());
-
730 QString file = cleanPath(fileName);
executed (the execution status of this line is deduced): QString file = cleanPath(fileName);
-
731 -
732 if (isRelativePath(file) || isRelativePath(dir))
evaluated: isRelativePath(file)
TRUEFALSE
yes
Evaluation Count:41
yes
Evaluation Count:59
partially evaluated: isRelativePath(dir)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:59
0-59
733 return file;
executed: return file;
Execution Count:41
41
734 -
735#ifdef Q_OS_WIN -
736 QString dirDrive = driveSpec(dir); -
737 QString fileDrive = driveSpec(file); -
738 -
739 bool fileDriveMissing = false; -
740 if (fileDrive.isEmpty()) { -
741 fileDrive = dirDrive; -
742 fileDriveMissing = true; -
743 } -
744 -
745 if (fileDrive.toLower() != dirDrive.toLower() -
746 || (file.startsWith(QLatin1String("//")) -
747 && !dir.startsWith(QLatin1String("//")))) -
748 return file; -
749 -
750 dir.remove(0, dirDrive.size()); -
751 if (!fileDriveMissing) -
752 file.remove(0, fileDrive.size()); -
753#endif -
754 -
755 QString result;
executed (the execution status of this line is deduced): QString result;
-
756 QStringList dirElts = dir.split(QLatin1Char('/'), QString::SkipEmptyParts);
executed (the execution status of this line is deduced): QStringList dirElts = dir.split(QLatin1Char('/'), QString::SkipEmptyParts);
-
757 QStringList fileElts = file.split(QLatin1Char('/'), QString::SkipEmptyParts);
executed (the execution status of this line is deduced): QStringList fileElts = file.split(QLatin1Char('/'), QString::SkipEmptyParts);
-
758 -
759 int i = 0;
executed (the execution status of this line is deduced): int i = 0;
-
760 while (i < dirElts.size() && i < fileElts.size() &&
evaluated: i < dirElts.size()
TRUEFALSE
yes
Evaluation Count:489
yes
Evaluation Count:56
partially evaluated: i < fileElts.size()
TRUEFALSE
yes
Evaluation Count:489
no
Evaluation Count:0
0-489
761#if defined(Q_OS_WIN)
executed (the execution status of this line is deduced):
-
762 dirElts.at(i).toLower() == fileElts.at(i).toLower())
executed (the execution status of this line is deduced):
-
763#else
executed (the execution status of this line is deduced):
-
764 dirElts.at(i) == fileElts.at(i))
evaluated: dirElts.at(i) == fileElts.at(i)
TRUEFALSE
yes
Evaluation Count:486
yes
Evaluation Count:3
3-486
765#endif -
766 ++i;
executed: ++i;
Execution Count:486
486
767 -
768 for (int j = 0; j < dirElts.size() - i; ++j)
evaluated: j < dirElts.size() - i
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:59
22-59
769 result += QLatin1String("../");
executed: result += QLatin1String("../");
Execution Count:22
22
770 -
771 for (int j = i; j < fileElts.size(); ++j) {
evaluated: j < fileElts.size()
TRUEFALSE
yes
Evaluation Count:85
yes
Evaluation Count:59
59-85
772 result += fileElts.at(j);
executed (the execution status of this line is deduced): result += fileElts.at(j);
-
773 if (j < fileElts.size() - 1)
evaluated: j < fileElts.size() - 1
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:59
26-59
774 result += QLatin1Char('/');
executed: result += QLatin1Char('/');
Execution Count:26
26
775 }
executed: }
Execution Count:85
85
776 -
777 return result;
executed: return result;
Execution Count:59
59
778} -
779 -
780/*! -
781 \since 4.2 -
782 -
783 Returns \a pathName with the '/' separators converted to -
784 separators that are appropriate for the underlying operating -
785 system. -
786 -
787 On Windows, toNativeSeparators("c:/winnt/system32") returns -
788 "c:\\winnt\\system32". -
789 -
790 The returned string may be the same as the argument on some -
791 operating systems, for example on Unix. -
792 -
793 \sa fromNativeSeparators(), separator() -
794*/ -
795QString QDir::toNativeSeparators(const QString &pathName) -
796{ -
797#if defined(Q_OS_WIN) -
798 int i = pathName.indexOf(QLatin1Char('/')); -
799 if (i != -1) { -
800 QString n(pathName); -
801 -
802 QChar * const data = n.data(); -
803 data[i++] = QLatin1Char('\\'); -
804 -
805 for (; i < n.length(); ++i) { -
806 if (data[i] == QLatin1Char('/')) -
807 data[i] = QLatin1Char('\\'); -
808 } -
809 -
810 return n; -
811 } -
812#endif -
813 return pathName;
executed: return pathName;
Execution Count:50746
50746
814} -
815 -
816/*! -
817 \since 4.2 -
818 -
819 Returns \a pathName using '/' as file separator. On Windows, -
820 for instance, fromNativeSeparators("\c{c:\\winnt\\system32}") returns -
821 "c:/winnt/system32". -
822 -
823 The returned string may be the same as the argument on some -
824 operating systems, for example on Unix. -
825 -
826 \sa toNativeSeparators(), separator() -
827*/ -
828QString QDir::fromNativeSeparators(const QString &pathName) -
829{ -
830#if defined(Q_OS_WIN) -
831 int i = pathName.indexOf(QLatin1Char('\\')); -
832 if (i != -1) { -
833 QString n(pathName); -
834 -
835 QChar * const data = n.data(); -
836 data[i++] = QLatin1Char('/'); -
837 -
838 for (; i < n.length(); ++i) { -
839 if (data[i] == QLatin1Char('\\')) -
840 data[i] = QLatin1Char('/'); -
841 } -
842 -
843 return n; -
844 } -
845#endif -
846 return pathName;
executed: return pathName;
Execution Count:324249
324249
847} -
848 -
849/*! -
850 Changes the QDir's directory to \a dirName. -
851 -
852 Returns true if the new directory exists and is readable; -
853 otherwise returns false. Note that the logical cd() operation is -
854 not performed if the new directory does not exist. -
855 -
856 Calling cd("..") is equivalent to calling cdUp(). -
857 -
858 \sa cdUp(), isReadable(), exists(), path() -
859*/ -
860bool QDir::cd(const QString &dirName) -
861{ -
862 // Don't detach just yet. -
863 const QDirPrivate * const d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate * const d = d_ptr.constData();
-
864 -
865 if (dirName.isEmpty() || dirName == QLatin1String("."))
partially evaluated: dirName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:47
evaluated: dirName == QLatin1String(".")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:46
0-47
866 return true;
executed: return true;
Execution Count:1
1
867 QString newPath;
executed (the execution status of this line is deduced): QString newPath;
-
868 if (isAbsolutePath(dirName)) {
evaluated: isAbsolutePath(dirName)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:43
3-43
869 newPath = cleanPath(dirName);
executed (the execution status of this line is deduced): newPath = cleanPath(dirName);
-
870 } else {
executed: }
Execution Count:3
3
871 if (isRoot())
evaluated: isRoot()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:39
4-39
872 newPath = d->dirEntry.filePath();
executed: newPath = d->dirEntry.filePath();
Execution Count:4
4
873 else -
874 newPath = d->dirEntry.filePath() % QLatin1Char('/');
executed: newPath = d->dirEntry.filePath() % QLatin1Char('/');
Execution Count:39
39
875 newPath += dirName;
executed (the execution status of this line is deduced): newPath += dirName;
-
876 if (dirName.indexOf(QLatin1Char('/')) >= 0
evaluated: dirName.indexOf(QLatin1Char('/')) >= 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:39
4-39
877 || dirName == QLatin1String("..")
evaluated: dirName == QLatin1String("..")
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:13
13-26
878 || d->dirEntry.filePath() == QLatin1String(".")) {
evaluated: d->dirEntry.filePath() == QLatin1String(".")
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:11
2-11
879 newPath = cleanPath(newPath);
executed (the execution status of this line is deduced): newPath = cleanPath(newPath);
-
880#if defined (Q_OS_UNIX) -
881 //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. -
882 if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/.."))
partially evaluated: newPath.startsWith(QLatin1String("/../"))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32
evaluated: newPath == QLatin1String("/..")
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:27
0-32
883#else -
884 /* -
885 cleanPath() already took care of replacing '\' with '/'. -
886 We can't use startsWith here because the letter of the drive is unknown. -
887 After cleanPath() if path is "[A-Z]:/.." or starts with "[A-Z]:/../" it means trying to cd above root. -
888 */ -
889 -
890 if (newPath.midRef(1, 4) == QLatin1String(":/..") && (newPath.length() == 5 || newPath.at(5) == QLatin1Char('/'))) -
891#endif -
892 return false;
executed: return false;
Execution Count:5
5
893 /* -
894 If newPath starts with .., we convert it to absolute to -
895 avoid infinite looping on -
896 -
897 QDir dir("."); -
898 while (dir.cdUp()) -
899 ; -
900 */ -
901 if (newPath.startsWith(QLatin1String(".."))) {
evaluated: newPath.startsWith(QLatin1String(".."))
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:25
2-25
902 newPath = QFileInfo(newPath).absoluteFilePath();
executed (the execution status of this line is deduced): newPath = QFileInfo(newPath).absoluteFilePath();
-
903 }
executed: }
Execution Count:2
2
904 }
executed: }
Execution Count:27
27
905 }
executed: }
Execution Count:38
38
906 -
907 QScopedPointer<QDirPrivate> dir(new QDirPrivate(*d_ptr.constData()));
executed (the execution status of this line is deduced): QScopedPointer<QDirPrivate> dir(new QDirPrivate(*d_ptr.constData()));
-
908 dir->setPath(newPath);
executed (the execution status of this line is deduced): dir->setPath(newPath);
-
909 if (!dir->exists())
evaluated: !dir->exists()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:38
3-38
910 return false;
executed: return false;
Execution Count:3
3
911 -
912 d_ptr = dir.take();
executed (the execution status of this line is deduced): d_ptr = dir.take();
-
913 return true;
executed: return true;
Execution Count:38
38
914} -
915 -
916/*! -
917 Changes directory by moving one directory up from the QDir's -
918 current directory. -
919 -
920 Returns true if the new directory exists and is readable; -
921 otherwise returns false. Note that the logical cdUp() operation is -
922 not performed if the new directory does not exist. -
923 -
924 \sa cd(), isReadable(), exists(), path() -
925*/ -
926bool QDir::cdUp() -
927{ -
928 return cd(QString::fromLatin1(".."));
executed: return cd(QString::fromLatin1(".."));
Execution Count:23
23
929} -
930 -
931/*! -
932 Returns the string list set by setNameFilters() -
933*/ -
934QStringList QDir::nameFilters() const -
935{ -
936 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
937 return d->nameFilters;
executed: return d->nameFilters;
Execution Count:13
13
938} -
939 -
940/*! -
941 Sets the name filters used by entryList() and entryInfoList() to the -
942 list of filters specified by \a nameFilters. -
943 -
944 Each name filter is a wildcard (globbing) filter that understands -
945 \c{*} and \c{?} wildcards. (See \l{QRegExp wildcard matching}.) -
946 -
947 For example, the following code sets three name filters on a QDir -
948 to ensure that only files with extensions typically used for C++ -
949 source files are listed: -
950 -
951 \snippet qdir-namefilters/main.cpp 0 -
952 -
953 \sa nameFilters(), setFilter() -
954*/ -
955void QDir::setNameFilters(const QStringList &nameFilters) -
956{ -
957 QDirPrivate* d = d_ptr.data();
executed (the execution status of this line is deduced): QDirPrivate* d = d_ptr.data();
-
958 d->initFileEngine();
executed (the execution status of this line is deduced): d->initFileEngine();
-
959 d->clearFileLists();
executed (the execution status of this line is deduced): d->clearFileLists();
-
960 -
961 d->nameFilters = nameFilters;
executed (the execution status of this line is deduced): d->nameFilters = nameFilters;
-
962}
executed: }
Execution Count:248
248
963 -
964/*! -
965 \obsolete -
966 -
967 Use QDir::addSearchPath() with a prefix instead. -
968 -
969 Adds \a path to the search paths searched in to find resources -
970 that are not specified with an absolute path. The default search -
971 path is to search only in the root (\c{:/}). -
972 -
973 \sa {The Qt Resource System} -
974*/ -
975void QDir::addResourceSearchPath(const QString &path) -
976{ -
977#ifdef QT_BUILD_CORE_LIB -
978 QResource::addSearchPath(path);
never executed (the execution status of this line is deduced): QResource::addSearchPath(path);
-
979#else -
980 Q_UNUSED(path) -
981#endif -
982}
never executed: }
0
983 -
984#ifdef QT_BUILD_CORE_LIB -
985/*! -
986 \since 4.3 -
987 -
988 Sets or replaces Qt's search paths for file names with the prefix \a prefix -
989 to \a searchPaths. -
990 -
991 To specify a prefix for a file name, prepend the prefix followed by a single -
992 colon (e.g., "images:undo.png", "xmldocs:books.xml"). \a prefix can only -
993 contain letters or numbers (e.g., it cannot contain a colon, nor a slash). -
994 -
995 Qt uses this search path to locate files with a known prefix. The search -
996 path entries are tested in order, starting with the first entry. -
997 -
998 \snippet code/src_corelib_io_qdir.cpp 8 -
999 -
1000 File name prefix must be at least 2 characters long to avoid conflicts with -
1001 Windows drive letters. -
1002 -
1003 Search paths may contain paths to \l{The Qt Resource System}. -
1004*/ -
1005void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths) -
1006{ -
1007 if (prefix.length() < 2) {
partially evaluated: prefix.length() < 2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:35
0-35
1008 qWarning("QDir::setSearchPaths: Prefix must be longer than 1 character");
never executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1008, __PRETTY_FUNCTION__).warning("QDir::setSearchPaths: Prefix must be longer than 1 character");
-
1009 return;
never executed: return;
0
1010 } -
1011 -
1012 for (int i = 0; i < prefix.count(); ++i) {
evaluated: i < prefix.count()
TRUEFALSE
yes
Evaluation Count:318
yes
Evaluation Count:35
35-318
1013 if (!prefix.at(i).isLetterOrNumber()) {
partially evaluated: !prefix.at(i).isLetterOrNumber()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:318
0-318
1014 qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
never executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1014, __PRETTY_FUNCTION__).warning("QDir::setSearchPaths: Prefix can only contain letters or numbers");
-
1015 return;
never executed: return;
0
1016 } -
1017 }
executed: }
Execution Count:318
318
1018 -
1019 QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
executed (the execution status of this line is deduced): QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
-
1020 QMap<QString, QStringList> &paths = QCoreGlobalData::instance()->dirSearchPaths;
executed (the execution status of this line is deduced): QMap<QString, QStringList> &paths = QCoreGlobalData::instance()->dirSearchPaths;
-
1021 if (searchPaths.isEmpty()) {
evaluated: searchPaths.isEmpty()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:13
13-22
1022 paths.remove(prefix);
executed (the execution status of this line is deduced): paths.remove(prefix);
-
1023 } else {
executed: }
Execution Count:22
22
1024 paths.insert(prefix, searchPaths);
executed (the execution status of this line is deduced): paths.insert(prefix, searchPaths);
-
1025 }
executed: }
Execution Count:13
13
1026} -
1027 -
1028/*! -
1029 \since 4.3 -
1030 -
1031 Adds \a path to the search path for \a prefix. -
1032 -
1033 \sa setSearchPaths() -
1034*/ -
1035void QDir::addSearchPath(const QString &prefix, const QString &path) -
1036{ -
1037 if (path.isEmpty())
partially evaluated: path.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
1038 return;
never executed: return;
0
1039 -
1040 QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
executed (the execution status of this line is deduced): QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
-
1041 QCoreGlobalData::instance()->dirSearchPaths[prefix] += path;
executed (the execution status of this line is deduced): QCoreGlobalData::instance()->dirSearchPaths[prefix] += path;
-
1042}
executed: }
Execution Count:13
13
1043 -
1044/*! -
1045 \since 4.3 -
1046 -
1047 Returns the search paths for \a prefix. -
1048 -
1049 \sa setSearchPaths(), addSearchPath() -
1050*/ -
1051QStringList QDir::searchPaths(const QString &prefix) -
1052{ -
1053 QReadLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
executed (the execution status of this line is deduced): QReadLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock);
-
1054 return QCoreGlobalData::instance()->dirSearchPaths.value(prefix);
executed: return QCoreGlobalData::instance()->dirSearchPaths.value(prefix);
Execution Count:116
116
1055} -
1056 -
1057#endif // QT_BUILD_CORE_LIB -
1058 -
1059/*! -
1060 Returns the value set by setFilter() -
1061*/ -
1062QDir::Filters QDir::filter() const -
1063{ -
1064 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1065 return d->filters;
executed: return d->filters;
Execution Count:16
16
1066} -
1067 -
1068/*! -
1069 \enum QDir::Filter -
1070 -
1071 This enum describes the filtering options available to QDir; e.g. -
1072 for entryList() and entryInfoList(). The filter value is specified -
1073 by combining values from the following list using the bitwise OR -
1074 operator: -
1075 -
1076 \value Dirs List directories that match the filters. -
1077 \value AllDirs List all directories; i.e. don't apply the filters -
1078 to directory names. -
1079 \value Files List files. -
1080 \value Drives List disk drives (ignored under Unix). -
1081 \value NoSymLinks Do not list symbolic links (ignored by operating -
1082 systems that don't support symbolic links). -
1083 \value NoDotAndDotDot Do not list the special entries "." and "..". -
1084 \value NoDot Do not list the special entry ".". -
1085 \value NoDotDot Do not list the special entry "..". -
1086 \value AllEntries List directories, files, drives and symlinks (this does not list -
1087 broken symlinks unless you specify System). -
1088 \value Readable List files for which the application has read -
1089 access. The Readable value needs to be combined -
1090 with Dirs or Files. -
1091 \value Writable List files for which the application has write -
1092 access. The Writable value needs to be combined -
1093 with Dirs or Files. -
1094 \value Executable List files for which the application has -
1095 execute access. The Executable value needs to be -
1096 combined with Dirs or Files. -
1097 \value Modified Only list files that have been modified (ignored -
1098 on Unix). -
1099 \value Hidden List hidden files (on Unix, files starting with a "."). -
1100 \value System List system files (on Unix, FIFOs, sockets and -
1101 device files are included; on Windows, \c {.lnk} -
1102 files are included) -
1103 \value CaseSensitive The filter should be case sensitive. -
1104 -
1105 \omitvalue TypeMask -
1106 \omitvalue AccessMask -
1107 \omitvalue PermissionMask -
1108 \omitvalue NoFilter -
1109 -
1110 Functions that use Filter enum values to filter lists of files -
1111 and directories will include symbolic links to files and directories -
1112 unless you set the NoSymLinks value. -
1113 -
1114 A default constructed QDir will not filter out files based on -
1115 their permissions, so entryList() and entryInfoList() will return -
1116 all files that are readable, writable, executable, or any -
1117 combination of the three. This makes the default easy to write, -
1118 and at the same time useful. -
1119 -
1120 For example, setting the \c Readable, \c Writable, and \c Files -
1121 flags allows all files to be listed for which the application has read -
1122 access, write access or both. If the \c Dirs and \c Drives flags are -
1123 also included in this combination then all drives, directories, all -
1124 files that the application can read, write, or execute, and symlinks -
1125 to such files/directories can be listed. -
1126 -
1127 To retrieve the permissons for a directory, use the -
1128 entryInfoList() function to get the associated QFileInfo objects -
1129 and then use the QFileInfo::permissons() to obtain the permissions -
1130 and ownership for each file. -
1131*/ -
1132 -
1133/*! -
1134 Sets the filter used by entryList() and entryInfoList() to \a -
1135 filters. The filter is used to specify the kind of files that -
1136 should be returned by entryList() and entryInfoList(). See -
1137 \l{QDir::Filter}. -
1138 -
1139 \sa filter(), setNameFilters() -
1140*/ -
1141void QDir::setFilter(Filters filters) -
1142{ -
1143 QDirPrivate* d = d_ptr.data();
executed (the execution status of this line is deduced): QDirPrivate* d = d_ptr.data();
-
1144 d->initFileEngine();
executed (the execution status of this line is deduced): d->initFileEngine();
-
1145 d->clearFileLists();
executed (the execution status of this line is deduced): d->clearFileLists();
-
1146 -
1147 d->filters = filters;
executed (the execution status of this line is deduced): d->filters = filters;
-
1148}
executed: }
Execution Count:245
245
1149 -
1150/*! -
1151 Returns the value set by setSorting() -
1152 -
1153 \sa setSorting(), SortFlag -
1154*/ -
1155QDir::SortFlags QDir::sorting() const -
1156{ -
1157 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1158 return d->sort;
executed: return d->sort;
Execution Count:16
16
1159} -
1160 -
1161/*! -
1162 \enum QDir::SortFlag -
1163 -
1164 This enum describes the sort options available to QDir, e.g. for -
1165 entryList() and entryInfoList(). The sort value is specified by -
1166 OR-ing together values from the following list: -
1167 -
1168 \value Name Sort by name. -
1169 \value Time Sort by time (modification time). -
1170 \value Size Sort by file size. -
1171 \value Type Sort by file type (extension). -
1172 \value Unsorted Do not sort. -
1173 \value NoSort Not sorted by default. -
1174 -
1175 \value DirsFirst Put the directories first, then the files. -
1176 \value DirsLast Put the files first, then the directories. -
1177 \value Reversed Reverse the sort order. -
1178 \value IgnoreCase Sort case-insensitively. -
1179 \value LocaleAware Sort items appropriately using the current locale settings. -
1180 -
1181 \omitvalue SortByMask -
1182 -
1183 You can only specify one of the first four. -
1184 -
1185 If you specify both DirsFirst and Reversed, directories are -
1186 still put first, but in reverse order; the files will be listed -
1187 after the directories, again in reverse order. -
1188*/ -
1189 -
1190/*! -
1191 Sets the sort order used by entryList() and entryInfoList(). -
1192 -
1193 The \a sort is specified by OR-ing values from the enum -
1194 \l{QDir::SortFlag}. -
1195 -
1196 \sa sorting(), SortFlag -
1197*/ -
1198void QDir::setSorting(SortFlags sort) -
1199{ -
1200 QDirPrivate* d = d_ptr.data();
executed (the execution status of this line is deduced): QDirPrivate* d = d_ptr.data();
-
1201 d->initFileEngine();
executed (the execution status of this line is deduced): d->initFileEngine();
-
1202 d->clearFileLists();
executed (the execution status of this line is deduced): d->clearFileLists();
-
1203 -
1204 d->sort = sort;
executed (the execution status of this line is deduced): d->sort = sort;
-
1205}
executed: }
Execution Count:5
5
1206 -
1207/*! -
1208 Returns the total number of directories and files in the directory. -
1209 -
1210 Equivalent to entryList().count(). -
1211 -
1212 \sa operator[](), entryList() -
1213*/ -
1214uint QDir::count() const -
1215{ -
1216 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1217 d->initFileLists(*this);
executed (the execution status of this line is deduced): d->initFileLists(*this);
-
1218 return d->files.count();
executed: return d->files.count();
Execution Count:10
10
1219} -
1220 -
1221/*! -
1222 Returns the file name at position \a pos in the list of file -
1223 names. Equivalent to entryList().at(index). -
1224 \a pos must be a valid index position in the list (i.e., 0 <= pos < count()). -
1225 -
1226 \sa count(), entryList() -
1227*/ -
1228QString QDir::operator[](int pos) const -
1229{ -
1230 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1231 d->initFileLists(*this);
executed (the execution status of this line is deduced): d->initFileLists(*this);
-
1232 return d->files[pos];
executed: return d->files[pos];
Execution Count:4
4
1233} -
1234 -
1235/*! -
1236 \overload -
1237 -
1238 Returns a list of the names of all the files and directories in -
1239 the directory, ordered according to the name and attribute filters -
1240 previously set with setNameFilters() and setFilter(), and sorted according -
1241 to the flags set with setSorting(). -
1242 -
1243 The attribute filter and sorting specifications can be overridden using the -
1244 \a filters and \a sort arguments. -
1245 -
1246 Returns an empty list if the directory is unreadable, does not -
1247 exist, or if nothing matches the specification. -
1248 -
1249 \note To list symlinks that point to non existing files, \l System must be -
1250 passed to the filter. -
1251 -
1252 \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() -
1253*/ -
1254QStringList QDir::entryList(Filters filters, SortFlags sort) const -
1255{ -
1256 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1257 return entryList(d->nameFilters, filters, sort);
executed: return entryList(d->nameFilters, filters, sort);
Execution Count:441
441
1258} -
1259 -
1260 -
1261/*! -
1262 \overload -
1263 -
1264 Returns a list of QFileInfo objects for all the files and directories in -
1265 the directory, ordered according to the name and attribute filters -
1266 previously set with setNameFilters() and setFilter(), and sorted according -
1267 to the flags set with setSorting(). -
1268 -
1269 The attribute filter and sorting specifications can be overridden using the -
1270 \a filters and \a sort arguments. -
1271 -
1272 Returns an empty list if the directory is unreadable, does not -
1273 exist, or if nothing matches the specification. -
1274 -
1275 \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() -
1276*/ -
1277QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const -
1278{ -
1279 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1280 return entryInfoList(d->nameFilters, filters, sort);
executed: return entryInfoList(d->nameFilters, filters, sort);
Execution Count:163
163
1281} -
1282 -
1283/*! -
1284 Returns a list of the names of all the files and -
1285 directories in the directory, ordered according to the name -
1286 and attribute filters previously set with setNameFilters() -
1287 and setFilter(), and sorted according to the flags set with -
1288 setSorting(). -
1289 -
1290 The name filter, file attribute filter, and sorting specification -
1291 can be overridden using the \a nameFilters, \a filters, and \a sort -
1292 arguments. -
1293 -
1294 Returns an empty list if the directory is unreadable, does not -
1295 exist, or if nothing matches the specification. -
1296 -
1297 \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() -
1298*/ -
1299QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, -
1300 SortFlags sort) const -
1301{ -
1302 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1303 -
1304 if (filters == NoFilter)
evaluated: filters == NoFilter
TRUEFALSE
yes
Evaluation Count:64
yes
Evaluation Count:430
64-430
1305 filters = d->filters;
executed: filters = d->filters;
Execution Count:64
64
1306 if (sort == NoSort)
evaluated: sort == NoSort
TRUEFALSE
yes
Evaluation Count:456
yes
Evaluation Count:38
38-456
1307 sort = d->sort;
executed: sort = d->sort;
Execution Count:456
456
1308 -
1309 if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
evaluated: filters == d->filters
TRUEFALSE
yes
Evaluation Count:90
yes
Evaluation Count:404
evaluated: sort == d->sort
TRUEFALSE
yes
Evaluation Count:78
yes
Evaluation Count:12
evaluated: nameFilters == d->nameFilters
TRUEFALSE
yes
Evaluation Count:72
yes
Evaluation Count:6
6-404
1310 d->initFileLists(*this);
executed (the execution status of this line is deduced): d->initFileLists(*this);
-
1311 return d->files;
executed: return d->files;
Execution Count:72
72
1312 } -
1313 -
1314 QFileInfoList l;
executed (the execution status of this line is deduced): QFileInfoList l;
-
1315 QDirIterator it(d->dirEntry.filePath(), nameFilters, filters);
executed (the execution status of this line is deduced): QDirIterator it(d->dirEntry.filePath(), nameFilters, filters);
-
1316 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:3170
yes
Evaluation Count:422
422-3170
1317 it.next();
executed (the execution status of this line is deduced): it.next();
-
1318 l.append(it.fileInfo());
executed (the execution status of this line is deduced): l.append(it.fileInfo());
-
1319 }
executed: }
Execution Count:3170
3170
1320 QStringList ret;
executed (the execution status of this line is deduced): QStringList ret;
-
1321 d->sortFileList(sort, l, &ret, 0);
executed (the execution status of this line is deduced): d->sortFileList(sort, l, &ret, 0);
-
1322 return ret;
executed: return ret;
Execution Count:422
422
1323} -
1324 -
1325/*! -
1326 Returns a list of QFileInfo objects for all the files and -
1327 directories in the directory, ordered according to the name -
1328 and attribute filters previously set with setNameFilters() -
1329 and setFilter(), and sorted according to the flags set with -
1330 setSorting(). -
1331 -
1332 The name filter, file attribute filter, and sorting specification -
1333 can be overridden using the \a nameFilters, \a filters, and \a sort -
1334 arguments. -
1335 -
1336 Returns an empty list if the directory is unreadable, does not -
1337 exist, or if nothing matches the specification. -
1338 -
1339 \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() -
1340*/ -
1341QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters, -
1342 SortFlags sort) const -
1343{ -
1344 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1345 -
1346 if (filters == NoFilter)
evaluated: filters == NoFilter
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:721
13-721
1347 filters = d->filters;
executed: filters = d->filters;
Execution Count:13
13
1348 if (sort == NoSort)
evaluated: sort == NoSort
TRUEFALSE
yes
Evaluation Count:170
yes
Evaluation Count:564
170-564
1349 sort = d->sort;
executed: sort = d->sort;
Execution Count:170
170
1350 -
1351 if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
evaluated: filters == d->filters
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:721
partially evaluated: sort == d->sort
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
evaluated: nameFilters == d->nameFilters
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:4
0-721
1352 d->initFileLists(*this);
executed (the execution status of this line is deduced): d->initFileLists(*this);
-
1353 return d->fileInfos;
executed: return d->fileInfos;
Execution Count:9
9
1354 } -
1355 -
1356 QFileInfoList l;
executed (the execution status of this line is deduced): QFileInfoList l;
-
1357 QDirIterator it(d->dirEntry.filePath(), nameFilters, filters);
executed (the execution status of this line is deduced): QDirIterator it(d->dirEntry.filePath(), nameFilters, filters);
-
1358 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:11781
yes
Evaluation Count:725
725-11781
1359 it.next();
executed (the execution status of this line is deduced): it.next();
-
1360 l.append(it.fileInfo());
executed (the execution status of this line is deduced): l.append(it.fileInfo());
-
1361 }
executed: }
Execution Count:11781
11781
1362 QFileInfoList ret;
executed (the execution status of this line is deduced): QFileInfoList ret;
-
1363 d->sortFileList(sort, l, 0, &ret);
executed (the execution status of this line is deduced): d->sortFileList(sort, l, 0, &ret);
-
1364 return ret;
executed: return ret;
Execution Count:725
725
1365} -
1366 -
1367/*! -
1368 Creates a sub-directory called \a dirName. -
1369 -
1370 Returns true on success; otherwise returns false. -
1371 -
1372 If the directory already exists when this function is called, it will return false. -
1373 -
1374 \sa rmdir() -
1375*/ -
1376bool QDir::mkdir(const QString &dirName) const -
1377{ -
1378 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1379 -
1380 if (dirName.isEmpty()) {
partially evaluated: dirName.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1332
0-1332
1381 qWarning("QDir::mkdir: Empty or null file name(s)");
never executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1381, __PRETTY_FUNCTION__).warning("QDir::mkdir: Empty or null file name(s)");
-
1382 return false;
never executed: return false;
0
1383 } -
1384 -
1385 QString fn = filePath(dirName);
executed (the execution status of this line is deduced): QString fn = filePath(dirName);
-
1386 if (d->fileEngine.isNull())
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:1332
no
Evaluation Count:0
0-1332
1387 return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
executed: return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
Execution Count:1332
1332
1388 return d->fileEngine->mkdir(fn, false);
never executed: return d->fileEngine->mkdir(fn, false);
0
1389} -
1390 -
1391/*! -
1392 Removes the directory specified by \a dirName. -
1393 -
1394 The directory must be empty for rmdir() to succeed. -
1395 -
1396 Returns true if successful; otherwise returns false. -
1397 -
1398 \sa mkdir() -
1399*/ -
1400bool QDir::rmdir(const QString &dirName) const -
1401{ -
1402 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1403 -
1404 if (dirName.isEmpty()) {
evaluated: dirName.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2392
2-2392
1405 qWarning("QDir::rmdir: Empty or null file name(s)");
executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1405, __PRETTY_FUNCTION__).warning("QDir::rmdir: Empty or null file name(s)");
-
1406 return false;
executed: return false;
Execution Count:2
2
1407 } -
1408 -
1409 QString fn = filePath(dirName);
executed (the execution status of this line is deduced): QString fn = filePath(dirName);
-
1410 if (d->fileEngine.isNull())
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:2392
no
Evaluation Count:0
0-2392
1411 return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
executed: return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
Execution Count:2392
2392
1412 -
1413 return d->fileEngine->rmdir(fn, false);
never executed: return d->fileEngine->rmdir(fn, false);
0
1414} -
1415 -
1416/*! -
1417 Creates the directory path \a dirPath. -
1418 -
1419 The function will create all parent directories necessary to -
1420 create the directory. -
1421 -
1422 Returns true if successful; otherwise returns false. -
1423 -
1424 If the path already exists when this function is called, it will return true. -
1425 -
1426 \sa rmpath() -
1427*/ -
1428bool QDir::mkpath(const QString &dirPath) const -
1429{ -
1430 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1431 -
1432 if (dirPath.isEmpty()) {
partially evaluated: dirPath.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:216
0-216
1433 qWarning("QDir::mkpath: Empty or null file name(s)");
never executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1433, __PRETTY_FUNCTION__).warning("QDir::mkpath: Empty or null file name(s)");
-
1434 return false;
never executed: return false;
0
1435 } -
1436 -
1437 QString fn = filePath(dirPath);
executed (the execution status of this line is deduced): QString fn = filePath(dirPath);
-
1438 if (d->fileEngine.isNull())
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:216
no
Evaluation Count:0
0-216
1439 return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
executed: return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
Execution Count:216
216
1440 return d->fileEngine->mkdir(fn, true);
never executed: return d->fileEngine->mkdir(fn, true);
0
1441} -
1442 -
1443/*! -
1444 Removes the directory path \a dirPath. -
1445 -
1446 The function will remove all parent directories in \a dirPath, -
1447 provided that they are empty. This is the opposite of -
1448 mkpath(dirPath). -
1449 -
1450 Returns true if successful; otherwise returns false. -
1451 -
1452 \sa mkpath() -
1453*/ -
1454bool QDir::rmpath(const QString &dirPath) const -
1455{ -
1456 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1457 -
1458 if (dirPath.isEmpty()) {
partially evaluated: dirPath.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1459 qWarning("QDir::rmpath: Empty or null file name(s)");
never executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1459, __PRETTY_FUNCTION__).warning("QDir::rmpath: Empty or null file name(s)");
-
1460 return false;
never executed: return false;
0
1461 } -
1462 -
1463 QString fn = filePath(dirPath);
executed (the execution status of this line is deduced): QString fn = filePath(dirPath);
-
1464 if (d->fileEngine.isNull())
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
1465 return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
executed: return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
Execution Count:4
4
1466 return d->fileEngine->rmdir(fn, true);
never executed: return d->fileEngine->rmdir(fn, true);
0
1467} -
1468 -
1469/*! -
1470 \since 5.0 -
1471 Removes the directory, including all its contents. -
1472 -
1473 Returns true if successful, otherwise false. -
1474 -
1475 If a file or directory cannot be removed, removeRecursively() keeps going -
1476 and attempts to delete as many files and sub-directories as possible, -
1477 then returns false. -
1478 -
1479 If the directory was already removed, the method returns true -
1480 (expected result already reached). -
1481 -
1482 Note: this function is meant for removing a small application-internal -
1483 directory (such as a temporary directory), but not user-visible -
1484 directories. For user-visible operations, it is rather recommended -
1485 to report errors more precisely to the user, to offer solutions -
1486 in case of errors, to show progress during the deletion since it -
1487 could take several minutes, etc. -
1488*/ -
1489bool QDir::removeRecursively() -
1490{ -
1491 if (!d_ptr->exists())
evaluated: !d_ptr->exists()
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:2025
5-2025
1492 return true;
executed: return true;
Execution Count:5
5
1493 -
1494 bool success = true;
executed (the execution status of this line is deduced): bool success = true;
-
1495 const QString dirPath = path();
executed (the execution status of this line is deduced): const QString dirPath = path();
-
1496 // not empty -- we must empty it first -
1497 QDirIterator di(dirPath, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
executed (the execution status of this line is deduced): QDirIterator di(dirPath, QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
-
1498 while (di.hasNext()) {
evaluated: di.hasNext()
TRUEFALSE
yes
Evaluation Count:2571
yes
Evaluation Count:2025
2025-2571
1499 di.next();
executed (the execution status of this line is deduced): di.next();
-
1500 const QFileInfo& fi = di.fileInfo();
executed (the execution status of this line is deduced): const QFileInfo& fi = di.fileInfo();
-
1501 bool ok;
executed (the execution status of this line is deduced): bool ok;
-
1502 if (fi.isDir() && !fi.isSymLink())
evaluated: fi.isDir()
TRUEFALSE
yes
Evaluation Count:862
yes
Evaluation Count:1709
evaluated: !fi.isSymLink()
TRUEFALSE
yes
Evaluation Count:861
yes
Evaluation Count:1
1-1709
1503 ok = QDir(di.filePath()).removeRecursively(); // recursive
executed: ok = QDir(di.filePath()).removeRecursively();
Execution Count:861
861
1504 else -
1505 ok = QFile::remove(di.filePath());
executed: ok = QFile::remove(di.filePath());
Execution Count:1710
1710
1506 if (!ok)
partially evaluated: !ok
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2571
0-2571
1507 success = false;
never executed: success = false;
0
1508 }
executed: }
Execution Count:2571
2571
1509 -
1510 if (success)
partially evaluated: success
TRUEFALSE
yes
Evaluation Count:2025
no
Evaluation Count:0
0-2025
1511 success = rmdir(absolutePath());
executed: success = rmdir(absolutePath());
Execution Count:2025
2025
1512 -
1513 return success;
executed: return success;
Execution Count:2025
2025
1514} -
1515 -
1516/*! -
1517 Returns true if the directory is readable \e and we can open files -
1518 by name; otherwise returns false. -
1519 -
1520 \warning A false value from this function is not a guarantee that -
1521 files in the directory are not accessible. -
1522 -
1523 \sa QFileInfo::isReadable() -
1524*/ -
1525bool QDir::isReadable() const -
1526{ -
1527 const QDirPrivate* d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate* d = d_ptr.constData();
-
1528 -
1529 if (d->fileEngine.isNull()) {
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1530 if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
partially evaluated: !d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission)
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
1531 QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
executed: QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
Execution Count:2
2
1532 -
1533 return (d->metaData.permissions() & QFile::ReadUser) != 0;
executed: return (d->metaData.permissions() & QFile::ReadUser) != 0;
Execution Count:2
2
1534 } -
1535 -
1536 const QAbstractFileEngine::FileFlags info =
never executed (the execution status of this line is deduced): const QAbstractFileEngine::FileFlags info =
-
1537 d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
never executed (the execution status of this line is deduced): d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
-
1538 | QAbstractFileEngine::PermsMask);
never executed (the execution status of this line is deduced): | QAbstractFileEngine::PermsMask);
-
1539 if (!(info & QAbstractFileEngine::DirectoryType))
never evaluated: !(info & QAbstractFileEngine::DirectoryType)
0
1540 return false;
never executed: return false;
0
1541 return info & QAbstractFileEngine::ReadUserPerm;
never executed: return info & QAbstractFileEngine::ReadUserPerm;
0
1542} -
1543 -
1544/*! -
1545 \overload -
1546 -
1547 Returns true if the directory exists; otherwise returns false. -
1548 (If a file with the same name is found this function will return false). -
1549 -
1550 The overload of this function that accepts an argument is used to test -
1551 for the presence of files and directories within a directory. -
1552 -
1553 \sa QFileInfo::exists(), QFile::exists() -
1554*/ -
1555bool QDir::exists() const -
1556{ -
1557 return d_ptr->exists();
executed: return d_ptr->exists();
Execution Count:896
896
1558} -
1559 -
1560/*! -
1561 Returns true if the directory is the root directory; otherwise -
1562 returns false. -
1563 -
1564 Note: If the directory is a symbolic link to the root directory -
1565 this function returns false. If you want to test for this use -
1566 canonicalPath(), e.g. -
1567 -
1568 \snippet code/src_corelib_io_qdir.cpp 9 -
1569 -
1570 \sa root(), rootPath() -
1571*/ -
1572bool QDir::isRoot() const -
1573{ -
1574 if (d_ptr->fileEngine.isNull())
evaluated: d_ptr->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:47
yes
Evaluation Count:2
2-47
1575 return d_ptr->dirEntry.isRoot();
executed: return d_ptr->dirEntry.isRoot();
Execution Count:47
47
1576 return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
executed: return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
Execution Count:2
2
1577} -
1578 -
1579/*! -
1580 \fn bool QDir::isAbsolute() const -
1581 -
1582 Returns true if the directory's path is absolute; otherwise -
1583 returns false. See isAbsolutePath(). -
1584 -
1585 \sa isRelative(), makeAbsolute(), cleanPath() -
1586*/ -
1587 -
1588/*! -
1589 \fn bool QDir::isAbsolutePath(const QString &) -
1590 -
1591 Returns true if \a path is absolute; returns false if it is -
1592 relative. -
1593 -
1594 \sa isAbsolute(), isRelativePath(), makeAbsolute(), cleanPath() -
1595*/ -
1596 -
1597/*! -
1598 Returns true if the directory path is relative; otherwise returns -
1599 false. (Under Unix a path is relative if it does not start with a -
1600 "/"). -
1601 -
1602 \sa makeAbsolute(), isAbsolute(), isAbsolutePath(), cleanPath() -
1603*/ -
1604bool QDir::isRelative() const -
1605{ -
1606 if (d_ptr->fileEngine.isNull())
evaluated: d_ptr->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:1
1-15
1607 return d_ptr->dirEntry.isRelative();
executed: return d_ptr->dirEntry.isRelative();
Execution Count:15
15
1608 return d_ptr->fileEngine->isRelativePath();
executed: return d_ptr->fileEngine->isRelativePath();
Execution Count:1
1
1609} -
1610 -
1611 -
1612/*! -
1613 Converts the directory path to an absolute path. If it is already -
1614 absolute nothing happens. Returns true if the conversion -
1615 succeeded; otherwise returns false. -
1616 -
1617 \sa isAbsolute(), isAbsolutePath(), isRelative(), cleanPath() -
1618*/ -
1619bool QDir::makeAbsolute() -
1620{ -
1621 const QDirPrivate *d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate *d = d_ptr.constData();
-
1622 QScopedPointer<QDirPrivate> dir;
executed (the execution status of this line is deduced): QScopedPointer<QDirPrivate> dir;
-
1623 if (!d->fileEngine.isNull()) {
partially evaluated: !d->fileEngine.isNull()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1624 QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
never executed (the execution status of this line is deduced): QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
-
1625 if (QDir::isRelativePath(absolutePath))
never evaluated: QDir::isRelativePath(absolutePath)
0
1626 return false;
never executed: return false;
0
1627 -
1628 dir.reset(new QDirPrivate(*d_ptr.constData()));
never executed (the execution status of this line is deduced): dir.reset(new QDirPrivate(*d_ptr.constData()));
-
1629 dir->setPath(absolutePath);
never executed (the execution status of this line is deduced): dir->setPath(absolutePath);
-
1630 } else { // native FS
never executed: }
0
1631 d->resolveAbsoluteEntry();
executed (the execution status of this line is deduced): d->resolveAbsoluteEntry();
-
1632 dir.reset(new QDirPrivate(*d_ptr.constData()));
executed (the execution status of this line is deduced): dir.reset(new QDirPrivate(*d_ptr.constData()));
-
1633 dir->setPath(d->absoluteDirEntry.filePath());
executed (the execution status of this line is deduced): dir->setPath(d->absoluteDirEntry.filePath());
-
1634 }
executed: }
Execution Count:1
1
1635 d_ptr = dir.take(); // actually detach
executed (the execution status of this line is deduced): d_ptr = dir.take();
-
1636 return true;
executed: return true;
Execution Count:1
1
1637} -
1638 -
1639/*! -
1640 Returns true if directory \a dir and this directory have the same -
1641 path and their sort and filter settings are the same; otherwise -
1642 returns false. -
1643 -
1644 Example: -
1645 -
1646 \snippet code/src_corelib_io_qdir.cpp 10 -
1647*/ -
1648bool QDir::operator==(const QDir &dir) const -
1649{ -
1650 const QDirPrivate *d = d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate *d = d_ptr.constData();
-
1651 const QDirPrivate *other = dir.d_ptr.constData();
executed (the execution status of this line is deduced): const QDirPrivate *other = dir.d_ptr.constData();
-
1652 -
1653 if (d == other)
partially evaluated: d == other
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:60
0-60
1654 return true;
never executed: return true;
0
1655 Qt::CaseSensitivity sensitive;
executed (the execution status of this line is deduced): Qt::CaseSensitivity sensitive;
-
1656 if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
partially evaluated: d->fileEngine.isNull()
TRUEFALSE
yes
Evaluation Count:60
no
Evaluation Count:0
never evaluated: other->fileEngine.isNull()
0-60
1657 if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
partially evaluated: d->fileEngine.data() != other->fileEngine.data()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:60
0-60
1658 return false;
never executed: return false;
0
1659 -
1660 sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
partially evaluated: QFileSystemEngine::isCaseSensitive()
TRUEFALSE
yes
Evaluation Count:60
no
Evaluation Count:0
0-60
1661 } else {
executed: }
Execution Count:60
60
1662 if (d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive())
never evaluated: d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive()
0
1663 return false;
never executed: return false;
0
1664 sensitive = d->fileEngine->caseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
never evaluated: d->fileEngine->caseSensitive()
0
1665 }
never executed: }
0
1666 -
1667 if (d->filters == other->filters
evaluated: d->filters == other->filters
TRUEFALSE
yes
Evaluation Count:56
yes
Evaluation Count:4
4-56
1668 && d->sort == other->sort
evaluated: d->sort == other->sort
TRUEFALSE
yes
Evaluation Count:52
yes
Evaluation Count:4
4-52
1669 && d->nameFilters == other->nameFilters) {
evaluated: d->nameFilters == other->nameFilters
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:4
4-48
1670 -
1671 // Assume directories are the same if path is the same -
1672 if (d->dirEntry.filePath() == other->dirEntry.filePath())
evaluated: d->dirEntry.filePath() == other->dirEntry.filePath()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:26
22-26
1673 return true;
executed: return true;
Execution Count:22
22
1674 -
1675 if (exists()) {
evaluated: exists()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:4
4-22
1676 if (!dir.exists())
partially evaluated: !dir.exists()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:22
0-22
1677 return false; //can't be equal if only one exists
never executed: return false;
0
1678 // Both exist, fallback to expensive canonical path computation -
1679 return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
executed: return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
Execution Count:22
22
1680 } else { -
1681 if (dir.exists())
partially evaluated: dir.exists()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1682 return false; //can't be equal if only one exists
never executed: return false;
0
1683 // Neither exists, compare absolute paths rather than canonical (which would be empty strings) -
1684 d->resolveAbsoluteEntry();
executed (the execution status of this line is deduced): d->resolveAbsoluteEntry();
-
1685 other->resolveAbsoluteEntry();
executed (the execution status of this line is deduced): other->resolveAbsoluteEntry();
-
1686 return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
executed: return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
Execution Count:4
4
1687 } -
1688 } -
1689 return false;
executed: return false;
Execution Count:12
12
1690} -
1691 -
1692/*! -
1693 Makes a copy of the \a dir object and assigns it to this QDir -
1694 object. -
1695*/ -
1696QDir &QDir::operator=(const QDir &dir) -
1697{ -
1698 d_ptr = dir.d_ptr;
executed (the execution status of this line is deduced): d_ptr = dir.d_ptr;
-
1699 return *this;
executed: return *this;
Execution Count:303
303
1700} -
1701 -
1702/*! -
1703 \overload -
1704 \obsolete -
1705 -
1706 Sets the directory path to the given \a path. -
1707 -
1708 Use setPath() instead. -
1709*/ -
1710QDir &QDir::operator=(const QString &path) -
1711{ -
1712 d_ptr->setPath(path);
executed (the execution status of this line is deduced): d_ptr->setPath(path);
-
1713 return *this;
executed: return *this;
Execution Count:1
1
1714} -
1715 -
1716/*! -
1717 \fn void QDir::swap(QDir &other) -
1718 \since 5.0 -
1719 -
1720 Swaps this QDir instance with \a other. This function is very fast -
1721 and never fails. -
1722*/ -
1723 -
1724/*! -
1725 \fn bool QDir::operator!=(const QDir &dir) const -
1726 -
1727 Returns true if directory \a dir and this directory have different -
1728 paths or different sort or filter settings; otherwise returns -
1729 false. -
1730 -
1731 Example: -
1732 -
1733 \snippet code/src_corelib_io_qdir.cpp 11 -
1734*/ -
1735 -
1736/*! -
1737 Removes the file, \a fileName. -
1738 -
1739 Returns true if the file is removed successfully; otherwise -
1740 returns false. -
1741*/ -
1742bool QDir::remove(const QString &fileName) -
1743{ -
1744 if (fileName.isEmpty()) {
evaluated: fileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:17
1-17
1745 qWarning("QDir::remove: Empty or null file name");
executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1745, __PRETTY_FUNCTION__).warning("QDir::remove: Empty or null file name");
-
1746 return false;
executed: return false;
Execution Count:1
1
1747 } -
1748 return QFile::remove(filePath(fileName));
executed: return QFile::remove(filePath(fileName));
Execution Count:17
17
1749} -
1750 -
1751/*! -
1752 Renames a file or directory from \a oldName to \a newName, and returns -
1753 true if successful; otherwise returns false. -
1754 -
1755 On most file systems, rename() fails only if \a oldName does not -
1756 exist, or if a file with the new name already exists. -
1757 However, there are also other reasons why rename() can -
1758 fail. For example, on at least one file system rename() fails if -
1759 \a newName points to an open file. -
1760 -
1761 If \a oldName is a file (not a directory) that can't be renamed -
1762 right away, Qt will try to copy \a oldName to \a newName and remove -
1763 \a oldName. -
1764 -
1765 \sa QFile::rename() -
1766*/ -
1767bool QDir::rename(const QString &oldName, const QString &newName) -
1768{ -
1769 if (oldName.isEmpty() || newName.isEmpty()) {
evaluated: oldName.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:7
evaluated: newName.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
1-7
1770 qWarning("QDir::rename: Empty or null file name(s)");
executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1770, __PRETTY_FUNCTION__).warning("QDir::rename: Empty or null file name(s)");
-
1771 return false;
executed: return false;
Execution Count:2
2
1772 } -
1773 -
1774 QFile file(filePath(oldName));
executed (the execution status of this line is deduced): QFile file(filePath(oldName));
-
1775 if (!file.exists())
evaluated: !file.exists()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:5
1-5
1776 return false;
executed: return false;
Execution Count:1
1
1777 return file.rename(filePath(newName));
executed: return file.rename(filePath(newName));
Execution Count:5
5
1778} -
1779 -
1780/*! -
1781 Returns true if the file called \a name exists; otherwise returns -
1782 false. -
1783 -
1784 Unless \a name contains an absolute file path, the file name is assumed -
1785 to be relative to the directory itself, so this function is typically used -
1786 to check for the presence of files within a directory. -
1787 -
1788 \sa QFileInfo::exists(), QFile::exists() -
1789*/ -
1790bool QDir::exists(const QString &name) const -
1791{ -
1792 if (name.isEmpty()) {
evaluated: name.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2262
1-2262
1793 qWarning("QDir::exists: Empty or null file name");
executed (the execution status of this line is deduced): QMessageLogger("io/qdir.cpp", 1793, __PRETTY_FUNCTION__).warning("QDir::exists: Empty or null file name");
-
1794 return false;
executed: return false;
Execution Count:1
1
1795 } -
1796 return QFile::exists(filePath(name));
executed: return QFile::exists(filePath(name));
Execution Count:2262
2262
1797} -
1798 -
1799/*! -
1800 Returns a list of the root directories on this system. -
1801 -
1802 On Windows this returns a list of QFileInfo objects containing "C:/", -
1803 "D:/", etc. On other operating systems, it returns a list containing -
1804 just one root directory (i.e. "/"). -
1805 -
1806 \sa root(), rootPath() -
1807*/ -
1808QFileInfoList QDir::drives() -
1809{ -
1810#ifdef QT_NO_FSFILEENGINE -
1811 return QFileInfoList(); -
1812#else -
1813 return QFSFileEngine::drives();
executed: return QFSFileEngine::drives();
Execution Count:147
147
1814#endif -
1815} -
1816 -
1817/*! -
1818 Returns the native directory separator: "/" under Unix (including -
1819 Mac OS X) and "\\" under Windows. -
1820 -
1821 You do not need to use this function to build file paths. If you -
1822 always use "/", Qt will translate your paths to conform to the -
1823 underlying operating system. If you want to display paths to the -
1824 user using their operating system's separator use -
1825 toNativeSeparators(). -
1826*/ -
1827QChar QDir::separator() -
1828{ -
1829#if defined(Q_OS_WIN) -
1830 return QLatin1Char('\\'); -
1831#else -
1832 return QLatin1Char('/');
executed: return QLatin1Char('/');
Execution Count:28089
28089
1833#endif -
1834} -
1835 -
1836/*! -
1837 Sets the application's current working directory to \a path. -
1838 Returns true if the directory was successfully changed; otherwise -
1839 returns false. -
1840 -
1841 \sa current(), currentPath(), home(), root(), temp() -
1842*/ -
1843bool QDir::setCurrent(const QString &path) -
1844{ -
1845 return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));
executed: return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));
Execution Count:312
312
1846} -
1847 -
1848/*! -
1849 \fn QDir QDir::current() -
1850 -
1851 Returns the application's current directory. -
1852 -
1853 The directory is constructed using the absolute path of the current directory, -
1854 ensuring that its path() will be the same as its absolutePath(). -
1855 -
1856 \sa currentPath(), setCurrent(), home(), root(), temp() -
1857*/ -
1858 -
1859/*! -
1860 Returns the absolute path of the application's current directory. -
1861 -
1862 \sa current(), setCurrent(), homePath(), rootPath(), tempPath() -
1863*/ -
1864QString QDir::currentPath() -
1865{ -
1866 return QFileSystemEngine::currentPath().filePath();
executed: return QFileSystemEngine::currentPath().filePath();
Execution Count:818
818
1867} -
1868 -
1869/*! -
1870 \fn QDir QDir::home() -
1871 -
1872 Returns the user's home directory. -
1873 -
1874 The directory is constructed using the absolute path of the home directory, -
1875 ensuring that its path() will be the same as its absolutePath(). -
1876 -
1877 See homePath() for details. -
1878 -
1879 \sa drives(), current(), root(), temp() -
1880*/ -
1881 -
1882/*! -
1883 Returns the absolute path of the user's home directory. -
1884 -
1885 Under Windows this function will return the directory of the -
1886 current user's profile. Typically, this is: -
1887 -
1888 \snippet code/src_corelib_io_qdir.cpp 12 -
1889 -
1890 Use the toNativeSeparators() function to convert the separators to -
1891 the ones that are appropriate for the underlying operating system. -
1892 -
1893 If the directory of the current user's profile does not exist or -
1894 cannot be retrieved, the following alternatives will be checked (in -
1895 the given order) until an existing and available path is found: -
1896 -
1897 \list 1 -
1898 \li The path specified by the \c USERPROFILE environment variable. -
1899 \li The path formed by concatenating the \c HOMEDRIVE and \c HOMEPATH -
1900 environment variables. -
1901 \li The path specified by the \c HOME environment variable. -
1902 \li The path returned by the rootPath() function (which uses the \c SystemDrive -
1903 environment variable) -
1904 \li The \c{C:/} directory. -
1905 \endlist -
1906 -
1907 Under non-Windows operating systems the \c HOME environment -
1908 variable is used if it exists, otherwise the path returned by the -
1909 rootPath(). -
1910 -
1911 \sa home(), currentPath(), rootPath(), tempPath() -
1912*/ -
1913QString QDir::homePath() -
1914{ -
1915 return QFileSystemEngine::homePath();
executed: return QFileSystemEngine::homePath();
Execution Count:794
794
1916} -
1917 -
1918/*! -
1919 \fn QDir QDir::temp() -
1920 -
1921 Returns the system's temporary directory. -
1922 -
1923 The directory is constructed using the absolute path of the temporary directory, -
1924 ensuring that its path() will be the same as its absolutePath(). -
1925 -
1926 See tempPath() for details. -
1927 -
1928 \sa drives(), current(), home(), root() -
1929*/ -
1930 -
1931/*! -
1932 Returns the absolute path of the system's temporary directory. -
1933 -
1934 On Unix/Linux systems this is the path in the \c TMPDIR environment -
1935 variable or \c{/tmp} if \c TMPDIR is not defined. On Windows this is -
1936 usually the path in the \c TEMP or \c TMP environment -
1937 variable. Whether a directory separator is added to the end or -
1938 not, depends on the operating system. -
1939 -
1940 \sa temp(), currentPath(), homePath(), rootPath() -
1941*/ -
1942QString QDir::tempPath() -
1943{ -
1944 return QFileSystemEngine::tempPath();
executed: return QFileSystemEngine::tempPath();
Execution Count:2929
2929
1945} -
1946 -
1947/*! -
1948 \fn QDir QDir::root() -
1949 -
1950 Returns the root directory. -
1951 -
1952 The directory is constructed using the absolute path of the root directory, -
1953 ensuring that its path() will be the same as its absolutePath(). -
1954 -
1955 See rootPath() for details. -
1956 -
1957 \sa drives(), current(), home(), temp() -
1958*/ -
1959 -
1960/*! -
1961 Returns the absolute path of the root directory. -
1962 -
1963 For Unix operating systems this returns "/". For Windows file -
1964 systems this normally returns "c:/". -
1965 -
1966 \sa root(), drives(), currentPath(), homePath(), tempPath() -
1967*/ -
1968QString QDir::rootPath() -
1969{ -
1970 return QFileSystemEngine::rootPath();
executed: return QFileSystemEngine::rootPath();
Execution Count:39
39
1971} -
1972 -
1973#ifndef QT_NO_REGEXP -
1974/*! -
1975 \overload -
1976 -
1977 Returns true if the \a fileName matches any of the wildcard (glob) -
1978 patterns in the list of \a filters; otherwise returns false. The -
1979 matching is case insensitive. -
1980 -
1981 \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() -
1982*/ -
1983bool QDir::match(const QStringList &filters, const QString &fileName) -
1984{ -
1985 for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
evaluated: sit != filters.constEnd()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:4
4-14
1986 QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard);
executed (the execution status of this line is deduced): QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard);
-
1987 if (rx.exactMatch(fileName))
evaluated: rx.exactMatch(fileName)
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:8
6-8
1988 return true;
executed: return true;
Execution Count:6
6
1989 }
executed: }
Execution Count:8
8
1990 return false;
executed: return false;
Execution Count:4
4
1991} -
1992 -
1993/*! -
1994 Returns true if the \a fileName matches the wildcard (glob) -
1995 pattern \a filter; otherwise returns false. The \a filter may -
1996 contain multiple patterns separated by spaces or semicolons. -
1997 The matching is case insensitive. -
1998 -
1999 \sa {QRegExp wildcard matching}, QRegExp::exactMatch(), entryList(), entryInfoList() -
2000*/ -
2001bool QDir::match(const QString &filter, const QString &fileName) -
2002{ -
2003 return match(nameFiltersFromString(filter), fileName);
executed: return match(nameFiltersFromString(filter), fileName);
Execution Count:5
5
2004} -
2005#endif // QT_NO_REGEXP -
2006 -
2007/*! -
2008 Returns \a path with directory separators normalized (converted to "/") and -
2009 redundant ones removed, and "."s and ".."s resolved (as far as possible). -
2010 -
2011 Symbolic links are kept. This function does not return the -
2012 canonical path, but rather the simplest version of the input. -
2013 For example, "./local" becomes "local", "local/../bin" becomes -
2014 "bin" and "/local/usr/../bin" becomes "/local/bin". -
2015 -
2016 \sa absolutePath(), canonicalPath() -
2017*/ -
2018QString QDir::cleanPath(const QString &path) -
2019{ -
2020 if (path.isEmpty())
evaluated: path.isEmpty()
TRUEFALSE
yes
Evaluation Count:299
yes
Evaluation Count:19911
299-19911
2021 return path;
executed: return path;
Execution Count:299
299
2022 QString name = path;
executed (the execution status of this line is deduced): QString name = path;
-
2023 QChar dir_separator = separator();
executed (the execution status of this line is deduced): QChar dir_separator = separator();
-
2024 if (dir_separator != QLatin1Char('/'))
partially evaluated: dir_separator != QLatin1Char('/')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:19911
0-19911
2025 name.replace(dir_separator, QLatin1Char('/'));
never executed: name.replace(dir_separator, QLatin1Char('/'));
0
2026 -
2027 int used = 0, levels = 0;
executed (the execution status of this line is deduced): int used = 0, levels = 0;
-
2028 const int len = name.length();
executed (the execution status of this line is deduced): const int len = name.length();
-
2029 QVarLengthArray<QChar> outVector(len);
executed (the execution status of this line is deduced): QVarLengthArray<QChar> outVector(len);
-
2030 QChar *out = outVector.data();
executed (the execution status of this line is deduced): QChar *out = outVector.data();
-
2031 -
2032 const QChar *p = name.unicode();
executed (the execution status of this line is deduced): const QChar *p = name.unicode();
-
2033 for (int i = 0, last = -1, iwrite = 0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:784287
yes
Evaluation Count:19542
19542-784287
2034 if (p[i] == QLatin1Char('/')) {
evaluated: p[i] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:90258
yes
Evaluation Count:694029
90258-694029
2035 while (i+1 < len && p[i+1] == QLatin1Char('/')) {
evaluated: i+1 < len
TRUEFALSE
yes
Evaluation Count:87125
yes
Evaluation Count:3186
evaluated: p[i+1] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:53
yes
Evaluation Count:87072
53-87125
2036#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths -
2037 if (!i) -
2038 break; -
2039#endif -
2040 i++;
executed (the execution status of this line is deduced): i++;
-
2041 }
executed: }
Execution Count:53
53
2042 bool eaten = false;
executed (the execution status of this line is deduced): bool eaten = false;
-
2043 if (i+1 < len && p[i+1] == QLatin1Char('.')) {
evaluated: i+1 < len
TRUEFALSE
yes
Evaluation Count:87072
yes
Evaluation Count:3186
evaluated: p[i+1] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:3416
yes
Evaluation Count:83656
3186-87072
2044 int dotcount = 1;
executed (the execution status of this line is deduced): int dotcount = 1;
-
2045 if (i+2 < len && p[i+2] == QLatin1Char('.'))
evaluated: i+2 < len
TRUEFALSE
yes
Evaluation Count:3245
yes
Evaluation Count:171
evaluated: p[i+2] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:3203
yes
Evaluation Count:42
42-3245
2046 dotcount++;
executed: dotcount++;
Execution Count:3203
3203
2047 if (i == len - dotcount - 1) {
evaluated: i == len - dotcount - 1
TRUEFALSE
yes
Evaluation Count:563
yes
Evaluation Count:2853
563-2853
2048 if (dotcount == 1) {
evaluated: dotcount == 1
TRUEFALSE
yes
Evaluation Count:171
yes
Evaluation Count:392
171-392
2049 break;
executed: break;
Execution Count:171
171
2050 } else if (levels) {
evaluated: levels
TRUEFALSE
yes
Evaluation Count:198
yes
Evaluation Count:194
194-198
2051 if (last == -1) {
evaluated: last == -1
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:189
9-189
2052 for (int i2 = iwrite-1; i2 >= 0; i2--) {
partially evaluated: i2 >= 0
TRUEFALSE
yes
Evaluation Count:62
no
Evaluation Count:0
0-62
2053 if (out[i2] == QLatin1Char('/')) {
evaluated: out[i2] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:53
9-53
2054 last = i2;
executed (the execution status of this line is deduced): last = i2;
-
2055 break;
executed: break;
Execution Count:9
9
2056 } -
2057 }
executed: }
Execution Count:53
53
2058 }
executed: }
Execution Count:9
9
2059 used -= iwrite - last - 1;
executed (the execution status of this line is deduced): used -= iwrite - last - 1;
-
2060 break;
executed: break;
Execution Count:198
198
2061 } -
2062 } else if (p[i+dotcount+1] == QLatin1Char('/')) {
evaluated: p[i+dotcount+1] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:2799
yes
Evaluation Count:54
54-2799
2063 if (dotcount == 2 && levels) {
evaluated: dotcount == 2
TRUEFALSE
yes
Evaluation Count:2785
yes
Evaluation Count:14
evaluated: levels
TRUEFALSE
yes
Evaluation Count:339
yes
Evaluation Count:2446
14-2785
2064 if (last == -1 || iwrite - last == 1) {
evaluated: last == -1
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:195
partially evaluated: iwrite - last == 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:195
0-195
2065 for (int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) {
partially evaluated: i2 >= 0
TRUEFALSE
yes
Evaluation Count:996
no
Evaluation Count:0
0-996
2066 if (out[i2] == QLatin1Char('/')) {
evaluated: out[i2] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:144
yes
Evaluation Count:852
144-852
2067 eaten = true;
executed (the execution status of this line is deduced): eaten = true;
-
2068 last = i2;
executed (the execution status of this line is deduced): last = i2;
-
2069 break;
executed: break;
Execution Count:144
144
2070 } -
2071 }
executed: }
Execution Count:852
852
2072 } else {
executed: }
Execution Count:144
144
2073 eaten = true;
executed (the execution status of this line is deduced): eaten = true;
-
2074 }
executed: }
Execution Count:195
195
2075 if (eaten) {
partially evaluated: eaten
TRUEFALSE
yes
Evaluation Count:339
no
Evaluation Count:0
0-339
2076 levels--;
executed (the execution status of this line is deduced): levels--;
-
2077 used -= iwrite - last;
executed (the execution status of this line is deduced): used -= iwrite - last;
-
2078 iwrite = last;
executed (the execution status of this line is deduced): iwrite = last;
-
2079 last = -1;
executed (the execution status of this line is deduced): last = -1;
-
2080 }
executed: }
Execution Count:339
339
2081 } else if (dotcount == 2 && i > 0 && p[i - 1] != QLatin1Char('.')) {
executed: }
Execution Count:339
evaluated: dotcount == 2
TRUEFALSE
yes
Evaluation Count:2446
yes
Evaluation Count:14
evaluated: i > 0
TRUEFALSE
yes
Evaluation Count:2358
yes
Evaluation Count:88
partially evaluated: p[i - 1] != QLatin1Char('.')
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2358
0-2446
2082 eaten = true;
never executed (the execution status of this line is deduced): eaten = true;
-
2083 used -= iwrite - qMax(0, last);
never executed (the execution status of this line is deduced): used -= iwrite - qMax(0, last);
-
2084 iwrite = qMax(0, last);
never executed (the execution status of this line is deduced): iwrite = qMax(0, last);
-
2085 last = -1;
never executed (the execution status of this line is deduced): last = -1;
-
2086 ++i;
never executed (the execution status of this line is deduced): ++i;
-
2087 } else if (dotcount == 1) {
never executed: }
evaluated: dotcount == 1
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:2446
0-2446
2088 eaten = true;
executed (the execution status of this line is deduced): eaten = true;
-
2089 }
executed: }
Execution Count:14
14
2090 if (eaten)
evaluated: eaten
TRUEFALSE
yes
Evaluation Count:353
yes
Evaluation Count:2446
353-2446
2091 i += dotcount;
executed: i += dotcount;
Execution Count:353
353
2092 } else {
executed: }
Execution Count:2799
2799
2093 levels++;
executed (the execution status of this line is deduced): levels++;
-
2094 }
executed: }
Execution Count:54
54
2095 } else if (last != -1 && iwrite - last == 1) {
evaluated: last != -1
TRUEFALSE
yes
Evaluation Count:66992
yes
Evaluation Count:19850
partially evaluated: iwrite - last == 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:66992
0-66992
2096#if defined(Q_OS_WIN) -
2097 eaten = (iwrite > 2); -
2098#else -
2099 eaten = true;
never executed (the execution status of this line is deduced): eaten = true;
-
2100#endif -
2101 last = -1;
never executed (the execution status of this line is deduced): last = -1;
-
2102 } else if (last != -1 && i == len-1) {
never executed: }
evaluated: last != -1
TRUEFALSE
yes
Evaluation Count:66992
yes
Evaluation Count:19850
evaluated: i == len-1
TRUEFALSE
yes
Evaluation Count:3055
yes
Evaluation Count:63937
0-66992
2103 eaten = true;
executed (the execution status of this line is deduced): eaten = true;
-
2104 } else {
executed: }
Execution Count:3055
3055
2105 levels++;
executed (the execution status of this line is deduced): levels++;
-
2106 }
executed: }
Execution Count:83787
83787
2107 if (!eaten)
evaluated: !eaten
TRUEFALSE
yes
Evaluation Count:86481
yes
Evaluation Count:3408
3408-86481
2108 last = i - (i - iwrite);
executed: last = i - (i - iwrite);
Execution Count:86481
86481
2109 else -
2110 continue;
executed: continue;
Execution Count:3408
3408
2111 } else if (!i && p[i] == QLatin1Char('.')) {
evaluated: !i
TRUEFALSE
yes
Evaluation Count:68
yes
Evaluation Count:693961
evaluated: p[i] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:48
20-693961
2112 int dotcount = 1;
executed (the execution status of this line is deduced): int dotcount = 1;
-
2113 if (len >= 1 && p[1] == QLatin1Char('.'))
partially evaluated: len >= 1
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
evaluated: p[1] == QLatin1Char('.')
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:11
0-20
2114 dotcount++;
executed: dotcount++;
Execution Count:9
9
2115 if (len >= dotcount && p[dotcount] == QLatin1Char('/')) {
partially evaluated: len >= dotcount
TRUEFALSE
yes
Evaluation Count:20
no
Evaluation Count:0
evaluated: p[dotcount] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:10
0-20
2116 if (dotcount == 1) {
evaluated: dotcount == 1
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:4
4-6
2117 i++;
executed (the execution status of this line is deduced): i++;
-
2118 while (i+1 < len-1 && p[i+1] == QLatin1Char('/'))
partially evaluated: i+1 < len-1
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
evaluated: p[i+1] == QLatin1Char('/')
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:6
0-7
2119 i++;
executed: i++;
Execution Count:1
1
2120 continue;
executed: continue;
Execution Count:6
6
2121 } -
2122 }
executed: }
Execution Count:4
4
2123 }
executed: }
Execution Count:14
14
2124 out[iwrite++] = p[i];
executed (the execution status of this line is deduced): out[iwrite++] = p[i];
-
2125 used++;
executed (the execution status of this line is deduced): used++;
-
2126 }
executed: }
Execution Count:780504
780504
2127 -
2128 QString ret = (used == len ? name : QString(out, used));
evaluated: used == len
TRUEFALSE
yes
Evaluation Count:16243
yes
Evaluation Count:3668
3668-16243
2129 // Strip away last slash except for root directories -
2130 if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
evaluated: ret.length() > 1
TRUEFALSE
yes
Evaluation Count:19743
yes
Evaluation Count:168
evaluated: ret.endsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:174
yes
Evaluation Count:19569
168-19743
2131#if defined (Q_OS_WIN) -
2132 if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':'))) -
2133#endif -
2134 ret.chop(1);
executed (the execution status of this line is deduced): ret.chop(1);
-
2135 }
executed: }
Execution Count:174
174
2136 -
2137 return ret;
executed: return ret;
Execution Count:19911
19911
2138} -
2139 -
2140/*! -
2141 Returns true if \a path is relative; returns false if it is -
2142 absolute. -
2143 -
2144 \sa isRelative(), isAbsolutePath(), makeAbsolute() -
2145*/ -
2146bool QDir::isRelativePath(const QString &path) -
2147{ -
2148 return QFileInfo(path).isRelative();
executed: return QFileInfo(path).isRelative();
Execution Count:7780
7780
2149} -
2150 -
2151/*! -
2152 Refreshes the directory information. -
2153*/ -
2154void QDir::refresh() const -
2155{ -
2156 QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data();
executed (the execution status of this line is deduced): QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data();
-
2157 d->metaData.clear();
executed (the execution status of this line is deduced): d->metaData.clear();
-
2158 d->initFileEngine();
executed (the execution status of this line is deduced): d->initFileEngine();
-
2159 d->clearFileLists();
executed (the execution status of this line is deduced): d->clearFileLists();
-
2160}
executed: }
Execution Count:2
2
2161 -
2162/*! -
2163 \internal -
2164*/ -
2165QDirPrivate* QDir::d_func() -
2166{ -
2167 return d_ptr.data();
never executed: return d_ptr.data();
0
2168} -
2169 -
2170/*! -
2171 \internal -
2172 -
2173 Returns a list of name filters from the given \a nameFilter. (If -
2174 there is more than one filter, each pair of filters is separated -
2175 by a space or by a semicolon.) -
2176*/ -
2177QStringList QDir::nameFiltersFromString(const QString &nameFilter) -
2178{ -
2179 return QDirPrivate::splitFilters(nameFilter);
executed: return QDirPrivate::splitFilters(nameFilter);
Execution Count:32
32
2180} -
2181 -
2182/*! -
2183 \macro void Q_INIT_RESOURCE(name) -
2184 \relates QDir -
2185 -
2186 Initializes the resources specified by the \c .qrc file with the -
2187 specified base \a name. Normally, Qt resources are loaded -
2188 automatically at startup. The Q_INIT_RESOURCE() macro is -
2189 necessary on some platforms for resources stored in a static -
2190 library. -
2191 -
2192 For example, if your application's resources are listed in a file -
2193 called \c myapp.qrc, you can ensure that the resources are -
2194 initialized at startup by adding this line to your \c main() -
2195 function: -
2196 -
2197 \snippet code/src_corelib_io_qdir.cpp 13 -
2198 -
2199 If the file name contains characters that cannot be part of a valid C++ function name -
2200 (such as '-'), they have to be replaced by the underscore character ('_'). -
2201 -
2202 Note: This macro cannot be used in a namespace. It should be called from -
2203 main(). If that is not possible, the following workaround can be used -
2204 to init the resource \c myapp from the function \c{MyNamespace::myFunction}: -
2205 -
2206 \snippet code/src_corelib_io_qdir.cpp 14 -
2207 -
2208 \sa Q_CLEANUP_RESOURCE(), {The Qt Resource System} -
2209*/ -
2210 -
2211/*! -
2212 \since 4.1 -
2213 \macro void Q_CLEANUP_RESOURCE(name) -
2214 \relates QDir -
2215 -
2216 Unloads the resources specified by the \c .qrc file with the base -
2217 name \a name. -
2218 -
2219 Normally, Qt resources are unloaded automatically when the -
2220 application terminates, but if the resources are located in a -
2221 plugin that is being unloaded, call Q_CLEANUP_RESOURCE() to force -
2222 removal of your resources. -
2223 -
2224 Note: This macro cannot be used in a namespace. Please see the -
2225 Q_INIT_RESOURCE documentation for a workaround. -
2226 -
2227 Example: -
2228 -
2229 \snippet code/src_corelib_io_qdir.cpp 15 -
2230 -
2231 \sa Q_INIT_RESOURCE(), {The Qt Resource System} -
2232*/ -
2233 -
2234 -
2235#ifndef QT_NO_DEBUG_STREAM -
2236QDebug operator<<(QDebug debug, QDir::Filters filters) -
2237{ -
2238 QStringList flags;
never executed (the execution status of this line is deduced): QStringList flags;
-
2239 if (filters == QDir::NoFilter) {
never evaluated: filters == QDir::NoFilter
0
2240 flags << QLatin1String("NoFilter");
never executed (the execution status of this line is deduced): flags << QLatin1String("NoFilter");
-
2241 } else {
never executed: }
0
2242 if (filters & QDir::Dirs) flags << QLatin1String("Dirs");
never executed: flags << QLatin1String("Dirs");
never evaluated: filters & QDir::Dirs
0
2243 if (filters & QDir::AllDirs) flags << QLatin1String("AllDirs");
never executed: flags << QLatin1String("AllDirs");
never evaluated: filters & QDir::AllDirs
0
2244 if (filters & QDir::Files) flags << QLatin1String("Files");
never executed: flags << QLatin1String("Files");
never evaluated: filters & QDir::Files
0
2245 if (filters & QDir::Drives) flags << QLatin1String("Drives");
never executed: flags << QLatin1String("Drives");
never evaluated: filters & QDir::Drives
0
2246 if (filters & QDir::NoSymLinks) flags << QLatin1String("NoSymLinks");
never executed: flags << QLatin1String("NoSymLinks");
never evaluated: filters & QDir::NoSymLinks
0
2247 if (filters & QDir::NoDot) flags << QLatin1String("NoDot");
never executed: flags << QLatin1String("NoDot");
never evaluated: filters & QDir::NoDot
0
2248 if (filters & QDir::NoDotDot) flags << QLatin1String("NoDotDot");
never executed: flags << QLatin1String("NoDotDot");
never evaluated: filters & QDir::NoDotDot
0
2249 if ((filters & QDir::AllEntries) == QDir::AllEntries) flags << QLatin1String("AllEntries");
never executed: flags << QLatin1String("AllEntries");
never evaluated: (filters & QDir::AllEntries) == QDir::AllEntries
0
2250 if (filters & QDir::Readable) flags << QLatin1String("Readable");
never executed: flags << QLatin1String("Readable");
never evaluated: filters & QDir::Readable
0
2251 if (filters & QDir::Writable) flags << QLatin1String("Writable");
never executed: flags << QLatin1String("Writable");
never evaluated: filters & QDir::Writable
0
2252 if (filters & QDir::Executable) flags << QLatin1String("Executable");
never executed: flags << QLatin1String("Executable");
never evaluated: filters & QDir::Executable
0
2253 if (filters & QDir::Modified) flags << QLatin1String("Modified");
never executed: flags << QLatin1String("Modified");
never evaluated: filters & QDir::Modified
0
2254 if (filters & QDir::Hidden) flags << QLatin1String("Hidden");
never executed: flags << QLatin1String("Hidden");
never evaluated: filters & QDir::Hidden
0
2255 if (filters & QDir::System) flags << QLatin1String("System");
never executed: flags << QLatin1String("System");
never evaluated: filters & QDir::System
0
2256 if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive");
never executed: flags << QLatin1String("CaseSensitive");
never evaluated: filters & QDir::CaseSensitive
0
2257 }
never executed: }
0
2258 debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1Char('|'))) << ')';
never executed (the execution status of this line is deduced): debug << "QDir::Filters(" << QString(flags.join(QLatin1Char('|'))).toLocal8Bit().constData() << ')';
-
2259 return debug;
never executed: return debug;
0
2260} -
2261 -
2262static QDebug operator<<(QDebug debug, QDir::SortFlags sorting) -
2263{ -
2264 if (sorting == QDir::NoSort) {
never evaluated: sorting == QDir::NoSort
0
2265 debug << "QDir::SortFlags(NoSort)";
never executed (the execution status of this line is deduced): debug << "QDir::SortFlags(NoSort)";
-
2266 } else {
never executed: }
0
2267 QString type;
never executed (the execution status of this line is deduced): QString type;
-
2268 if ((sorting & 3) == QDir::Name) type = QLatin1String("Name");
never executed: type = QLatin1String("Name");
never evaluated: (sorting & 3) == QDir::Name
0
2269 if ((sorting & 3) == QDir::Time) type = QLatin1String("Time");
never executed: type = QLatin1String("Time");
never evaluated: (sorting & 3) == QDir::Time
0
2270 if ((sorting & 3) == QDir::Size) type = QLatin1String("Size");
never executed: type = QLatin1String("Size");
never evaluated: (sorting & 3) == QDir::Size
0
2271 if ((sorting & 3) == QDir::Unsorted) type = QLatin1String("Unsorted");
never executed: type = QLatin1String("Unsorted");
never evaluated: (sorting & 3) == QDir::Unsorted
0
2272 -
2273 QStringList flags;
never executed (the execution status of this line is deduced): QStringList flags;
-
2274 if (sorting & QDir::DirsFirst) flags << QLatin1String("DirsFirst");
never executed: flags << QLatin1String("DirsFirst");
never evaluated: sorting & QDir::DirsFirst
0
2275 if (sorting & QDir::DirsLast) flags << QLatin1String("DirsLast");
never executed: flags << QLatin1String("DirsLast");
never evaluated: sorting & QDir::DirsLast
0
2276 if (sorting & QDir::IgnoreCase) flags << QLatin1String("IgnoreCase");
never executed: flags << QLatin1String("IgnoreCase");
never evaluated: sorting & QDir::IgnoreCase
0
2277 if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware");
never executed: flags << QLatin1String("LocaleAware");
never evaluated: sorting & QDir::LocaleAware
0
2278 if (sorting & QDir::Type) flags << QLatin1String("Type");
never executed: flags << QLatin1String("Type");
never evaluated: sorting & QDir::Type
0
2279 debug << "QDir::SortFlags(" << qPrintable(type)
never executed (the execution status of this line is deduced): debug << "QDir::SortFlags(" << QString(type).toLocal8Bit().constData()
-
2280 << '|'
never executed (the execution status of this line is deduced): << '|'
-
2281 << qPrintable(flags.join(QLatin1Char('|'))) << ')';
never executed (the execution status of this line is deduced): << QString(flags.join(QLatin1Char('|'))).toLocal8Bit().constData() << ')';
-
2282 }
never executed: }
0
2283 return debug;
never executed: return debug;
0
2284} -
2285 -
2286QDebug operator<<(QDebug debug, const QDir &dir) -
2287{ -
2288 debug.maybeSpace() << "QDir(" << dir.path()
never executed (the execution status of this line is deduced): debug.maybeSpace() << "QDir(" << dir.path()
-
2289 << ", nameFilters = {"
never executed (the execution status of this line is deduced): << ", nameFilters = {"
-
2290 << qPrintable(dir.nameFilters().join(QLatin1Char(',')))
never executed (the execution status of this line is deduced): << QString(dir.nameFilters().join(QLatin1Char(','))).toLocal8Bit().constData()
-
2291 << "}, "
never executed (the execution status of this line is deduced): << "}, "
-
2292 << dir.sorting()
never executed (the execution status of this line is deduced): << dir.sorting()
-
2293 << ','
never executed (the execution status of this line is deduced): << ','
-
2294 << dir.filter()
never executed (the execution status of this line is deduced): << dir.filter()
-
2295 << ')';
never executed (the execution status of this line is deduced): << ')';
-
2296 return debug.space();
never executed: return debug.space();
0
2297} -
2298#endif // QT_NO_DEBUG_STREAM -
2299 -
2300QT_END_NAMESPACE -
2301 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial