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