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