| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfileinfo.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 "qfileinfo.h" | - | ||||||||||||
| 36 | #include "qglobal.h" | - | ||||||||||||
| 37 | #include "qdir.h" | - | ||||||||||||
| 38 | #include "qfileinfo_p.h" | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const | - | ||||||||||||
| 43 | { | - | ||||||||||||
| 44 | if (cache_enabled && !fileNames[(int)name].isNull())
| 1-37017 | ||||||||||||
| 45 | return fileNames[(int)name]; executed 762 times by 14 tests: return fileNames[(int)name];Executed by:
| 762 | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QString ret; | - | ||||||||||||
| 48 | if (fileEngine == 0) { // local file; use the QFileSystemEngine directly
| 1010-35246 | ||||||||||||
| 49 | switch (name) { | - | ||||||||||||
| 50 | case QAbstractFileEngine::CanonicalName: executed 23948 times by 141 tests: case QAbstractFileEngine::CanonicalName:Executed by:
| 23948 | ||||||||||||
| 51 | case QAbstractFileEngine::CanonicalPathName: { executed 1 time by 1 test: case QAbstractFileEngine::CanonicalPathName:Executed by:
| 1 | ||||||||||||
| 52 | QFileSystemEntry entry = QFileSystemEngine::canonicalName(fileEntry, metaData); | - | ||||||||||||
| 53 | if (cache_enabled) { // be smart and store both
| 0-23948 | ||||||||||||
| 54 | fileNames[QAbstractFileEngine::CanonicalName] = entry.filePath(); | - | ||||||||||||
| 55 | fileNames[QAbstractFileEngine::CanonicalPathName] = entry.path(); | - | ||||||||||||
| 56 | } executed 23948 times by 141 tests: end of blockExecuted by:
| 23948 | ||||||||||||
| 57 | if (name == QAbstractFileEngine::CanonicalName)
| 1-23947 | ||||||||||||
| 58 | ret = entry.filePath(); executed 23947 times by 141 tests: ret = entry.filePath();Executed by:
| 23947 | ||||||||||||
| 59 | else | - | ||||||||||||
| 60 | ret = entry.path(); executed 1 time by 1 test: ret = entry.path();Executed by:
| 1 | ||||||||||||
| 61 | break; executed 23948 times by 141 tests: break;Executed by:
| 23948 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | case QAbstractFileEngine::LinkName: executed 397 times by 10 tests: case QAbstractFileEngine::LinkName:Executed by:
| 397 | ||||||||||||
| 64 | ret = QFileSystemEngine::getLinkTarget(fileEntry, metaData).filePath(); | - | ||||||||||||
| 65 | break; executed 397 times by 10 tests: break;Executed by:
| 397 | ||||||||||||
| 66 | case QAbstractFileEngine::BundleName: executed 2 times by 1 test: case QAbstractFileEngine::BundleName:Executed by:
| 2 | ||||||||||||
| 67 | ret = QFileSystemEngine::bundleName(fileEntry); | - | ||||||||||||
| 68 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||
| 69 | case QAbstractFileEngine::AbsoluteName: executed 9431 times by 53 tests: case QAbstractFileEngine::AbsoluteName:Executed by:
| 9431 | ||||||||||||
| 70 | case QAbstractFileEngine::AbsolutePathName: { executed 1467 times by 31 tests: case QAbstractFileEngine::AbsolutePathName:Executed by:
| 1467 | ||||||||||||
| 71 | QFileSystemEntry entry = QFileSystemEngine::absoluteName(fileEntry); | - | ||||||||||||
| 72 | if (cache_enabled) { // be smart and store both
| 1-10897 | ||||||||||||
| 73 | fileNames[QAbstractFileEngine::AbsoluteName] = entry.filePath(); | - | ||||||||||||
| 74 | fileNames[QAbstractFileEngine::AbsolutePathName] = entry.path(); | - | ||||||||||||
| 75 | } executed 10897 times by 69 tests: end of blockExecuted by:
| 10897 | ||||||||||||
| 76 | if (name == QAbstractFileEngine::AbsoluteName)
| 1467-9431 | ||||||||||||
| 77 | ret = entry.filePath(); executed 9431 times by 53 tests: ret = entry.filePath();Executed by:
| 9431 | ||||||||||||
| 78 | else | - | ||||||||||||
| 79 | ret = entry.path(); executed 1467 times by 31 tests: ret = entry.path();Executed by:
| 1467 | ||||||||||||
| 80 | break; executed 10898 times by 69 tests: break;Executed by:
| 10898 | ||||||||||||
| 81 | } | - | ||||||||||||
| 82 | default: break; never executed: break;never executed: default: | 0 | ||||||||||||
| 83 | } | - | ||||||||||||
| 84 | } else { | - | ||||||||||||
| 85 | ret = fileEngine->fileName(name); | - | ||||||||||||
| 86 | } executed 1010 times by 30 tests: end of blockExecuted by:
| 1010 | ||||||||||||
| 87 | if (ret.isNull())
| 641-35614 | ||||||||||||
| 88 | ret = QLatin1String(""); executed 641 times by 6 tests: ret = QLatin1String("");Executed by:
| 641 | ||||||||||||
| 89 | if (cache_enabled)
| 1-36254 | ||||||||||||
| 90 | fileNames[(int)name] = ret; executed 36254 times by 166 tests: fileNames[(int)name] = ret;Executed by:
| 36254 | ||||||||||||
| 91 | return ret; executed 36255 times by 166 tests: return ret;Executed by:
| 36255 | ||||||||||||
| 92 | } | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const | - | ||||||||||||
| 95 | { | - | ||||||||||||
| 96 | if (cache_enabled && !fileOwners[(int)own].isNull())
| 0-2 | ||||||||||||
| 97 | return fileOwners[(int)own]; never executed: return fileOwners[(int)own]; | 0 | ||||||||||||
| 98 | QString ret; | - | ||||||||||||
| 99 | if (fileEngine == 0) {
| 0-2 | ||||||||||||
| 100 | switch (own) { | - | ||||||||||||
| 101 | case QAbstractFileEngine::OwnerUser: executed 1 time by 1 test: case QAbstractFileEngine::OwnerUser:Executed by:
| 1 | ||||||||||||
| 102 | ret = QFileSystemEngine::resolveUserName(fileEntry, metaData); | - | ||||||||||||
| 103 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 104 | case QAbstractFileEngine::OwnerGroup: executed 1 time by 1 test: case QAbstractFileEngine::OwnerGroup:Executed by:
| 1 | ||||||||||||
| 105 | ret = QFileSystemEngine::resolveGroupName(fileEntry, metaData); | - | ||||||||||||
| 106 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||
| 107 | } | - | ||||||||||||
| 108 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 109 | ret = fileEngine->owner(own); | - | ||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||
| 111 | if (ret.isNull())
| 0-2 | ||||||||||||
| 112 | ret = QLatin1String(""); never executed: ret = QLatin1String(""); | 0 | ||||||||||||
| 113 | if (cache_enabled)
| 0-2 | ||||||||||||
| 114 | fileOwners[(int)own] = ret; executed 2 times by 1 test: fileOwners[(int)own] = ret;Executed by:
| 2 | ||||||||||||
| 115 | return ret; executed 2 times by 1 test: return ret;Executed by:
| 2 | ||||||||||||
| 116 | } | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const | - | ||||||||||||
| 119 | { | - | ||||||||||||
| 120 | Q_ASSERT(fileEngine); // should never be called when using the native FS | - | ||||||||||||
| 121 | // We split the testing into tests for for LinkType, BundleType, PermsMask | - | ||||||||||||
| 122 | // and the rest. | - | ||||||||||||
| 123 | // Tests for file permissions on Windows can be slow, expecially on network | - | ||||||||||||
| 124 | // paths and NTFS drives. | - | ||||||||||||
| 125 | // In order to determine if a file is a symlink or not, we have to lstat(). | - | ||||||||||||
| 126 | // If we're not interested in that information, we might as well avoid one | - | ||||||||||||
| 127 | // extra syscall. Bundle detecton on Mac can be slow, expecially on network | - | ||||||||||||
| 128 | // paths, so we separate out that as well. | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | QAbstractFileEngine::FileFlags req = 0; | - | ||||||||||||
| 131 | uint cachedFlags = 0; | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | if (request & (QAbstractFileEngine::FlagsMask | QAbstractFileEngine::TypesMask)) {
| 222-8498 | ||||||||||||
| 134 | if (!getCachedFlag(CachedFileFlags)) {
| 2063-6435 | ||||||||||||
| 135 | req |= QAbstractFileEngine::FlagsMask; | - | ||||||||||||
| 136 | req |= QAbstractFileEngine::TypesMask; | - | ||||||||||||
| 137 | req &= (~QAbstractFileEngine::LinkType); | - | ||||||||||||
| 138 | req &= (~QAbstractFileEngine::BundleType); | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | cachedFlags |= CachedFileFlags; | - | ||||||||||||
| 141 | } executed 6435 times by 75 tests: end of blockExecuted by:
| 6435 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | if (request & QAbstractFileEngine::LinkType) {
| 81-8417 | ||||||||||||
| 144 | if (!getCachedFlag(CachedLinkTypeFlag)) {
| 0-81 | ||||||||||||
| 145 | req |= QAbstractFileEngine::LinkType; | - | ||||||||||||
| 146 | cachedFlags |= CachedLinkTypeFlag; | - | ||||||||||||
| 147 | } executed 81 times by 3 tests: end of blockExecuted by:
| 81 | ||||||||||||
| 148 | } executed 81 times by 3 tests: end of blockExecuted by:
| 81 | ||||||||||||
| 149 | - | |||||||||||||
| 150 | if (request & QAbstractFileEngine::BundleType) {
| 0-8498 | ||||||||||||
| 151 | if (!getCachedFlag(CachedBundleTypeFlag)) {
| 0 | ||||||||||||
| 152 | req |= QAbstractFileEngine::BundleType; | - | ||||||||||||
| 153 | cachedFlags |= CachedBundleTypeFlag; | - | ||||||||||||
| 154 | } never executed: end of block | 0 | ||||||||||||
| 155 | } never executed: end of block | 0 | ||||||||||||
| 156 | } executed 8498 times by 75 tests: end of blockExecuted by:
| 8498 | ||||||||||||
| 157 | - | |||||||||||||
| 158 | if (request & QAbstractFileEngine::PermsMask) {
| 222-8498 | ||||||||||||
| 159 | if (!getCachedFlag(CachedPerms)) {
| 80-142 | ||||||||||||
| 160 | req |= QAbstractFileEngine::PermsMask; | - | ||||||||||||
| 161 | cachedFlags |= CachedPerms; | - | ||||||||||||
| 162 | } executed 80 times by 4 tests: end of blockExecuted by:
| 80 | ||||||||||||
| 163 | } executed 222 times by 4 tests: end of blockExecuted by:
| 222 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | if (req) {
| 2124-6596 | ||||||||||||
| 166 | if (cache_enabled)
| 1-6595 | ||||||||||||
| 167 | req &= (~QAbstractFileEngine::Refresh); executed 6595 times by 75 tests: req &= (~QAbstractFileEngine::Refresh);Executed by:
| 6595 | ||||||||||||
| 168 | else | - | ||||||||||||
| 169 | req |= QAbstractFileEngine::Refresh; executed 1 time by 1 test: req |= QAbstractFileEngine::Refresh;Executed by:
| 1 | ||||||||||||
| 170 | - | |||||||||||||
| 171 | QAbstractFileEngine::FileFlags flags = fileEngine->fileFlags(req); | - | ||||||||||||
| 172 | fileFlags |= uint(flags); | - | ||||||||||||
| 173 | setCachedFlag(cachedFlags); | - | ||||||||||||
| 174 | } executed 6596 times by 75 tests: end of blockExecuted by:
| 6596 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | return fileFlags & request; executed 8720 times by 75 tests: return fileFlags & request;Executed by:
| 8720 | ||||||||||||
| 177 | } | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | Q_ASSERT(fileEngine); // should never be called when using the native FS | - | ||||||||||||
| 182 | if (fileTimes.size() != 3)
| 0-1007 | ||||||||||||
| 183 | fileTimes.resize(3); executed 1007 times by 29 tests: fileTimes.resize(3);Executed by:
| 1007 | ||||||||||||
| 184 | if (!cache_enabled)
| 0-1007 | ||||||||||||
| 185 | clearFlags(); never executed: clearFlags(); | 0 | ||||||||||||
| 186 | uint cf; | - | ||||||||||||
| 187 | if (request == QAbstractFileEngine::CreationTime)
| 0-1007 | ||||||||||||
| 188 | cf = CachedCTime; never executed: cf = CachedCTime; | 0 | ||||||||||||
| 189 | else if (request == QAbstractFileEngine::ModificationTime)
| 0-1007 | ||||||||||||
| 190 | cf = CachedMTime; executed 1007 times by 29 tests: cf = CachedMTime;Executed by:
| 1007 | ||||||||||||
| 191 | else | - | ||||||||||||
| 192 | cf = CachedATime; never executed: cf = CachedATime; | 0 | ||||||||||||
| 193 | if (!getCachedFlag(cf)) {
| 0-1007 | ||||||||||||
| 194 | fileTimes[request] = fileEngine->fileTime(request); | - | ||||||||||||
| 195 | setCachedFlag(cf); | - | ||||||||||||
| 196 | } executed 1007 times by 29 tests: end of blockExecuted by:
| 1007 | ||||||||||||
| 197 | return fileTimes[request]; executed 1007 times by 29 tests: return fileTimes[request];Executed by:
| 1007 | ||||||||||||
| 198 | } | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | //************* QFileInfo | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | /*! | - | ||||||||||||
| 203 | \class QFileInfo | - | ||||||||||||
| 204 | \inmodule QtCore | - | ||||||||||||
| 205 | \reentrant | - | ||||||||||||
| 206 | \brief The QFileInfo class provides system-independent file information. | - | ||||||||||||
| 207 | - | |||||||||||||
| 208 | \ingroup io | - | ||||||||||||
| 209 | \ingroup shared | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | QFileInfo provides information about a file's name and position | - | ||||||||||||
| 212 | (path) in the file system, its access rights and whether it is a | - | ||||||||||||
| 213 | directory or symbolic link, etc. The file's size and last | - | ||||||||||||
| 214 | modified/read times are also available. QFileInfo can also be | - | ||||||||||||
| 215 | used to obtain information about a Qt \l{resource | - | ||||||||||||
| 216 | system}{resource}. | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 | A QFileInfo can point to a file with either a relative or an | - | ||||||||||||
| 219 | absolute file path. Absolute file paths begin with the directory | - | ||||||||||||
| 220 | separator "/" (or with a drive specification on Windows). Relative | - | ||||||||||||
| 221 | file names begin with a directory name or a file name and specify | - | ||||||||||||
| 222 | a path relative to the current working directory. An example of an | - | ||||||||||||
| 223 | absolute path is the string "/tmp/quartz". A relative path might | - | ||||||||||||
| 224 | look like "src/fatlib". You can use the function isRelative() to | - | ||||||||||||
| 225 | check whether a QFileInfo is using a relative or an absolute file | - | ||||||||||||
| 226 | path. You can call the function makeAbsolute() to convert a | - | ||||||||||||
| 227 | relative QFileInfo's path to an absolute path. | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | The file that the QFileInfo works on is set in the constructor or | - | ||||||||||||
| 230 | later with setFile(). Use exists() to see if the file exists and | - | ||||||||||||
| 231 | size() to get its size. | - | ||||||||||||
| 232 | - | |||||||||||||
| 233 | The file's type is obtained with isFile(), isDir() and | - | ||||||||||||
| 234 | isSymLink(). The symLinkTarget() function provides the name of the file | - | ||||||||||||
| 235 | the symlink points to. | - | ||||||||||||
| 236 | - | |||||||||||||
| 237 | On Unix (including \macos and iOS), the symlink has the same size() has | - | ||||||||||||
| 238 | the file it points to, because Unix handles symlinks | - | ||||||||||||
| 239 | transparently; similarly, opening a symlink using QFile | - | ||||||||||||
| 240 | effectively opens the link's target. For example: | - | ||||||||||||
| 241 | - | |||||||||||||
| 242 | \snippet code/src_corelib_io_qfileinfo.cpp 0 | - | ||||||||||||
| 243 | - | |||||||||||||
| 244 | On Windows, symlinks (shortcuts) are \c .lnk files. The reported | - | ||||||||||||
| 245 | size() is that of the symlink (not the link's target), and | - | ||||||||||||
| 246 | opening a symlink using QFile opens the \c .lnk file. For | - | ||||||||||||
| 247 | example: | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | \snippet code/src_corelib_io_qfileinfo.cpp 1 | - | ||||||||||||
| 250 | - | |||||||||||||
| 251 | Elements of the file's name can be extracted with path() and | - | ||||||||||||
| 252 | fileName(). The fileName()'s parts can be extracted with | - | ||||||||||||
| 253 | baseName(), suffix() or completeSuffix(). QFileInfo objects to | - | ||||||||||||
| 254 | directories created by Qt classes will not have a trailing file | - | ||||||||||||
| 255 | separator. If you wish to use trailing separators in your own file | - | ||||||||||||
| 256 | info objects, just append one to the file name given to the constructors | - | ||||||||||||
| 257 | or setFile(). | - | ||||||||||||
| 258 | - | |||||||||||||
| 259 | The file's dates are returned by created(), lastModified() and | - | ||||||||||||
| 260 | lastRead(). Information about the file's access permissions is | - | ||||||||||||
| 261 | obtained with isReadable(), isWritable() and isExecutable(). The | - | ||||||||||||
| 262 | file's ownership is available from owner(), ownerId(), group() and | - | ||||||||||||
| 263 | groupId(). You can examine a file's permissions and ownership in a | - | ||||||||||||
| 264 | single statement using the permission() function. | - | ||||||||||||
| 265 | - | |||||||||||||
| 266 | \target NTFS permissions | - | ||||||||||||
| 267 | \note On NTFS file systems, ownership and permissions checking is | - | ||||||||||||
| 268 | disabled by default for performance reasons. To enable it, | - | ||||||||||||
| 269 | include the following line: | - | ||||||||||||
| 270 | - | |||||||||||||
| 271 | \snippet ntfsp.cpp 0 | - | ||||||||||||
| 272 | - | |||||||||||||
| 273 | Permission checking is then turned on and off by incrementing and | - | ||||||||||||
| 274 | decrementing \c qt_ntfs_permission_lookup by 1. | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | \snippet ntfsp.cpp 1 | - | ||||||||||||
| 277 | - | |||||||||||||
| 278 | \section1 Performance Issues | - | ||||||||||||
| 279 | - | |||||||||||||
| 280 | Some of QFileInfo's functions query the file system, but for | - | ||||||||||||
| 281 | performance reasons, some functions only operate on the | - | ||||||||||||
| 282 | file name itself. For example: To return the absolute path of | - | ||||||||||||
| 283 | a relative file name, absolutePath() has to query the file system. | - | ||||||||||||
| 284 | The path() function, however, can work on the file name directly, | - | ||||||||||||
| 285 | and so it is faster. | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | \note To speed up performance, QFileInfo caches information about | - | ||||||||||||
| 288 | the file. | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | Because files can be changed by other users or programs, or | - | ||||||||||||
| 291 | even by other parts of the same program, there is a function that | - | ||||||||||||
| 292 | refreshes the file information: refresh(). If you want to switch | - | ||||||||||||
| 293 | off a QFileInfo's caching and force it to access the file system | - | ||||||||||||
| 294 | every time you request information from it call setCaching(false). | - | ||||||||||||
| 295 | - | |||||||||||||
| 296 | \sa QDir, QFile | - | ||||||||||||
| 297 | */ | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | /*! | - | ||||||||||||
| 300 | \fn QFileInfo &QFileInfo::operator=(QFileInfo &&other) | - | ||||||||||||
| 301 | - | |||||||||||||
| 302 | Move-assigns \a other to this QFileInfo instance. | - | ||||||||||||
| 303 | - | |||||||||||||
| 304 | \since 5.2 | - | ||||||||||||
| 305 | */ | - | ||||||||||||
| 306 | - | |||||||||||||
| 307 | /*! | - | ||||||||||||
| 308 | \internal | - | ||||||||||||
| 309 | */ | - | ||||||||||||
| 310 | QFileInfo::QFileInfo(QFileInfoPrivate *p) : d_ptr(p) | - | ||||||||||||
| 311 | { | - | ||||||||||||
| 312 | } executed 110054 times by 187 tests: end of blockExecuted by:
| 110054 | ||||||||||||
| 313 | - | |||||||||||||
| 314 | /*! | - | ||||||||||||
| 315 | Constructs an empty QFileInfo object. | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | Note that an empty QFileInfo object contain no file reference. | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | \sa setFile() | - | ||||||||||||
| 320 | */ | - | ||||||||||||
| 321 | QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate()) | - | ||||||||||||
| 322 | { | - | ||||||||||||
| 323 | } executed 37436 times by 172 tests: end of blockExecuted by:
| 37436 | ||||||||||||
| 324 | - | |||||||||||||
| 325 | /*! | - | ||||||||||||
| 326 | Constructs a new QFileInfo that gives information about the given | - | ||||||||||||
| 327 | file. The \a file can also include an absolute or relative path. | - | ||||||||||||
| 328 | - | |||||||||||||
| 329 | \sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() | - | ||||||||||||
| 330 | */ | - | ||||||||||||
| 331 | QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate(file)) | - | ||||||||||||
| 332 | { | - | ||||||||||||
| 333 | } executed 184016 times by 289 tests: end of blockExecuted by:
| 184016 | ||||||||||||
| 334 | - | |||||||||||||
| 335 | /*! | - | ||||||||||||
| 336 | Constructs a new QFileInfo that gives information about file \a | - | ||||||||||||
| 337 | file. | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | If the \a file has a relative path, the QFileInfo will also have a | - | ||||||||||||
| 340 | relative path. | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | \sa isRelative() | - | ||||||||||||
| 343 | */ | - | ||||||||||||
| 344 | QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate(file.fileName())) | - | ||||||||||||
| 345 | { | - | ||||||||||||
| 346 | } executed 200 times by 8 tests: end of blockExecuted by:
| 200 | ||||||||||||
| 347 | - | |||||||||||||
| 348 | /*! | - | ||||||||||||
| 349 | Constructs a new QFileInfo that gives information about the given | - | ||||||||||||
| 350 | \a file in the directory \a dir. | - | ||||||||||||
| 351 | - | |||||||||||||
| 352 | If \a dir has a relative path, the QFileInfo will also have a | - | ||||||||||||
| 353 | relative path. | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | If \a file is an absolute path, then the directory specified | - | ||||||||||||
| 356 | by \a dir will be disregarded. | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | \sa isRelative() | - | ||||||||||||
| 359 | */ | - | ||||||||||||
| 360 | QFileInfo::QFileInfo(const QDir &dir, const QString &file) | - | ||||||||||||
| 361 | : d_ptr(new QFileInfoPrivate(dir.filePath(file))) | - | ||||||||||||
| 362 | { | - | ||||||||||||
| 363 | } executed 260 times by 7 tests: end of blockExecuted by:
| 260 | ||||||||||||
| 364 | - | |||||||||||||
| 365 | /*! | - | ||||||||||||
| 366 | Constructs a new QFileInfo that is a copy of the given \a fileinfo. | - | ||||||||||||
| 367 | */ | - | ||||||||||||
| 368 | QFileInfo::QFileInfo(const QFileInfo &fileinfo) | - | ||||||||||||
| 369 | : d_ptr(fileinfo.d_ptr) | - | ||||||||||||
| 370 | { | - | ||||||||||||
| 371 | - | |||||||||||||
| 372 | } executed 124683 times by 153 tests: end of blockExecuted by:
| 124683 | ||||||||||||
| 373 | - | |||||||||||||
| 374 | /*! | - | ||||||||||||
| 375 | Destroys the QFileInfo and frees its resources. | - | ||||||||||||
| 376 | */ | - | ||||||||||||
| 377 | - | |||||||||||||
| 378 | QFileInfo::~QFileInfo() | - | ||||||||||||
| 379 | { | - | ||||||||||||
| 380 | } | - | ||||||||||||
| 381 | - | |||||||||||||
| 382 | /*! | - | ||||||||||||
| 383 | \fn bool QFileInfo::operator!=(const QFileInfo &fileinfo) const | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | Returns \c true if this QFileInfo object refers to a different file | - | ||||||||||||
| 386 | than the one specified by \a fileinfo; otherwise returns \c false. | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | \sa operator==() | - | ||||||||||||
| 389 | */ | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | /*! | - | ||||||||||||
| 392 | Returns \c true if this QFileInfo object refers to a file in the same | - | ||||||||||||
| 393 | location as \a fileinfo; otherwise returns \c false. | - | ||||||||||||
| 394 | - | |||||||||||||
| 395 | Note that the result of comparing two empty QFileInfo objects, | - | ||||||||||||
| 396 | containing no file references (file paths that do not exist or | - | ||||||||||||
| 397 | are empty), is undefined. | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | \warning This will not compare two different symbolic links | - | ||||||||||||
| 400 | pointing to the same file. | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | \warning Long and short file names that refer to the same file on Windows | - | ||||||||||||
| 403 | are treated as if they referred to different files. | - | ||||||||||||
| 404 | - | |||||||||||||
| 405 | \sa operator!=() | - | ||||||||||||
| 406 | */ | - | ||||||||||||
| 407 | bool QFileInfo::operator==(const QFileInfo &fileinfo) const | - | ||||||||||||
| 408 | { | - | ||||||||||||
| 409 | Q_D(const QFileInfo); | - | ||||||||||||
| 410 | // ### Qt 5: understand long and short file names on Windows | - | ||||||||||||
| 411 | // ### (GetFullPathName()). | - | ||||||||||||
| 412 | if (fileinfo.d_ptr == d_ptr)
| 717-2715 | ||||||||||||
| 413 | return true; executed 2715 times by 7 tests: return true;Executed by:
| 2715 | ||||||||||||
| 414 | if (d->isDefaultConstructed || fileinfo.d_ptr->isDefaultConstructed)
| 0-715 | ||||||||||||
| 415 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 416 | - | |||||||||||||
| 417 | // Assume files are the same if path is the same | - | ||||||||||||
| 418 | if (d->fileEntry.filePath() == fileinfo.d_ptr->fileEntry.filePath())
| 46-669 | ||||||||||||
| 419 | return true; executed 669 times by 9 tests: return true;Executed by:
| 669 | ||||||||||||
| 420 | - | |||||||||||||
| 421 | Qt::CaseSensitivity sensitive; | - | ||||||||||||
| 422 | if (d->fileEngine == 0 || fileinfo.d_ptr->fileEngine == 0) {
| 0-46 | ||||||||||||
| 423 | if (d->fileEngine != fileinfo.d_ptr->fileEngine) // one is native, the other is a custom file-engine
| 0-46 | ||||||||||||
| 424 | return false; never executed: return false; | 0 | ||||||||||||
| 425 | - | |||||||||||||
| 426 | sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 0-46 | ||||||||||||
| 427 | } else { executed 46 times by 5 tests: end of blockExecuted by:
| 46 | ||||||||||||
| 428 | if (d->fileEngine->caseSensitive() != fileinfo.d_ptr->fileEngine->caseSensitive())
| 0 | ||||||||||||
| 429 | return false; never executed: return false; | 0 | ||||||||||||
| 430 | sensitive = d->fileEngine->caseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 0 | ||||||||||||
| 431 | } never executed: end of block | 0 | ||||||||||||
| 432 | - | |||||||||||||
| 433 | // Fallback to expensive canonical path computation | - | ||||||||||||
| 434 | return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0; executed 46 times by 5 tests: return canonicalFilePath().compare(fileinfo.canonicalFilePath(), sensitive) == 0;Executed by:
| 46 | ||||||||||||
| 435 | } | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | /*! | - | ||||||||||||
| 438 | Makes a copy of the given \a fileinfo and assigns it to this QFileInfo. | - | ||||||||||||
| 439 | */ | - | ||||||||||||
| 440 | QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) | - | ||||||||||||
| 441 | { | - | ||||||||||||
| 442 | d_ptr = fileinfo.d_ptr; | - | ||||||||||||
| 443 | return *this; executed 130829 times by 168 tests: return *this;Executed by:
| 130829 | ||||||||||||
| 444 | } | - | ||||||||||||
| 445 | - | |||||||||||||
| 446 | /*! | - | ||||||||||||
| 447 | \fn void QFileInfo::swap(QFileInfo &other) | - | ||||||||||||
| 448 | \since 5.0 | - | ||||||||||||
| 449 | - | |||||||||||||
| 450 | Swaps this file info with \a other. This function is very fast and | - | ||||||||||||
| 451 | never fails. | - | ||||||||||||
| 452 | */ | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | /*! | - | ||||||||||||
| 455 | Sets the file that the QFileInfo provides information about to \a | - | ||||||||||||
| 456 | file. | - | ||||||||||||
| 457 | - | |||||||||||||
| 458 | The \a file can also include an absolute or relative file path. | - | ||||||||||||
| 459 | Absolute paths begin with the directory separator (e.g. "/" under | - | ||||||||||||
| 460 | Unix) or a drive specification (under Windows). Relative file | - | ||||||||||||
| 461 | names begin with a directory name or a file name and specify a | - | ||||||||||||
| 462 | path relative to the current directory. | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | Example: | - | ||||||||||||
| 465 | \snippet code/src_corelib_io_qfileinfo.cpp 2 | - | ||||||||||||
| 466 | - | |||||||||||||
| 467 | \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath() | - | ||||||||||||
| 468 | */ | - | ||||||||||||
| 469 | void QFileInfo::setFile(const QString &file) | - | ||||||||||||
| 470 | { | - | ||||||||||||
| 471 | bool caching = d_ptr.constData()->cache_enabled; | - | ||||||||||||
| 472 | *this = QFileInfo(file); | - | ||||||||||||
| 473 | d_ptr->cache_enabled = caching; | - | ||||||||||||
| 474 | } executed 1592 times by 24 tests: end of blockExecuted by:
| 1592 | ||||||||||||
| 475 | - | |||||||||||||
| 476 | /*! | - | ||||||||||||
| 477 | \overload | - | ||||||||||||
| 478 | - | |||||||||||||
| 479 | Sets the file that the QFileInfo provides information about to \a | - | ||||||||||||
| 480 | file. | - | ||||||||||||
| 481 | - | |||||||||||||
| 482 | If \a file includes a relative path, the QFileInfo will also have | - | ||||||||||||
| 483 | a relative path. | - | ||||||||||||
| 484 | - | |||||||||||||
| 485 | \sa isRelative() | - | ||||||||||||
| 486 | */ | - | ||||||||||||
| 487 | void QFileInfo::setFile(const QFile &file) | - | ||||||||||||
| 488 | { | - | ||||||||||||
| 489 | setFile(file.fileName()); | - | ||||||||||||
| 490 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 491 | - | |||||||||||||
| 492 | /*! | - | ||||||||||||
| 493 | \overload | - | ||||||||||||
| 494 | - | |||||||||||||
| 495 | Sets the file that the QFileInfo provides information about to \a | - | ||||||||||||
| 496 | file in directory \a dir. | - | ||||||||||||
| 497 | - | |||||||||||||
| 498 | If \a file includes a relative path, the QFileInfo will also | - | ||||||||||||
| 499 | have a relative path. | - | ||||||||||||
| 500 | - | |||||||||||||
| 501 | \sa isRelative() | - | ||||||||||||
| 502 | */ | - | ||||||||||||
| 503 | void QFileInfo::setFile(const QDir &dir, const QString &file) | - | ||||||||||||
| 504 | { | - | ||||||||||||
| 505 | setFile(dir.filePath(file)); | - | ||||||||||||
| 506 | } executed 628 times by 2 tests: end of blockExecuted by:
| 628 | ||||||||||||
| 507 | - | |||||||||||||
| 508 | /*! | - | ||||||||||||
| 509 | Returns an absolute path including the file name. | - | ||||||||||||
| 510 | - | |||||||||||||
| 511 | The absolute path name consists of the full path and the file | - | ||||||||||||
| 512 | name. On Unix this will always begin with the root, '/', | - | ||||||||||||
| 513 | directory. On Windows this will always begin 'D:/' where D is a | - | ||||||||||||
| 514 | drive letter, except for network shares that are not mapped to a | - | ||||||||||||
| 515 | drive letter, in which case the path will begin '//sharename/'. | - | ||||||||||||
| 516 | QFileInfo will uppercase drive letters. Note that QDir does not do | - | ||||||||||||
| 517 | this. The code snippet below shows this. | - | ||||||||||||
| 518 | - | |||||||||||||
| 519 | \snippet code/src_corelib_io_qfileinfo.cpp newstuff | - | ||||||||||||
| 520 | - | |||||||||||||
| 521 | This function returns the same as filePath(), unless isRelative() | - | ||||||||||||
| 522 | is true. In contrast to canonicalFilePath(), symbolic links or | - | ||||||||||||
| 523 | redundant "." or ".." elements are not necessarily removed. | - | ||||||||||||
| 524 | - | |||||||||||||
| 525 | \warning If filePath() is empty the behavior of this function | - | ||||||||||||
| 526 | is undefined. | - | ||||||||||||
| 527 | - | |||||||||||||
| 528 | \sa filePath(), canonicalFilePath(), isRelative() | - | ||||||||||||
| 529 | */ | - | ||||||||||||
| 530 | QString QFileInfo::absoluteFilePath() const | - | ||||||||||||
| 531 | { | - | ||||||||||||
| 532 | Q_D(const QFileInfo); | - | ||||||||||||
| 533 | if (d->isDefaultConstructed)
| 0-11018 | ||||||||||||
| 534 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 535 | return d->getFileName(QAbstractFileEngine::AbsoluteName); executed 11018 times by 61 tests: return d->getFileName(QAbstractFileEngine::AbsoluteName);Executed by:
| 11018 | ||||||||||||
| 536 | } | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | /*! | - | ||||||||||||
| 539 | Returns the canonical path including the file name, i.e. an absolute | - | ||||||||||||
| 540 | path without symbolic links or redundant "." or ".." elements. | - | ||||||||||||
| 541 | - | |||||||||||||
| 542 | If the file does not exist, canonicalFilePath() returns an empty | - | ||||||||||||
| 543 | string. | - | ||||||||||||
| 544 | - | |||||||||||||
| 545 | \sa filePath(), absoluteFilePath(), dir() | - | ||||||||||||
| 546 | */ | - | ||||||||||||
| 547 | QString QFileInfo::canonicalFilePath() const | - | ||||||||||||
| 548 | { | - | ||||||||||||
| 549 | Q_D(const QFileInfo); | - | ||||||||||||
| 550 | if (d->isDefaultConstructed)
| 0-24125 | ||||||||||||
| 551 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 552 | return d->getFileName(QAbstractFileEngine::CanonicalName); executed 24125 times by 141 tests: return d->getFileName(QAbstractFileEngine::CanonicalName);Executed by:
| 24125 | ||||||||||||
| 553 | } | - | ||||||||||||
| 554 | - | |||||||||||||
| 555 | - | |||||||||||||
| 556 | /*! | - | ||||||||||||
| 557 | Returns a file's path absolute path. This doesn't include the | - | ||||||||||||
| 558 | file name. | - | ||||||||||||
| 559 | - | |||||||||||||
| 560 | On Unix the absolute path will always begin with the root, '/', | - | ||||||||||||
| 561 | directory. On Windows this will always begin 'D:/' where D is a | - | ||||||||||||
| 562 | drive letter, except for network shares that are not mapped to a | - | ||||||||||||
| 563 | drive letter, in which case the path will begin '//sharename/'. | - | ||||||||||||
| 564 | - | |||||||||||||
| 565 | In contrast to canonicalPath() symbolic links or redundant "." or | - | ||||||||||||
| 566 | ".." elements are not necessarily removed. | - | ||||||||||||
| 567 | - | |||||||||||||
| 568 | \warning If filePath() is empty the behavior of this function | - | ||||||||||||
| 569 | is undefined. | - | ||||||||||||
| 570 | - | |||||||||||||
| 571 | \sa absoluteFilePath(), path(), canonicalPath(), fileName(), isRelative() | - | ||||||||||||
| 572 | */ | - | ||||||||||||
| 573 | QString QFileInfo::absolutePath() const | - | ||||||||||||
| 574 | { | - | ||||||||||||
| 575 | Q_D(const QFileInfo); | - | ||||||||||||
| 576 | - | |||||||||||||
| 577 | if (d->isDefaultConstructed) {
| 0-1475 | ||||||||||||
| 578 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 579 | } else if (d->fileEntry.isEmpty()) {
| 0-1475 | ||||||||||||
| 580 | qWarning("QFileInfo::absolutePath: Constructed with empty filename"); | - | ||||||||||||
| 581 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 582 | } | - | ||||||||||||
| 583 | return d->getFileName(QAbstractFileEngine::AbsolutePathName); executed 1475 times by 32 tests: return d->getFileName(QAbstractFileEngine::AbsolutePathName);Executed by:
| 1475 | ||||||||||||
| 584 | } | - | ||||||||||||
| 585 | - | |||||||||||||
| 586 | /*! | - | ||||||||||||
| 587 | Returns the file's path canonical path (excluding the file name), | - | ||||||||||||
| 588 | i.e. an absolute path without symbolic links or redundant "." or ".." elements. | - | ||||||||||||
| 589 | - | |||||||||||||
| 590 | If the file does not exist, canonicalPath() returns an empty string. | - | ||||||||||||
| 591 | - | |||||||||||||
| 592 | \sa path(), absolutePath() | - | ||||||||||||
| 593 | */ | - | ||||||||||||
| 594 | QString QFileInfo::canonicalPath() const | - | ||||||||||||
| 595 | { | - | ||||||||||||
| 596 | Q_D(const QFileInfo); | - | ||||||||||||
| 597 | if (d->isDefaultConstructed)
| 0-1 | ||||||||||||
| 598 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 599 | return d->getFileName(QAbstractFileEngine::CanonicalPathName); executed 1 time by 1 test: return d->getFileName(QAbstractFileEngine::CanonicalPathName);Executed by:
| 1 | ||||||||||||
| 600 | } | - | ||||||||||||
| 601 | - | |||||||||||||
| 602 | /*! | - | ||||||||||||
| 603 | Returns the file's path. This doesn't include the file name. | - | ||||||||||||
| 604 | - | |||||||||||||
| 605 | Note that, if this QFileInfo object is given a path ending in a | - | ||||||||||||
| 606 | slash, the name of the file is considered empty and this function | - | ||||||||||||
| 607 | will return the entire path. | - | ||||||||||||
| 608 | - | |||||||||||||
| 609 | \sa filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative() | - | ||||||||||||
| 610 | */ | - | ||||||||||||
| 611 | QString QFileInfo::path() const | - | ||||||||||||
| 612 | { | - | ||||||||||||
| 613 | Q_D(const QFileInfo); | - | ||||||||||||
| 614 | if (d->isDefaultConstructed)
| 0-1815 | ||||||||||||
| 615 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 616 | return d->fileEntry.path(); executed 1815 times by 37 tests: return d->fileEntry.path();Executed by:
| 1815 | ||||||||||||
| 617 | } | - | ||||||||||||
| 618 | - | |||||||||||||
| 619 | /*! | - | ||||||||||||
| 620 | \fn bool QFileInfo::isAbsolute() const | - | ||||||||||||
| 621 | - | |||||||||||||
| 622 | Returns \c true if the file path name is absolute, otherwise returns | - | ||||||||||||
| 623 | false if the path is relative. | - | ||||||||||||
| 624 | - | |||||||||||||
| 625 | \sa isRelative() | - | ||||||||||||
| 626 | */ | - | ||||||||||||
| 627 | - | |||||||||||||
| 628 | /*! | - | ||||||||||||
| 629 | Returns \c true if the file path name is relative, otherwise returns | - | ||||||||||||
| 630 | false if the path is absolute (e.g. under Unix a path is absolute | - | ||||||||||||
| 631 | if it begins with a "/"). | - | ||||||||||||
| 632 | - | |||||||||||||
| 633 | \sa isAbsolute() | - | ||||||||||||
| 634 | */ | - | ||||||||||||
| 635 | bool QFileInfo::isRelative() const | - | ||||||||||||
| 636 | { | - | ||||||||||||
| 637 | Q_D(const QFileInfo); | - | ||||||||||||
| 638 | if (d->isDefaultConstructed)
| 0-121380 | ||||||||||||
| 639 | return true; never executed: return true; | 0 | ||||||||||||
| 640 | if (d->fileEngine == 0)
| 13-121367 | ||||||||||||
| 641 | return d->fileEntry.isRelative(); executed 121367 times by 251 tests: return d->fileEntry.isRelative();Executed by:
| 121367 | ||||||||||||
| 642 | return d->fileEngine->isRelativePath(); executed 13 times by 5 tests: return d->fileEngine->isRelativePath();Executed by:
| 13 | ||||||||||||
| 643 | } | - | ||||||||||||
| 644 | - | |||||||||||||
| 645 | /*! | - | ||||||||||||
| 646 | Converts the file's path to an absolute path if it is not already in that form. | - | ||||||||||||
| 647 | Returns \c true to indicate that the path was converted; otherwise returns \c false | - | ||||||||||||
| 648 | to indicate that the path was already absolute. | - | ||||||||||||
| 649 | - | |||||||||||||
| 650 | \sa filePath(), isRelative() | - | ||||||||||||
| 651 | */ | - | ||||||||||||
| 652 | bool QFileInfo::makeAbsolute() | - | ||||||||||||
| 653 | { | - | ||||||||||||
| 654 | if (d_ptr.constData()->isDefaultConstructed
| 0-1 | ||||||||||||
| 655 | || !d_ptr.constData()->fileEntry.isRelative())
| 0-1 | ||||||||||||
| 656 | return false; never executed: return false; | 0 | ||||||||||||
| 657 | - | |||||||||||||
| 658 | setFile(absoluteFilePath()); | - | ||||||||||||
| 659 | return true; executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||
| 660 | } | - | ||||||||||||
| 661 | - | |||||||||||||
| 662 | /*! | - | ||||||||||||
| 663 | Returns \c true if the file exists; otherwise returns \c false. | - | ||||||||||||
| 664 | - | |||||||||||||
| 665 | \note If the file is a symlink that points to a non-existing | - | ||||||||||||
| 666 | file, false is returned. | - | ||||||||||||
| 667 | */ | - | ||||||||||||
| 668 | bool QFileInfo::exists() const | - | ||||||||||||
| 669 | { | - | ||||||||||||
| 670 | Q_D(const QFileInfo); | - | ||||||||||||
| 671 | if (d->isDefaultConstructed)
| 80-55833 | ||||||||||||
| 672 | return false; executed 80 times by 2 tests: return false;Executed by:
| 80 | ||||||||||||
| 673 | if (d->fileEngine == 0) {
| 6295-49538 | ||||||||||||
| 674 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ExistsAttribute))
| 0-49538 | ||||||||||||
| 675 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ExistsAttribute); executed 10080 times by 76 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ExistsAttribute);Executed by:
| 10080 | ||||||||||||
| 676 | return d->metaData.exists(); executed 49538 times by 160 tests: return d->metaData.exists();Executed by:
| 49538 | ||||||||||||
| 677 | } | - | ||||||||||||
| 678 | return d->getFileFlags(QAbstractFileEngine::ExistsFlag); executed 6295 times by 63 tests: return d->getFileFlags(QAbstractFileEngine::ExistsFlag);Executed by:
| 6295 | ||||||||||||
| 679 | } | - | ||||||||||||
| 680 | - | |||||||||||||
| 681 | /*! | - | ||||||||||||
| 682 | \since 5.2 | - | ||||||||||||
| 683 | - | |||||||||||||
| 684 | Returns \c true if the \a file exists; otherwise returns \c false. | - | ||||||||||||
| 685 | - | |||||||||||||
| 686 | \note If \a file is a symlink that points to a non-existing | - | ||||||||||||
| 687 | file, false is returned. | - | ||||||||||||
| 688 | - | |||||||||||||
| 689 | \note Using this function is faster than using | - | ||||||||||||
| 690 | \c QFileInfo(file).exists() for file system access. | - | ||||||||||||
| 691 | */ | - | ||||||||||||
| 692 | bool QFileInfo::exists(const QString &file) | - | ||||||||||||
| 693 | { | - | ||||||||||||
| 694 | QFileSystemEntry entry(file); | - | ||||||||||||
| 695 | QFileSystemMetaData data; | - | ||||||||||||
| 696 | QAbstractFileEngine *engine = | - | ||||||||||||
| 697 | QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data); | - | ||||||||||||
| 698 | // Expensive fallback to non-QFileSystemEngine implementation | - | ||||||||||||
| 699 | if (engine)
| 4689-113524 | ||||||||||||
| 700 | return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists(); executed 4689 times by 34 tests: return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();Executed by:
| 4689 | ||||||||||||
| 701 | - | |||||||||||||
| 702 | QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute); | - | ||||||||||||
| 703 | return data.exists(); executed 113524 times by 220 tests: return data.exists();Executed by:
| 113524 | ||||||||||||
| 704 | } | - | ||||||||||||
| 705 | - | |||||||||||||
| 706 | /*! | - | ||||||||||||
| 707 | Refreshes the information about the file, i.e. reads in information | - | ||||||||||||
| 708 | from the file system the next time a cached property is fetched. | - | ||||||||||||
| 709 | - | |||||||||||||
| 710 | \note On Windows CE, there might be a delay for the file system driver | - | ||||||||||||
| 711 | to detect changes on the file. | - | ||||||||||||
| 712 | */ | - | ||||||||||||
| 713 | void QFileInfo::refresh() | - | ||||||||||||
| 714 | { | - | ||||||||||||
| 715 | Q_D(QFileInfo); | - | ||||||||||||
| 716 | d->clear(); | - | ||||||||||||
| 717 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 718 | - | |||||||||||||
| 719 | /*! | - | ||||||||||||
| 720 | Returns the file name, including the path (which may be absolute | - | ||||||||||||
| 721 | or relative). | - | ||||||||||||
| 722 | - | |||||||||||||
| 723 | \sa absoluteFilePath(), canonicalFilePath(), isRelative() | - | ||||||||||||
| 724 | */ | - | ||||||||||||
| 725 | QString QFileInfo::filePath() const | - | ||||||||||||
| 726 | { | - | ||||||||||||
| 727 | Q_D(const QFileInfo); | - | ||||||||||||
| 728 | if (d->isDefaultConstructed)
| 176-59318 | ||||||||||||
| 729 | return QLatin1String(""); executed 176 times by 8 tests: return QLatin1String("");Executed by:
| 176 | ||||||||||||
| 730 | return d->fileEntry.filePath(); executed 59318 times by 174 tests: return d->fileEntry.filePath();Executed by:
| 59318 | ||||||||||||
| 731 | } | - | ||||||||||||
| 732 | - | |||||||||||||
| 733 | /*! | - | ||||||||||||
| 734 | Returns the name of the file, excluding the path. | - | ||||||||||||
| 735 | - | |||||||||||||
| 736 | Example: | - | ||||||||||||
| 737 | \snippet code/src_corelib_io_qfileinfo.cpp 3 | - | ||||||||||||
| 738 | - | |||||||||||||
| 739 | Note that, if this QFileInfo object is given a path ending in a | - | ||||||||||||
| 740 | slash, the name of the file is considered empty. | - | ||||||||||||
| 741 | - | |||||||||||||
| 742 | \sa isRelative(), filePath(), baseName(), suffix() | - | ||||||||||||
| 743 | */ | - | ||||||||||||
| 744 | QString QFileInfo::fileName() const | - | ||||||||||||
| 745 | { | - | ||||||||||||
| 746 | Q_D(const QFileInfo); | - | ||||||||||||
| 747 | if (d->isDefaultConstructed)
| 0-45875 | ||||||||||||
| 748 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 749 | return d->fileEntry.fileName(); executed 45875 times by 135 tests: return d->fileEntry.fileName();Executed by:
| 45875 | ||||||||||||
| 750 | } | - | ||||||||||||
| 751 | - | |||||||||||||
| 752 | /*! | - | ||||||||||||
| 753 | \since 4.3 | - | ||||||||||||
| 754 | Returns the name of the bundle. | - | ||||||||||||
| 755 | - | |||||||||||||
| 756 | On \macos and iOS this returns the proper localized name for a bundle if the | - | ||||||||||||
| 757 | path isBundle(). On all other platforms an empty QString is returned. | - | ||||||||||||
| 758 | - | |||||||||||||
| 759 | Example: | - | ||||||||||||
| 760 | \snippet code/src_corelib_io_qfileinfo.cpp 4 | - | ||||||||||||
| 761 | - | |||||||||||||
| 762 | \sa isBundle(), filePath(), baseName(), suffix() | - | ||||||||||||
| 763 | */ | - | ||||||||||||
| 764 | QString QFileInfo::bundleName() const | - | ||||||||||||
| 765 | { | - | ||||||||||||
| 766 | Q_D(const QFileInfo); | - | ||||||||||||
| 767 | if (d->isDefaultConstructed)
| 0-2 | ||||||||||||
| 768 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 769 | return d->getFileName(QAbstractFileEngine::BundleName); executed 2 times by 1 test: return d->getFileName(QAbstractFileEngine::BundleName);Executed by:
| 2 | ||||||||||||
| 770 | } | - | ||||||||||||
| 771 | - | |||||||||||||
| 772 | /*! | - | ||||||||||||
| 773 | Returns the base name of the file without the path. | - | ||||||||||||
| 774 | - | |||||||||||||
| 775 | The base name consists of all characters in the file up to (but | - | ||||||||||||
| 776 | not including) the \e first '.' character. | - | ||||||||||||
| 777 | - | |||||||||||||
| 778 | Example: | - | ||||||||||||
| 779 | \snippet code/src_corelib_io_qfileinfo.cpp 5 | - | ||||||||||||
| 780 | - | |||||||||||||
| 781 | - | |||||||||||||
| 782 | The base name of a file is computed equally on all platforms, independent | - | ||||||||||||
| 783 | of file naming conventions (e.g., ".bashrc" on Unix has an empty base | - | ||||||||||||
| 784 | name, and the suffix is "bashrc"). | - | ||||||||||||
| 785 | - | |||||||||||||
| 786 | \sa fileName(), suffix(), completeSuffix(), completeBaseName() | - | ||||||||||||
| 787 | */ | - | ||||||||||||
| 788 | QString QFileInfo::baseName() const | - | ||||||||||||
| 789 | { | - | ||||||||||||
| 790 | Q_D(const QFileInfo); | - | ||||||||||||
| 791 | if (d->isDefaultConstructed)
| 0-11928 | ||||||||||||
| 792 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 793 | return d->fileEntry.baseName(); executed 11928 times by 81 tests: return d->fileEntry.baseName();Executed by:
| 11928 | ||||||||||||
| 794 | } | - | ||||||||||||
| 795 | - | |||||||||||||
| 796 | /*! | - | ||||||||||||
| 797 | Returns the complete base name of the file without the path. | - | ||||||||||||
| 798 | - | |||||||||||||
| 799 | The complete base name consists of all characters in the file up | - | ||||||||||||
| 800 | to (but not including) the \e last '.' character. | - | ||||||||||||
| 801 | - | |||||||||||||
| 802 | Example: | - | ||||||||||||
| 803 | \snippet code/src_corelib_io_qfileinfo.cpp 6 | - | ||||||||||||
| 804 | - | |||||||||||||
| 805 | \sa fileName(), suffix(), completeSuffix(), baseName() | - | ||||||||||||
| 806 | */ | - | ||||||||||||
| 807 | QString QFileInfo::completeBaseName() const | - | ||||||||||||
| 808 | { | - | ||||||||||||
| 809 | Q_D(const QFileInfo); | - | ||||||||||||
| 810 | if (d->isDefaultConstructed)
| 0-7 | ||||||||||||
| 811 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 812 | return d->fileEntry.completeBaseName(); executed 7 times by 1 test: return d->fileEntry.completeBaseName();Executed by:
| 7 | ||||||||||||
| 813 | } | - | ||||||||||||
| 814 | - | |||||||||||||
| 815 | /*! | - | ||||||||||||
| 816 | Returns the complete suffix (extension) of the file. | - | ||||||||||||
| 817 | - | |||||||||||||
| 818 | The complete suffix consists of all characters in the file after | - | ||||||||||||
| 819 | (but not including) the first '.'. | - | ||||||||||||
| 820 | - | |||||||||||||
| 821 | Example: | - | ||||||||||||
| 822 | \snippet code/src_corelib_io_qfileinfo.cpp 7 | - | ||||||||||||
| 823 | - | |||||||||||||
| 824 | \sa fileName(), suffix(), baseName(), completeBaseName() | - | ||||||||||||
| 825 | */ | - | ||||||||||||
| 826 | QString QFileInfo::completeSuffix() const | - | ||||||||||||
| 827 | { | - | ||||||||||||
| 828 | Q_D(const QFileInfo); | - | ||||||||||||
| 829 | if (d->isDefaultConstructed)
| 0-1131 | ||||||||||||
| 830 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 831 | return d->fileEntry.completeSuffix(); executed 1131 times by 35 tests: return d->fileEntry.completeSuffix();Executed by:
| 1131 | ||||||||||||
| 832 | } | - | ||||||||||||
| 833 | - | |||||||||||||
| 834 | /*! | - | ||||||||||||
| 835 | Returns the suffix (extension) of the file. | - | ||||||||||||
| 836 | - | |||||||||||||
| 837 | The suffix consists of all characters in the file after (but not | - | ||||||||||||
| 838 | including) the last '.'. | - | ||||||||||||
| 839 | - | |||||||||||||
| 840 | Example: | - | ||||||||||||
| 841 | \snippet code/src_corelib_io_qfileinfo.cpp 8 | - | ||||||||||||
| 842 | - | |||||||||||||
| 843 | The suffix of a file is computed equally on all platforms, independent of | - | ||||||||||||
| 844 | file naming conventions (e.g., ".bashrc" on Unix has an empty base name, | - | ||||||||||||
| 845 | and the suffix is "bashrc"). | - | ||||||||||||
| 846 | - | |||||||||||||
| 847 | \sa fileName(), completeSuffix(), baseName(), completeBaseName() | - | ||||||||||||
| 848 | */ | - | ||||||||||||
| 849 | QString QFileInfo::suffix() const | - | ||||||||||||
| 850 | { | - | ||||||||||||
| 851 | Q_D(const QFileInfo); | - | ||||||||||||
| 852 | if (d->isDefaultConstructed)
| 0-17082 | ||||||||||||
| 853 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 854 | return d->fileEntry.suffix(); executed 17082 times by 76 tests: return d->fileEntry.suffix();Executed by:
| 17082 | ||||||||||||
| 855 | } | - | ||||||||||||
| 856 | - | |||||||||||||
| 857 | - | |||||||||||||
| 858 | /*! | - | ||||||||||||
| 859 | Returns the path of the object's parent directory as a QDir object. | - | ||||||||||||
| 860 | - | |||||||||||||
| 861 | \b{Note:} The QDir returned always corresponds to the object's | - | ||||||||||||
| 862 | parent directory, even if the QFileInfo represents a directory. | - | ||||||||||||
| 863 | - | |||||||||||||
| 864 | For each of the following, dir() returns a QDir for | - | ||||||||||||
| 865 | \c{"~/examples/191697"}. | - | ||||||||||||
| 866 | - | |||||||||||||
| 867 | \snippet fileinfo/main.cpp 0 | - | ||||||||||||
| 868 | - | |||||||||||||
| 869 | For each of the following, dir() returns a QDir for | - | ||||||||||||
| 870 | \c{"."}. | - | ||||||||||||
| 871 | - | |||||||||||||
| 872 | \snippet fileinfo/main.cpp 1 | - | ||||||||||||
| 873 | - | |||||||||||||
| 874 | \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir() | - | ||||||||||||
| 875 | */ | - | ||||||||||||
| 876 | QDir QFileInfo::dir() const | - | ||||||||||||
| 877 | { | - | ||||||||||||
| 878 | Q_D(const QFileInfo); | - | ||||||||||||
| 879 | // ### Qt 6: Maybe rename this to parentDirectory(), considering what it actually does? | - | ||||||||||||
| 880 | return QDir(d->fileEntry.path()); executed 15 times by 3 tests: return QDir(d->fileEntry.path());Executed by:
| 15 | ||||||||||||
| 881 | } | - | ||||||||||||
| 882 | - | |||||||||||||
| 883 | /*! | - | ||||||||||||
| 884 | Returns the file's absolute path as a QDir object. | - | ||||||||||||
| 885 | - | |||||||||||||
| 886 | \sa dir(), filePath(), fileName(), isRelative() | - | ||||||||||||
| 887 | */ | - | ||||||||||||
| 888 | QDir QFileInfo::absoluteDir() const | - | ||||||||||||
| 889 | { | - | ||||||||||||
| 890 | return QDir(absolutePath()); executed 40 times by 5 tests: return QDir(absolutePath());Executed by:
| 40 | ||||||||||||
| 891 | } | - | ||||||||||||
| 892 | - | |||||||||||||
| 893 | /*! | - | ||||||||||||
| 894 | Returns \c true if the user can read the file; otherwise returns \c false. | - | ||||||||||||
| 895 | - | |||||||||||||
| 896 | \note If the \l{NTFS permissions} check has not been enabled, the result | - | ||||||||||||
| 897 | on Windows will merely reflect whether the file exists. | - | ||||||||||||
| 898 | - | |||||||||||||
| 899 | \sa isWritable(), isExecutable(), permission() | - | ||||||||||||
| 900 | */ | - | ||||||||||||
| 901 | bool QFileInfo::isReadable() const | - | ||||||||||||
| 902 | { | - | ||||||||||||
| 903 | Q_D(const QFileInfo); | - | ||||||||||||
| 904 | if (d->isDefaultConstructed)
| 0-200 | ||||||||||||
| 905 | return false; never executed: return false; | 0 | ||||||||||||
| 906 | if (d->fileEngine == 0) {
| 75-125 | ||||||||||||
| 907 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
| 0-125 | ||||||||||||
| 908 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserReadPermission); executed 125 times by 4 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserReadPermission);Executed by:
| 125 | ||||||||||||
| 909 | return (d->metaData.permissions() & QFile::ReadUser) != 0; executed 125 times by 4 tests: return (d->metaData.permissions() & QFile::ReadUser) != 0;Executed by:
| 125 | ||||||||||||
| 910 | } | - | ||||||||||||
| 911 | return d->getFileFlags(QAbstractFileEngine::ReadUserPerm); executed 75 times by 3 tests: return d->getFileFlags(QAbstractFileEngine::ReadUserPerm);Executed by:
| 75 | ||||||||||||
| 912 | } | - | ||||||||||||
| 913 | - | |||||||||||||
| 914 | /*! | - | ||||||||||||
| 915 | Returns \c true if the user can write to the file; otherwise returns \c false. | - | ||||||||||||
| 916 | - | |||||||||||||
| 917 | \note If the \l{NTFS permissions} check has not been enabled, the result on | - | ||||||||||||
| 918 | Windows will merely reflect whether the file is marked as Read Only. | - | ||||||||||||
| 919 | - | |||||||||||||
| 920 | \sa isReadable(), isExecutable(), permission() | - | ||||||||||||
| 921 | */ | - | ||||||||||||
| 922 | bool QFileInfo::isWritable() const | - | ||||||||||||
| 923 | { | - | ||||||||||||
| 924 | Q_D(const QFileInfo); | - | ||||||||||||
| 925 | if (d->isDefaultConstructed)
| 0-536 | ||||||||||||
| 926 | return false; never executed: return false; | 0 | ||||||||||||
| 927 | if (d->fileEngine == 0) {
| 71-465 | ||||||||||||
| 928 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::UserWritePermission))
| 0-465 | ||||||||||||
| 929 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserWritePermission); executed 465 times by 10 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserWritePermission);Executed by:
| 465 | ||||||||||||
| 930 | return (d->metaData.permissions() & QFile::WriteUser) != 0; executed 465 times by 10 tests: return (d->metaData.permissions() & QFile::WriteUser) != 0;Executed by:
| 465 | ||||||||||||
| 931 | } | - | ||||||||||||
| 932 | return d->getFileFlags(QAbstractFileEngine::WriteUserPerm); executed 71 times by 1 test: return d->getFileFlags(QAbstractFileEngine::WriteUserPerm);Executed by:
| 71 | ||||||||||||
| 933 | } | - | ||||||||||||
| 934 | - | |||||||||||||
| 935 | /*! | - | ||||||||||||
| 936 | Returns \c true if the file is executable; otherwise returns \c false. | - | ||||||||||||
| 937 | - | |||||||||||||
| 938 | \sa isReadable(), isWritable(), permission() | - | ||||||||||||
| 939 | */ | - | ||||||||||||
| 940 | bool QFileInfo::isExecutable() const | - | ||||||||||||
| 941 | { | - | ||||||||||||
| 942 | Q_D(const QFileInfo); | - | ||||||||||||
| 943 | if (d->isDefaultConstructed)
| 0-88 | ||||||||||||
| 944 | return false; never executed: return false; | 0 | ||||||||||||
| 945 | if (d->fileEngine == 0) {
| 17-71 | ||||||||||||
| 946 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::UserExecutePermission))
| 0-17 | ||||||||||||
| 947 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserExecutePermission); executed 17 times by 4 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserExecutePermission);Executed by:
| 17 | ||||||||||||
| 948 | return (d->metaData.permissions() & QFile::ExeUser) != 0; executed 17 times by 4 tests: return (d->metaData.permissions() & QFile::ExeUser) != 0;Executed by:
| 17 | ||||||||||||
| 949 | } | - | ||||||||||||
| 950 | return d->getFileFlags(QAbstractFileEngine::ExeUserPerm); executed 71 times by 1 test: return d->getFileFlags(QAbstractFileEngine::ExeUserPerm);Executed by:
| 71 | ||||||||||||
| 951 | } | - | ||||||||||||
| 952 | - | |||||||||||||
| 953 | /*! | - | ||||||||||||
| 954 | Returns \c true if this is a `hidden' file; otherwise returns \c false. | - | ||||||||||||
| 955 | - | |||||||||||||
| 956 | \b{Note:} This function returns \c true for the special entries | - | ||||||||||||
| 957 | "." and ".." on Unix, even though QDir::entryList threats them as shown. | - | ||||||||||||
| 958 | */ | - | ||||||||||||
| 959 | bool QFileInfo::isHidden() const | - | ||||||||||||
| 960 | { | - | ||||||||||||
| 961 | Q_D(const QFileInfo); | - | ||||||||||||
| 962 | if (d->isDefaultConstructed)
| 0-41530 | ||||||||||||
| 963 | return false; never executed: return false; | 0 | ||||||||||||
| 964 | if (d->fileEngine == 0) {
| 587-40943 | ||||||||||||
| 965 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::HiddenAttribute))
| 0-40943 | ||||||||||||
| 966 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::HiddenAttribute); executed 38544 times by 134 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::HiddenAttribute);Executed by:
| 38544 | ||||||||||||
| 967 | return d->metaData.isHidden(); executed 40943 times by 134 tests: return d->metaData.isHidden();Executed by:
| 40943 | ||||||||||||
| 968 | } | - | ||||||||||||
| 969 | return d->getFileFlags(QAbstractFileEngine::HiddenFlag); executed 587 times by 7 tests: return d->getFileFlags(QAbstractFileEngine::HiddenFlag);Executed by:
| 587 | ||||||||||||
| 970 | } | - | ||||||||||||
| 971 | - | |||||||||||||
| 972 | /*! | - | ||||||||||||
| 973 | \since 5.0 | - | ||||||||||||
| 974 | Returns \c true if the file path can be used directly with native APIs. | - | ||||||||||||
| 975 | Returns \c false if the file is otherwise supported by a virtual file system | - | ||||||||||||
| 976 | inside Qt, such as \l{the Qt Resource System}. | - | ||||||||||||
| 977 | - | |||||||||||||
| 978 | \b{Note:} Native paths may still require conversion of path separators | - | ||||||||||||
| 979 | and character encoding, depending on platform and input requirements of the | - | ||||||||||||
| 980 | native API. | - | ||||||||||||
| 981 | - | |||||||||||||
| 982 | \sa QDir::toNativeSeparators(), QFile::encodeName(), filePath(), | - | ||||||||||||
| 983 | absoluteFilePath(), canonicalFilePath() | - | ||||||||||||
| 984 | */ | - | ||||||||||||
| 985 | bool QFileInfo::isNativePath() const | - | ||||||||||||
| 986 | { | - | ||||||||||||
| 987 | Q_D(const QFileInfo); | - | ||||||||||||
| 988 | if (d->isDefaultConstructed)
| 1-439 | ||||||||||||
| 989 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 990 | if (d->fileEngine == 0)
| 43-396 | ||||||||||||
| 991 | return true; executed 396 times by 124 tests: return true;Executed by:
| 396 | ||||||||||||
| 992 | return d->getFileFlags(QAbstractFileEngine::LocalDiskFlag); executed 43 times by 5 tests: return d->getFileFlags(QAbstractFileEngine::LocalDiskFlag);Executed by:
| 43 | ||||||||||||
| 993 | } | - | ||||||||||||
| 994 | - | |||||||||||||
| 995 | /*! | - | ||||||||||||
| 996 | Returns \c true if this object points to a file or to a symbolic | - | ||||||||||||
| 997 | link to a file. Returns \c false if the | - | ||||||||||||
| 998 | object points to something which isn't a file, such as a directory. | - | ||||||||||||
| 999 | - | |||||||||||||
| 1000 | \sa isDir(), isSymLink(), isBundle() | - | ||||||||||||
| 1001 | */ | - | ||||||||||||
| 1002 | bool QFileInfo::isFile() const | - | ||||||||||||
| 1003 | { | - | ||||||||||||
| 1004 | Q_D(const QFileInfo); | - | ||||||||||||
| 1005 | if (d->isDefaultConstructed)
| 0-85084 | ||||||||||||
| 1006 | return false; never executed: return false; | 0 | ||||||||||||
| 1007 | if (d->fileEngine == 0) {
| 576-84508 | ||||||||||||
| 1008 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::FileType))
| 0-84508 | ||||||||||||
| 1009 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::FileType); executed 32078 times by 60 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::FileType);Executed by:
| 32078 | ||||||||||||
| 1010 | return d->metaData.isFile(); executed 84508 times by 160 tests: return d->metaData.isFile();Executed by:
| 84508 | ||||||||||||
| 1011 | } | - | ||||||||||||
| 1012 | return d->getFileFlags(QAbstractFileEngine::FileType); executed 576 times by 9 tests: return d->getFileFlags(QAbstractFileEngine::FileType);Executed by:
| 576 | ||||||||||||
| 1013 | } | - | ||||||||||||
| 1014 | - | |||||||||||||
| 1015 | /*! | - | ||||||||||||
| 1016 | Returns \c true if this object points to a directory or to a symbolic | - | ||||||||||||
| 1017 | link to a directory; otherwise returns \c false. | - | ||||||||||||
| 1018 | - | |||||||||||||
| 1019 | \sa isFile(), isSymLink(), isBundle() | - | ||||||||||||
| 1020 | */ | - | ||||||||||||
| 1021 | bool QFileInfo::isDir() const | - | ||||||||||||
| 1022 | { | - | ||||||||||||
| 1023 | Q_D(const QFileInfo); | - | ||||||||||||
| 1024 | if (d->isDefaultConstructed)
| 0-117476 | ||||||||||||
| 1025 | return false; never executed: return false; | 0 | ||||||||||||
| 1026 | if (d->fileEngine == 0) {
| 914-116562 | ||||||||||||
| 1027 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::DirectoryType))
| 0-116562 | ||||||||||||
| 1028 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::DirectoryType); executed 2024 times by 42 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::DirectoryType);Executed by:
| 2024 | ||||||||||||
| 1029 | return d->metaData.isDirectory(); executed 116562 times by 159 tests: return d->metaData.isDirectory();Executed by:
| 116562 | ||||||||||||
| 1030 | } | - | ||||||||||||
| 1031 | return d->getFileFlags(QAbstractFileEngine::DirectoryType); executed 914 times by 34 tests: return d->getFileFlags(QAbstractFileEngine::DirectoryType);Executed by:
| 914 | ||||||||||||
| 1032 | } | - | ||||||||||||
| 1033 | - | |||||||||||||
| 1034 | - | |||||||||||||
| 1035 | /*! | - | ||||||||||||
| 1036 | \since 4.3 | - | ||||||||||||
| 1037 | Returns \c true if this object points to a bundle or to a symbolic | - | ||||||||||||
| 1038 | link to a bundle on \macos and iOS; otherwise returns \c false. | - | ||||||||||||
| 1039 | - | |||||||||||||
| 1040 | \sa isDir(), isSymLink(), isFile() | - | ||||||||||||
| 1041 | */ | - | ||||||||||||
| 1042 | bool QFileInfo::isBundle() const | - | ||||||||||||
| 1043 | { | - | ||||||||||||
| 1044 | Q_D(const QFileInfo); | - | ||||||||||||
| 1045 | if (d->isDefaultConstructed)
| 0-169 | ||||||||||||
| 1046 | return false; never executed: return false; | 0 | ||||||||||||
| 1047 | if (d->fileEngine == 0) {
| 0-169 | ||||||||||||
| 1048 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::BundleType))
| 0-169 | ||||||||||||
| 1049 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::BundleType); never executed: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::BundleType); | 0 | ||||||||||||
| 1050 | return d->metaData.isBundle(); executed 169 times by 4 tests: return d->metaData.isBundle();Executed by:
| 169 | ||||||||||||
| 1051 | } | - | ||||||||||||
| 1052 | return d->getFileFlags(QAbstractFileEngine::BundleType); never executed: return d->getFileFlags(QAbstractFileEngine::BundleType); | 0 | ||||||||||||
| 1053 | } | - | ||||||||||||
| 1054 | - | |||||||||||||
| 1055 | /*! | - | ||||||||||||
| 1056 | Returns \c true if this object points to a symbolic link (or to a | - | ||||||||||||
| 1057 | shortcut on Windows); otherwise returns \c false. | - | ||||||||||||
| 1058 | - | |||||||||||||
| 1059 | On Unix (including \macos and iOS), opening a symlink effectively opens | - | ||||||||||||
| 1060 | the \l{symLinkTarget()}{link's target}. On Windows, it opens the \c | - | ||||||||||||
| 1061 | .lnk file itself. | - | ||||||||||||
| 1062 | - | |||||||||||||
| 1063 | Example: | - | ||||||||||||
| 1064 | - | |||||||||||||
| 1065 | \snippet code/src_corelib_io_qfileinfo.cpp 9 | - | ||||||||||||
| 1066 | - | |||||||||||||
| 1067 | \note If the symlink points to a non existing file, exists() returns | - | ||||||||||||
| 1068 | false. | - | ||||||||||||
| 1069 | - | |||||||||||||
| 1070 | \sa isFile(), isDir(), symLinkTarget() | - | ||||||||||||
| 1071 | */ | - | ||||||||||||
| 1072 | bool QFileInfo::isSymLink() const | - | ||||||||||||
| 1073 | { | - | ||||||||||||
| 1074 | Q_D(const QFileInfo); | - | ||||||||||||
| 1075 | if (d->isDefaultConstructed)
| 0-25675 | ||||||||||||
| 1076 | return false; never executed: return false; | 0 | ||||||||||||
| 1077 | if (d->fileEngine == 0) {
| 81-25594 | ||||||||||||
| 1078 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::LegacyLinkType))
| 0-25594 | ||||||||||||
| 1079 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::LegacyLinkType); executed 4686 times by 39 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::LegacyLinkType);Executed by:
| 4686 | ||||||||||||
| 1080 | return d->metaData.isLegacyLink(); executed 25594 times by 55 tests: return d->metaData.isLegacyLink();Executed by:
| 25594 | ||||||||||||
| 1081 | } | - | ||||||||||||
| 1082 | return d->getFileFlags(QAbstractFileEngine::LinkType); executed 81 times by 3 tests: return d->getFileFlags(QAbstractFileEngine::LinkType);Executed by:
| 81 | ||||||||||||
| 1083 | } | - | ||||||||||||
| 1084 | - | |||||||||||||
| 1085 | /*! | - | ||||||||||||
| 1086 | Returns \c true if the object points to a directory or to a symbolic | - | ||||||||||||
| 1087 | link to a directory, and that directory is the root directory; otherwise | - | ||||||||||||
| 1088 | returns \c false. | - | ||||||||||||
| 1089 | */ | - | ||||||||||||
| 1090 | bool QFileInfo::isRoot() const | - | ||||||||||||
| 1091 | { | - | ||||||||||||
| 1092 | Q_D(const QFileInfo); | - | ||||||||||||
| 1093 | if (d->isDefaultConstructed)
| 2-13786 | ||||||||||||
| 1094 | return true; executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||
| 1095 | if (d->fileEngine == 0) {
| 2-13784 | ||||||||||||
| 1096 | if (d->fileEntry.isRoot()) {
| 652-13132 | ||||||||||||
| 1097 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||
| 1098 | //the path is a drive root, but the drive may not exist | - | ||||||||||||
| 1099 | //for backward compatibility, return true only if the drive exists | - | ||||||||||||
| 1100 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ExistsAttribute)) | - | ||||||||||||
| 1101 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ExistsAttribute); | - | ||||||||||||
| 1102 | return d->metaData.exists(); | - | ||||||||||||
| 1103 | #else | - | ||||||||||||
| 1104 | return true; executed 652 times by 12 tests: return true;Executed by:
| 652 | ||||||||||||
| 1105 | #endif | - | ||||||||||||
| 1106 | } | - | ||||||||||||
| 1107 | return false; executed 13132 times by 13 tests: return false;Executed by:
| 13132 | ||||||||||||
| 1108 | } | - | ||||||||||||
| 1109 | return d->getFileFlags(QAbstractFileEngine::RootFlag); executed 2 times by 1 test: return d->getFileFlags(QAbstractFileEngine::RootFlag);Executed by:
| 2 | ||||||||||||
| 1110 | } | - | ||||||||||||
| 1111 | - | |||||||||||||
| 1112 | /*! | - | ||||||||||||
| 1113 | \fn QString QFileInfo::symLinkTarget() const | - | ||||||||||||
| 1114 | \since 4.2 | - | ||||||||||||
| 1115 | - | |||||||||||||
| 1116 | Returns the absolute path to the file or directory a symlink (or shortcut | - | ||||||||||||
| 1117 | on Windows) points to, or a an empty string if the object isn't a symbolic | - | ||||||||||||
| 1118 | link. | - | ||||||||||||
| 1119 | - | |||||||||||||
| 1120 | This name may not represent an existing file; it is only a string. | - | ||||||||||||
| 1121 | QFileInfo::exists() returns \c true if the symlink points to an | - | ||||||||||||
| 1122 | existing file. | - | ||||||||||||
| 1123 | - | |||||||||||||
| 1124 | \sa exists(), isSymLink(), isDir(), isFile() | - | ||||||||||||
| 1125 | */ | - | ||||||||||||
| 1126 | - | |||||||||||||
| 1127 | /*! | - | ||||||||||||
| 1128 | \obsolete | - | ||||||||||||
| 1129 | - | |||||||||||||
| 1130 | Use symLinkTarget() instead. | - | ||||||||||||
| 1131 | */ | - | ||||||||||||
| 1132 | QString QFileInfo::readLink() const | - | ||||||||||||
| 1133 | { | - | ||||||||||||
| 1134 | Q_D(const QFileInfo); | - | ||||||||||||
| 1135 | if (d->isDefaultConstructed)
| 0-397 | ||||||||||||
| 1136 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 1137 | return d->getFileName(QAbstractFileEngine::LinkName); executed 397 times by 10 tests: return d->getFileName(QAbstractFileEngine::LinkName);Executed by:
| 397 | ||||||||||||
| 1138 | } | - | ||||||||||||
| 1139 | - | |||||||||||||
| 1140 | /*! | - | ||||||||||||
| 1141 | Returns the owner of the file. On systems where files | - | ||||||||||||
| 1142 | do not have owners, or if an error occurs, an empty string is | - | ||||||||||||
| 1143 | returned. | - | ||||||||||||
| 1144 | - | |||||||||||||
| 1145 | This function can be time consuming under Unix (in the order of | - | ||||||||||||
| 1146 | milliseconds). On Windows, it will return an empty string unless | - | ||||||||||||
| 1147 | the \l{NTFS permissions} check has been enabled. | - | ||||||||||||
| 1148 | - | |||||||||||||
| 1149 | \sa ownerId(), group(), groupId() | - | ||||||||||||
| 1150 | */ | - | ||||||||||||
| 1151 | QString QFileInfo::owner() const | - | ||||||||||||
| 1152 | { | - | ||||||||||||
| 1153 | Q_D(const QFileInfo); | - | ||||||||||||
| 1154 | if (d->isDefaultConstructed)
| 0-1 | ||||||||||||
| 1155 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 1156 | return d->getFileOwner(QAbstractFileEngine::OwnerUser); executed 1 time by 1 test: return d->getFileOwner(QAbstractFileEngine::OwnerUser);Executed by:
| 1 | ||||||||||||
| 1157 | } | - | ||||||||||||
| 1158 | - | |||||||||||||
| 1159 | /*! | - | ||||||||||||
| 1160 | Returns the id of the owner of the file. | - | ||||||||||||
| 1161 | - | |||||||||||||
| 1162 | On Windows and on systems where files do not have owners this | - | ||||||||||||
| 1163 | function returns ((uint) -2). | - | ||||||||||||
| 1164 | - | |||||||||||||
| 1165 | \sa owner(), group(), groupId() | - | ||||||||||||
| 1166 | */ | - | ||||||||||||
| 1167 | uint QFileInfo::ownerId() const | - | ||||||||||||
| 1168 | { | - | ||||||||||||
| 1169 | Q_D(const QFileInfo); | - | ||||||||||||
| 1170 | if (d->isDefaultConstructed)
| 0-45 | ||||||||||||
| 1171 | return 0; never executed: return 0; | 0 | ||||||||||||
| 1172 | if (d->fileEngine == 0) {
| 0-45 | ||||||||||||
| 1173 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::UserId))
| 0-45 | ||||||||||||
| 1174 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserId); executed 4 times by 1 test: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::UserId);Executed by:
| 4 | ||||||||||||
| 1175 | return d->metaData.userId(); executed 45 times by 2 tests: return d->metaData.userId();Executed by:
| 45 | ||||||||||||
| 1176 | } | - | ||||||||||||
| 1177 | return d->fileEngine->ownerId(QAbstractFileEngine::OwnerUser); never executed: return d->fileEngine->ownerId(QAbstractFileEngine::OwnerUser); | 0 | ||||||||||||
| 1178 | } | - | ||||||||||||
| 1179 | - | |||||||||||||
| 1180 | /*! | - | ||||||||||||
| 1181 | Returns the group of the file. On Windows, on systems where files | - | ||||||||||||
| 1182 | do not have groups, or if an error occurs, an empty string is | - | ||||||||||||
| 1183 | returned. | - | ||||||||||||
| 1184 | - | |||||||||||||
| 1185 | This function can be time consuming under Unix (in the order of | - | ||||||||||||
| 1186 | milliseconds). | - | ||||||||||||
| 1187 | - | |||||||||||||
| 1188 | \sa groupId(), owner(), ownerId() | - | ||||||||||||
| 1189 | */ | - | ||||||||||||
| 1190 | QString QFileInfo::group() const | - | ||||||||||||
| 1191 | { | - | ||||||||||||
| 1192 | Q_D(const QFileInfo); | - | ||||||||||||
| 1193 | if (d->isDefaultConstructed)
| 0-1 | ||||||||||||
| 1194 | return QLatin1String(""); never executed: return QLatin1String(""); | 0 | ||||||||||||
| 1195 | return d->getFileOwner(QAbstractFileEngine::OwnerGroup); executed 1 time by 1 test: return d->getFileOwner(QAbstractFileEngine::OwnerGroup);Executed by:
| 1 | ||||||||||||
| 1196 | } | - | ||||||||||||
| 1197 | - | |||||||||||||
| 1198 | /*! | - | ||||||||||||
| 1199 | Returns the id of the group the file belongs to. | - | ||||||||||||
| 1200 | - | |||||||||||||
| 1201 | On Windows and on systems where files do not have groups this | - | ||||||||||||
| 1202 | function always returns (uint) -2. | - | ||||||||||||
| 1203 | - | |||||||||||||
| 1204 | \sa group(), owner(), ownerId() | - | ||||||||||||
| 1205 | */ | - | ||||||||||||
| 1206 | uint QFileInfo::groupId() const | - | ||||||||||||
| 1207 | { | - | ||||||||||||
| 1208 | Q_D(const QFileInfo); | - | ||||||||||||
| 1209 | if (d->isDefaultConstructed)
| 0-38 | ||||||||||||
| 1210 | return 0; never executed: return 0; | 0 | ||||||||||||
| 1211 | if (d->fileEngine == 0) {
| 0-38 | ||||||||||||
| 1212 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::GroupId))
| 0-38 | ||||||||||||
| 1213 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::GroupId); never executed: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::GroupId); | 0 | ||||||||||||
| 1214 | return d->metaData.groupId(); executed 38 times by 1 test: return d->metaData.groupId();Executed by:
| 38 | ||||||||||||
| 1215 | } | - | ||||||||||||
| 1216 | return d->fileEngine->ownerId(QAbstractFileEngine::OwnerGroup); never executed: return d->fileEngine->ownerId(QAbstractFileEngine::OwnerGroup); | 0 | ||||||||||||
| 1217 | } | - | ||||||||||||
| 1218 | - | |||||||||||||
| 1219 | /*! | - | ||||||||||||
| 1220 | Tests for file permissions. The \a permissions argument can be | - | ||||||||||||
| 1221 | several flags of type QFile::Permissions OR-ed together to check | - | ||||||||||||
| 1222 | for permission combinations. | - | ||||||||||||
| 1223 | - | |||||||||||||
| 1224 | On systems where files do not have permissions this function | - | ||||||||||||
| 1225 | always returns \c true. | - | ||||||||||||
| 1226 | - | |||||||||||||
| 1227 | \note The result might be inaccurate on Windows if the | - | ||||||||||||
| 1228 | \l{NTFS permissions} check has not been enabled. | - | ||||||||||||
| 1229 | - | |||||||||||||
| 1230 | Example: | - | ||||||||||||
| 1231 | \snippet code/src_corelib_io_qfileinfo.cpp 10 | - | ||||||||||||
| 1232 | - | |||||||||||||
| 1233 | \sa isReadable(), isWritable(), isExecutable() | - | ||||||||||||
| 1234 | */ | - | ||||||||||||
| 1235 | bool QFileInfo::permission(QFile::Permissions permissions) const | - | ||||||||||||
| 1236 | { | - | ||||||||||||
| 1237 | Q_D(const QFileInfo); | - | ||||||||||||
| 1238 | if (d->isDefaultConstructed)
| 0-5 | ||||||||||||
| 1239 | return false; never executed: return false; | 0 | ||||||||||||
| 1240 | if (d->fileEngine == 0) {
| 2-3 | ||||||||||||
| 1241 | // the QFileSystemMetaData::MetaDataFlag and QFile::Permissions overlap, so just static cast. | - | ||||||||||||
| 1242 | QFileSystemMetaData::MetaDataFlag permissionFlags = static_cast<QFileSystemMetaData::MetaDataFlag>((int)permissions); | - | ||||||||||||
| 1243 | if (!d->cache_enabled || !d->metaData.hasFlags(permissionFlags))
| 0-2 | ||||||||||||
| 1244 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, permissionFlags); executed 2 times by 1 test: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, permissionFlags);Executed by:
| 2 | ||||||||||||
| 1245 | return (d->metaData.permissions() & permissions) == permissions; executed 2 times by 1 test: return (d->metaData.permissions() & permissions) == permissions;Executed by:
| 2 | ||||||||||||
| 1246 | } | - | ||||||||||||
| 1247 | return d->getFileFlags(QAbstractFileEngine::FileFlags((int)permissions)) == (uint)permissions; executed 3 times by 1 test: return d->getFileFlags(QAbstractFileEngine::FileFlags((int)permissions)) == (uint)permissions;Executed by:
| 3 | ||||||||||||
| 1248 | } | - | ||||||||||||
| 1249 | - | |||||||||||||
| 1250 | /*! | - | ||||||||||||
| 1251 | Returns the complete OR-ed together combination of | - | ||||||||||||
| 1252 | QFile::Permissions for the file. | - | ||||||||||||
| 1253 | - | |||||||||||||
| 1254 | \note The result might be inaccurate on Windows if the | - | ||||||||||||
| 1255 | \l{NTFS permissions} check has not been enabled. | - | ||||||||||||
| 1256 | */ | - | ||||||||||||
| 1257 | QFile::Permissions QFileInfo::permissions() const | - | ||||||||||||
| 1258 | { | - | ||||||||||||
| 1259 | Q_D(const QFileInfo); | - | ||||||||||||
| 1260 | if (d->isDefaultConstructed)
| 0-14532 | ||||||||||||
| 1261 | return 0; never executed: return 0; | 0 | ||||||||||||
| 1262 | if (d->fileEngine == 0) {
| 2-14530 | ||||||||||||
| 1263 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::Permissions))
| 0-14530 | ||||||||||||
| 1264 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::Permissions); executed 5081 times by 13 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::Permissions);Executed by:
| 5081 | ||||||||||||
| 1265 | return d->metaData.permissions(); executed 14530 times by 13 tests: return d->metaData.permissions();Executed by:
| 14530 | ||||||||||||
| 1266 | } | - | ||||||||||||
| 1267 | return QFile::Permissions(d->getFileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask); executed 2 times by 1 test: return QFile::Permissions(d->getFileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask);Executed by:
| 2 | ||||||||||||
| 1268 | } | - | ||||||||||||
| 1269 | - | |||||||||||||
| 1270 | - | |||||||||||||
| 1271 | /*! | - | ||||||||||||
| 1272 | Returns the file size in bytes. If the file does not exist or cannot be | - | ||||||||||||
| 1273 | fetched, 0 is returned. | - | ||||||||||||
| 1274 | - | |||||||||||||
| 1275 | \sa exists() | - | ||||||||||||
| 1276 | */ | - | ||||||||||||
| 1277 | qint64 QFileInfo::size() const | - | ||||||||||||
| 1278 | { | - | ||||||||||||
| 1279 | Q_D(const QFileInfo); | - | ||||||||||||
| 1280 | if (d->isDefaultConstructed)
| 1-10200 | ||||||||||||
| 1281 | return 0; executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||
| 1282 | if (d->fileEngine == 0) {
| 1106-9094 | ||||||||||||
| 1283 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::SizeAttribute))
| 2-9092 | ||||||||||||
| 1284 | QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::SizeAttribute); executed 4861 times by 20 tests: QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::SizeAttribute);Executed by:
| 4861 | ||||||||||||
| 1285 | return d->metaData.size(); executed 9094 times by 45 tests: return d->metaData.size();Executed by:
| 9094 | ||||||||||||
| 1286 | } | - | ||||||||||||
| 1287 | if (!d->getCachedFlag(QFileInfoPrivate::CachedSize)) {
| 25-1081 | ||||||||||||
| 1288 | d->setCachedFlag(QFileInfoPrivate::CachedSize); | - | ||||||||||||
| 1289 | d->fileSize = d->fileEngine->size(); | - | ||||||||||||
| 1290 | } executed 1081 times by 31 tests: end of blockExecuted by:
| 1081 | ||||||||||||
| 1291 | return d->fileSize; executed 1106 times by 31 tests: return d->fileSize;Executed by:
| 1106 | ||||||||||||
| 1292 | } | - | ||||||||||||
| 1293 | - | |||||||||||||
| 1294 | /*! | - | ||||||||||||
| 1295 | Returns the date and time when the file was created. | - | ||||||||||||
| 1296 | - | |||||||||||||
| 1297 | On most Unix systems, this function returns the time of the last | - | ||||||||||||
| 1298 | status change. A status change occurs when the file is created, | - | ||||||||||||
| 1299 | but it also occurs whenever the user writes or sets inode | - | ||||||||||||
| 1300 | information (for example, changing the file permissions). | - | ||||||||||||
| 1301 | - | |||||||||||||
| 1302 | If neither creation time nor "last status change" time are not | - | ||||||||||||
| 1303 | available, returns the same as lastModified(). | - | ||||||||||||
| 1304 | - | |||||||||||||
| 1305 | \sa lastModified(), lastRead() | - | ||||||||||||
| 1306 | */ | - | ||||||||||||
| 1307 | QDateTime QFileInfo::created() const | - | ||||||||||||
| 1308 | { | - | ||||||||||||
| 1309 | Q_D(const QFileInfo); | - | ||||||||||||
| 1310 | if (d->isDefaultConstructed)
| 1-104 | ||||||||||||
| 1311 | return QDateTime(); executed 1 time by 1 test: return QDateTime();Executed by:
| 1 | ||||||||||||
| 1312 | if (d->fileEngine == 0) {
| 0-104 | ||||||||||||
| 1313 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::CreationTime))
| 0-102 | ||||||||||||
| 1314 | if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::CreationTime))
| 3-101 | ||||||||||||
| 1315 | return QDateTime(); executed 3 times by 1 test: return QDateTime();Executed by:
| 3 | ||||||||||||
| 1316 | return d->metaData.creationTime(); executed 101 times by 3 tests: return d->metaData.creationTime();Executed by:
| 101 | ||||||||||||
| 1317 | } | - | ||||||||||||
| 1318 | return d->getFileTime(QAbstractFileEngine::CreationTime); never executed: return d->getFileTime(QAbstractFileEngine::CreationTime); | 0 | ||||||||||||
| 1319 | } | - | ||||||||||||
| 1320 | - | |||||||||||||
| 1321 | /*! | - | ||||||||||||
| 1322 | Returns the date and time when the file was last modified. | - | ||||||||||||
| 1323 | - | |||||||||||||
| 1324 | \sa created(), lastRead() | - | ||||||||||||
| 1325 | */ | - | ||||||||||||
| 1326 | QDateTime QFileInfo::lastModified() const | - | ||||||||||||
| 1327 | { | - | ||||||||||||
| 1328 | Q_D(const QFileInfo); | - | ||||||||||||
| 1329 | if (d->isDefaultConstructed)
| 1-10204 | ||||||||||||
| 1330 | return QDateTime(); executed 1 time by 1 test: return QDateTime();Executed by:
| 1 | ||||||||||||
| 1331 | if (d->fileEngine == 0) {
| 1007-9197 | ||||||||||||
| 1332 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ModificationTime))
| 2-9195 | ||||||||||||
| 1333 | if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::ModificationTime))
| 359-2903 | ||||||||||||
| 1334 | return QDateTime(); executed 2903 times by 10 tests: return QDateTime();Executed by:
| 2903 | ||||||||||||
| 1335 | return d->metaData.modificationTime(); executed 6294 times by 41 tests: return d->metaData.modificationTime();Executed by:
| 6294 | ||||||||||||
| 1336 | } | - | ||||||||||||
| 1337 | return d->getFileTime(QAbstractFileEngine::ModificationTime); executed 1007 times by 29 tests: return d->getFileTime(QAbstractFileEngine::ModificationTime);Executed by:
| 1007 | ||||||||||||
| 1338 | } | - | ||||||||||||
| 1339 | - | |||||||||||||
| 1340 | /*! | - | ||||||||||||
| 1341 | Returns the date and time when the file was last read (accessed). | - | ||||||||||||
| 1342 | - | |||||||||||||
| 1343 | On platforms where this information is not available, returns the | - | ||||||||||||
| 1344 | same as lastModified(). | - | ||||||||||||
| 1345 | - | |||||||||||||
| 1346 | \sa created(), lastModified() | - | ||||||||||||
| 1347 | */ | - | ||||||||||||
| 1348 | QDateTime QFileInfo::lastRead() const | - | ||||||||||||
| 1349 | { | - | ||||||||||||
| 1350 | Q_D(const QFileInfo); | - | ||||||||||||
| 1351 | if (d->isDefaultConstructed)
| 1-6 | ||||||||||||
| 1352 | return QDateTime(); executed 1 time by 1 test: return QDateTime();Executed by:
| 1 | ||||||||||||
| 1353 | if (d->fileEngine == 0) {
| 0-6 | ||||||||||||
| 1354 | if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::AccessTime))
| 0-4 | ||||||||||||
| 1355 | if (!QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::AccessTime))
| 3 | ||||||||||||
| 1356 | return QDateTime(); executed 3 times by 1 test: return QDateTime();Executed by:
| 3 | ||||||||||||
| 1357 | return d->metaData.accessTime(); executed 3 times by 1 test: return d->metaData.accessTime();Executed by:
| 3 | ||||||||||||
| 1358 | } | - | ||||||||||||
| 1359 | return d->getFileTime(QAbstractFileEngine::AccessTime); never executed: return d->getFileTime(QAbstractFileEngine::AccessTime); | 0 | ||||||||||||
| 1360 | } | - | ||||||||||||
| 1361 | - | |||||||||||||
| 1362 | /*! | - | ||||||||||||
| 1363 | \internal | - | ||||||||||||
| 1364 | */ | - | ||||||||||||
| 1365 | QFileInfoPrivate* QFileInfo::d_func() | - | ||||||||||||
| 1366 | { | - | ||||||||||||
| 1367 | return d_ptr.data(); executed 29 times by 5 tests: return d_ptr.data();Executed by:
| 29 | ||||||||||||
| 1368 | } | - | ||||||||||||
| 1369 | - | |||||||||||||
| 1370 | /*! | - | ||||||||||||
| 1371 | Returns \c true if caching is enabled; otherwise returns \c false. | - | ||||||||||||
| 1372 | - | |||||||||||||
| 1373 | \sa setCaching(), refresh() | - | ||||||||||||
| 1374 | */ | - | ||||||||||||
| 1375 | bool QFileInfo::caching() const | - | ||||||||||||
| 1376 | { | - | ||||||||||||
| 1377 | Q_D(const QFileInfo); | - | ||||||||||||
| 1378 | return d->cache_enabled; executed 13 times by 1 test: return d->cache_enabled;Executed by:
| 13 | ||||||||||||
| 1379 | } | - | ||||||||||||
| 1380 | - | |||||||||||||
| 1381 | /*! | - | ||||||||||||
| 1382 | If \a enable is true, enables caching of file information. If \a | - | ||||||||||||
| 1383 | enable is false caching is disabled. | - | ||||||||||||
| 1384 | - | |||||||||||||
| 1385 | When caching is enabled, QFileInfo reads the file information from | - | ||||||||||||
| 1386 | the file system the first time it's needed, but generally not | - | ||||||||||||
| 1387 | later. | - | ||||||||||||
| 1388 | - | |||||||||||||
| 1389 | Caching is enabled by default. | - | ||||||||||||
| 1390 | - | |||||||||||||
| 1391 | \sa refresh(), caching() | - | ||||||||||||
| 1392 | */ | - | ||||||||||||
| 1393 | void QFileInfo::setCaching(bool enable) | - | ||||||||||||
| 1394 | { | - | ||||||||||||
| 1395 | Q_D(QFileInfo); | - | ||||||||||||
| 1396 | d->cache_enabled = enable; | - | ||||||||||||
| 1397 | } executed 21 times by 4 tests: end of blockExecuted by:
| 21 | ||||||||||||
| 1398 | - | |||||||||||||
| 1399 | /*! | - | ||||||||||||
| 1400 | \typedef QFileInfoList | - | ||||||||||||
| 1401 | \relates QFileInfo | - | ||||||||||||
| 1402 | - | |||||||||||||
| 1403 | Synonym for QList<QFileInfo>. | - | ||||||||||||
| 1404 | */ | - | ||||||||||||
| 1405 | - | |||||||||||||
| 1406 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |