| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfile.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 "qdebug.h" | - | ||||||||||||
| 36 | #include "qfile.h" | - | ||||||||||||
| 37 | #include "qfsfileengine_p.h" | - | ||||||||||||
| 38 | #include "qtemporaryfile.h" | - | ||||||||||||
| 39 | #include "qlist.h" | - | ||||||||||||
| 40 | #include "qfileinfo.h" | - | ||||||||||||
| 41 | #include "private/qiodevice_p.h" | - | ||||||||||||
| 42 | #include "private/qfile_p.h" | - | ||||||||||||
| 43 | #include "private/qfilesystemengine_p.h" | - | ||||||||||||
| 44 | #include "private/qsystemerror_p.h" | - | ||||||||||||
| 45 | #if defined(QT_BUILD_CORE_LIB) | - | ||||||||||||
| 46 | # include "qcoreapplication.h" | - | ||||||||||||
| 47 | #endif | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | #ifdef QT_NO_QOBJECT | - | ||||||||||||
| 50 | #define tr(X) QString::fromLatin1(X) | - | ||||||||||||
| 51 | #endif | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | //************* QFilePrivate | - | ||||||||||||
| 56 | QFilePrivate::QFilePrivate() | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | QFilePrivate::~QFilePrivate() | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | bool | - | ||||||||||||
| 65 | QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags) | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | #ifdef QT_NO_FSFILEENGINE | - | ||||||||||||
| 68 | Q_UNUSED(flags); | - | ||||||||||||
| 69 | Q_UNUSED(fd); | - | ||||||||||||
| 70 | return false; | - | ||||||||||||
| 71 | #else | - | ||||||||||||
| 72 | delete fileEngine; | - | ||||||||||||
| 73 | fileEngine = 0; | - | ||||||||||||
| 74 | QFSFileEngine *fe = new QFSFileEngine; | - | ||||||||||||
| 75 | fileEngine = fe; | - | ||||||||||||
| 76 | return fe->open(QIODevice::OpenMode(flags), fd, handleFlags); executed 29 times by 3 tests: return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);Executed by:
| 29 | ||||||||||||
| 77 | #endif | - | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | bool | - | ||||||||||||
| 81 | QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags) | - | ||||||||||||
| 82 | { | - | ||||||||||||
| 83 | #ifdef QT_NO_FSFILEENGINE | - | ||||||||||||
| 84 | Q_UNUSED(flags); | - | ||||||||||||
| 85 | Q_UNUSED(fh); | - | ||||||||||||
| 86 | return false; | - | ||||||||||||
| 87 | #else | - | ||||||||||||
| 88 | delete fileEngine; | - | ||||||||||||
| 89 | fileEngine = 0; | - | ||||||||||||
| 90 | QFSFileEngine *fe = new QFSFileEngine; | - | ||||||||||||
| 91 | fileEngine = fe; | - | ||||||||||||
| 92 | return fe->open(QIODevice::OpenMode(flags), fh, handleFlags); executed 364 times by 5 tests: return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);Executed by:
| 364 | ||||||||||||
| 93 | #endif | - | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QAbstractFileEngine *QFilePrivate::engine() const | - | ||||||||||||
| 97 | { | - | ||||||||||||
| 98 | if (!fileEngine)
| 55449-257290 | ||||||||||||
| 99 | fileEngine = QAbstractFileEngine::create(fileName); executed 55449 times by 209 tests: fileEngine = QAbstractFileEngine::create(fileName);Executed by:
| 55449 | ||||||||||||
| 100 | return fileEngine; executed 312739 times by 209 tests: return fileEngine;Executed by:
| 312739 | ||||||||||||
| 101 | } | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | //************* QFile | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | /*! | - | ||||||||||||
| 106 | \class QFile | - | ||||||||||||
| 107 | \inmodule QtCore | - | ||||||||||||
| 108 | \brief The QFile class provides an interface for reading from and writing to files. | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | \ingroup io | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | \reentrant | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | QFile is an I/O device for reading and writing text and binary | - | ||||||||||||
| 115 | files and \l{The Qt Resource System}{resources}. A QFile may be | - | ||||||||||||
| 116 | used by itself or, more conveniently, with a QTextStream or | - | ||||||||||||
| 117 | QDataStream. | - | ||||||||||||
| 118 | - | |||||||||||||
| 119 | The file name is usually passed in the constructor, but it can be | - | ||||||||||||
| 120 | set at any time using setFileName(). QFile expects the file | - | ||||||||||||
| 121 | separator to be '/' regardless of operating system. The use of | - | ||||||||||||
| 122 | other separators (e.g., '\\') is not supported. | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | You can check for a file's existence using exists(), and remove a | - | ||||||||||||
| 125 | file using remove(). (More advanced file system related operations | - | ||||||||||||
| 126 | are provided by QFileInfo and QDir.) | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | The file is opened with open(), closed with close(), and flushed | - | ||||||||||||
| 129 | with flush(). Data is usually read and written using QDataStream | - | ||||||||||||
| 130 | or QTextStream, but you can also call the QIODevice-inherited | - | ||||||||||||
| 131 | functions read(), readLine(), readAll(), write(). QFile also | - | ||||||||||||
| 132 | inherits getChar(), putChar(), and ungetChar(), which work one | - | ||||||||||||
| 133 | character at a time. | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | The size of the file is returned by size(). You can get the | - | ||||||||||||
| 136 | current file position using pos(), or move to a new file position | - | ||||||||||||
| 137 | using seek(). If you've reached the end of the file, atEnd() | - | ||||||||||||
| 138 | returns \c true. | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | \section1 Reading Files Directly | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | The following example reads a text file line by line: | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | \snippet file/file.cpp 0 | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | The QIODevice::Text flag passed to open() tells Qt to convert | - | ||||||||||||
| 147 | Windows-style line terminators ("\\r\\n") into C++-style | - | ||||||||||||
| 148 | terminators ("\\n"). By default, QFile assumes binary, i.e. it | - | ||||||||||||
| 149 | doesn't perform any conversion on the bytes stored in the file. | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | \section1 Using Streams to Read Files | - | ||||||||||||
| 152 | - | |||||||||||||
| 153 | The next example uses QTextStream to read a text file | - | ||||||||||||
| 154 | line by line: | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | \snippet file/file.cpp 1 | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | QTextStream takes care of converting the 8-bit data stored on | - | ||||||||||||
| 159 | disk into a 16-bit Unicode QString. By default, it assumes that | - | ||||||||||||
| 160 | the user system's local 8-bit encoding is used (e.g., UTF-8 | - | ||||||||||||
| 161 | on most unix based operating systems; see QTextCodec::codecForLocale() for | - | ||||||||||||
| 162 | details). This can be changed using \l QTextStream::setCodec(). | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | To write text, we can use operator<<(), which is overloaded to | - | ||||||||||||
| 165 | take a QTextStream on the left and various data types (including | - | ||||||||||||
| 166 | QString) on the right: | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | \snippet file/file.cpp 2 | - | ||||||||||||
| 169 | - | |||||||||||||
| 170 | QDataStream is similar, in that you can use operator<<() to write | - | ||||||||||||
| 171 | data and operator>>() to read it back. See the class | - | ||||||||||||
| 172 | documentation for details. | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | When you use QFile, QFileInfo, and QDir to access the file system | - | ||||||||||||
| 175 | with Qt, you can use Unicode file names. On Unix, these file | - | ||||||||||||
| 176 | names are converted to an 8-bit encoding. If you want to use | - | ||||||||||||
| 177 | standard C++ APIs (\c <cstdio> or \c <iostream>) or | - | ||||||||||||
| 178 | platform-specific APIs to access files instead of QFile, you can | - | ||||||||||||
| 179 | use the encodeName() and decodeName() functions to convert | - | ||||||||||||
| 180 | between Unicode file names and 8-bit file names. | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | On Unix, there are some special system files (e.g. in \c /proc) for which | - | ||||||||||||
| 183 | size() will always return 0, yet you may still be able to read more data | - | ||||||||||||
| 184 | from such a file; the data is generated in direct response to you calling | - | ||||||||||||
| 185 | read(). In this case, however, you cannot use atEnd() to determine if | - | ||||||||||||
| 186 | there is more data to read (since atEnd() will return true for a file that | - | ||||||||||||
| 187 | claims to have size 0). Instead, you should either call readAll(), or call | - | ||||||||||||
| 188 | read() or readLine() repeatedly until no more data can be read. The next | - | ||||||||||||
| 189 | example uses QTextStream to read \c /proc/modules line by line: | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | \snippet file/file.cpp 3 | - | ||||||||||||
| 192 | - | |||||||||||||
| 193 | \section1 Signals | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | Unlike other QIODevice implementations, such as QTcpSocket, QFile does not | - | ||||||||||||
| 196 | emit the aboutToClose(), bytesWritten(), or readyRead() signals. This | - | ||||||||||||
| 197 | implementation detail means that QFile is not suitable for reading and | - | ||||||||||||
| 198 | writing certain types of files, such as device files on Unix platforms. | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | \section1 Platform Specific Issues | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | File permissions are handled differently on Unix-like systems and | - | ||||||||||||
| 203 | Windows. In a non \l{QIODevice::isWritable()}{writable} | - | ||||||||||||
| 204 | directory on Unix-like systems, files cannot be created. This is not always | - | ||||||||||||
| 205 | the case on Windows, where, for instance, the 'My Documents' | - | ||||||||||||
| 206 | directory usually is not writable, but it is still possible to | - | ||||||||||||
| 207 | create files in it. | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | Qt's understanding of file permissions is limited, which affects especially | - | ||||||||||||
| 210 | the \l QFile::setPermissions() function. On Windows, Qt will set only the | - | ||||||||||||
| 211 | legacy read-only flag, and that only when none of the Write* flags are | - | ||||||||||||
| 212 | passed. Qt does not manipulate access control lists (ACLs), which makes this | - | ||||||||||||
| 213 | function mostly useless for NTFS volumes. It may still be of use for USB | - | ||||||||||||
| 214 | sticks that use VFAT file systems. POSIX ACLs are not manipulated, either. | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | \sa QTextStream, QDataStream, QFileInfo, QDir, {The Qt Resource System} | - | ||||||||||||
| 217 | */ | - | ||||||||||||
| 218 | - | |||||||||||||
| 219 | #ifdef QT_NO_QOBJECT | - | ||||||||||||
| 220 | QFile::QFile() | - | ||||||||||||
| 221 | : QFileDevice(*new QFilePrivate) | - | ||||||||||||
| 222 | { | - | ||||||||||||
| 223 | } | - | ||||||||||||
| 224 | QFile::QFile(const QString &name) | - | ||||||||||||
| 225 | : QFileDevice(*new QFilePrivate) | - | ||||||||||||
| 226 | { | - | ||||||||||||
| 227 | d_func()->fileName = name; | - | ||||||||||||
| 228 | } | - | ||||||||||||
| 229 | QFile::QFile(QFilePrivate &dd) | - | ||||||||||||
| 230 | : QFileDevice(dd) | - | ||||||||||||
| 231 | { | - | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | #else | - | ||||||||||||
| 234 | /*! | - | ||||||||||||
| 235 | \internal | - | ||||||||||||
| 236 | */ | - | ||||||||||||
| 237 | QFile::QFile() | - | ||||||||||||
| 238 | : QFileDevice(*new QFilePrivate, 0) | - | ||||||||||||
| 239 | { | - | ||||||||||||
| 240 | } executed 846 times by 47 tests: end of blockExecuted by:
| 846 | ||||||||||||
| 241 | /*! | - | ||||||||||||
| 242 | Constructs a new file object with the given \a parent. | - | ||||||||||||
| 243 | */ | - | ||||||||||||
| 244 | QFile::QFile(QObject *parent) | - | ||||||||||||
| 245 | : QFileDevice(*new QFilePrivate, parent) | - | ||||||||||||
| 246 | { | - | ||||||||||||
| 247 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||
| 248 | /*! | - | ||||||||||||
| 249 | Constructs a new file object to represent the file with the given \a name. | - | ||||||||||||
| 250 | */ | - | ||||||||||||
| 251 | QFile::QFile(const QString &name) | - | ||||||||||||
| 252 | : QFileDevice(*new QFilePrivate, 0) | - | ||||||||||||
| 253 | { | - | ||||||||||||
| 254 | Q_D(QFile); | - | ||||||||||||
| 255 | d->fileName = name; | - | ||||||||||||
| 256 | } executed 55560 times by 210 tests: end of blockExecuted by:
| 55560 | ||||||||||||
| 257 | /*! | - | ||||||||||||
| 258 | Constructs a new file object with the given \a parent to represent the | - | ||||||||||||
| 259 | file with the specified \a name. | - | ||||||||||||
| 260 | */ | - | ||||||||||||
| 261 | QFile::QFile(const QString &name, QObject *parent) | - | ||||||||||||
| 262 | : QFileDevice(*new QFilePrivate, parent) | - | ||||||||||||
| 263 | { | - | ||||||||||||
| 264 | Q_D(QFile); | - | ||||||||||||
| 265 | d->fileName = name; | - | ||||||||||||
| 266 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 267 | /*! | - | ||||||||||||
| 268 | \internal | - | ||||||||||||
| 269 | */ | - | ||||||||||||
| 270 | QFile::QFile(QFilePrivate &dd, QObject *parent) | - | ||||||||||||
| 271 | : QFileDevice(dd, parent) | - | ||||||||||||
| 272 | { | - | ||||||||||||
| 273 | } executed 1579 times by 24 tests: end of blockExecuted by:
| 1579 | ||||||||||||
| 274 | #endif | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | /*! | - | ||||||||||||
| 277 | Destroys the file object, closing it if necessary. | - | ||||||||||||
| 278 | */ | - | ||||||||||||
| 279 | QFile::~QFile() | - | ||||||||||||
| 280 | { | - | ||||||||||||
| 281 | } | - | ||||||||||||
| 282 | - | |||||||||||||
| 283 | /*! | - | ||||||||||||
| 284 | Returns the name set by setFileName() or to the QFile | - | ||||||||||||
| 285 | constructors. | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | \sa setFileName(), QFileInfo::fileName() | - | ||||||||||||
| 288 | */ | - | ||||||||||||
| 289 | QString QFile::fileName() const | - | ||||||||||||
| 290 | { | - | ||||||||||||
| 291 | Q_D(const QFile); | - | ||||||||||||
| 292 | return d->engine()->fileName(QAbstractFileEngine::DefaultName); executed 23511 times by 89 tests: return d->engine()->fileName(QAbstractFileEngine::DefaultName);Executed by:
| 23511 | ||||||||||||
| 293 | } | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | /*! | - | ||||||||||||
| 296 | Sets the \a name of the file. The name can have no path, a | - | ||||||||||||
| 297 | relative path, or an absolute path. | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | Do not call this function if the file has already been opened. | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | If the file name has no path or a relative path, the path used | - | ||||||||||||
| 302 | will be the application's current directory path | - | ||||||||||||
| 303 | \e{at the time of the open()} call. | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | Example: | - | ||||||||||||
| 306 | \snippet code/src_corelib_io_qfile.cpp 0 | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | Note that the directory separator "/" works for all operating | - | ||||||||||||
| 309 | systems supported by Qt. | - | ||||||||||||
| 310 | - | |||||||||||||
| 311 | \sa fileName(), QFileInfo, QDir | - | ||||||||||||
| 312 | */ | - | ||||||||||||
| 313 | void | - | ||||||||||||
| 314 | QFile::setFileName(const QString &name) | - | ||||||||||||
| 315 | { | - | ||||||||||||
| 316 | Q_D(QFile); | - | ||||||||||||
| 317 | if (isOpen()) {
| 0-3036 | ||||||||||||
| 318 | qWarning("QFile::setFileName: File (%s) is already opened", | - | ||||||||||||
| 319 | qPrintable(fileName())); | - | ||||||||||||
| 320 | close(); | - | ||||||||||||
| 321 | } never executed: end of block | 0 | ||||||||||||
| 322 | if(d->fileEngine) { //get a new file engine later
| 591-2445 | ||||||||||||
| 323 | delete d->fileEngine; | - | ||||||||||||
| 324 | d->fileEngine = 0; | - | ||||||||||||
| 325 | } executed 2445 times by 16 tests: end of blockExecuted by:
| 2445 | ||||||||||||
| 326 | d->fileName = name; | - | ||||||||||||
| 327 | } executed 3036 times by 43 tests: end of blockExecuted by:
| 3036 | ||||||||||||
| 328 | - | |||||||||||||
| 329 | /*! | - | ||||||||||||
| 330 | \fn QString QFile::decodeName(const char *localFileName) | - | ||||||||||||
| 331 | - | |||||||||||||
| 332 | \overload | - | ||||||||||||
| 333 | - | |||||||||||||
| 334 | Returns the Unicode version of the given \a localFileName. See | - | ||||||||||||
| 335 | encodeName() for details. | - | ||||||||||||
| 336 | */ | - | ||||||||||||
| 337 | - | |||||||||||||
| 338 | /*! | - | ||||||||||||
| 339 | \fn QByteArray QFile::encodeName(const QString &fileName) | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | Converts \a fileName to the local 8-bit | - | ||||||||||||
| 342 | encoding determined by the user's locale. This is sufficient for | - | ||||||||||||
| 343 | file names that the user chooses. File names hard-coded into the | - | ||||||||||||
| 344 | application should only use 7-bit ASCII filename characters. | - | ||||||||||||
| 345 | - | |||||||||||||
| 346 | \sa decodeName() | - | ||||||||||||
| 347 | */ | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | /*! | - | ||||||||||||
| 350 | \typedef QFile::EncoderFn | - | ||||||||||||
| 351 | \obsolete | - | ||||||||||||
| 352 | - | |||||||||||||
| 353 | This is a typedef for a pointer to a function with the following | - | ||||||||||||
| 354 | signature: | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | \snippet code/src_corelib_io_qfile.cpp 1 | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | \sa setEncodingFunction(), encodeName() | - | ||||||||||||
| 359 | */ | - | ||||||||||||
| 360 | - | |||||||||||||
| 361 | /*! | - | ||||||||||||
| 362 | \fn QString QFile::decodeName(const QByteArray &localFileName) | - | ||||||||||||
| 363 | - | |||||||||||||
| 364 | This does the reverse of QFile::encodeName() using \a localFileName. | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | \sa encodeName() | - | ||||||||||||
| 367 | */ | - | ||||||||||||
| 368 | - | |||||||||||||
| 369 | /*! | - | ||||||||||||
| 370 | \fn void QFile::setEncodingFunction(EncoderFn function) | - | ||||||||||||
| 371 | \obsolete | - | ||||||||||||
| 372 | - | |||||||||||||
| 373 | This function does nothing. It is provided for compatibility with Qt 4 code | - | ||||||||||||
| 374 | that attempted to set a different encoding function for file names. That | - | ||||||||||||
| 375 | feature is flawed and no longer supported in Qt 5. | - | ||||||||||||
| 376 | - | |||||||||||||
| 377 | \sa encodeName(), setDecodingFunction() | - | ||||||||||||
| 378 | */ | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | /*! | - | ||||||||||||
| 381 | \typedef QFile::DecoderFn | - | ||||||||||||
| 382 | - | |||||||||||||
| 383 | This is a typedef for a pointer to a function with the following | - | ||||||||||||
| 384 | signature: | - | ||||||||||||
| 385 | - | |||||||||||||
| 386 | \snippet code/src_corelib_io_qfile.cpp 2 | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | \sa setDecodingFunction() | - | ||||||||||||
| 389 | */ | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | /*! | - | ||||||||||||
| 392 | \fn void QFile::setDecodingFunction(DecoderFn function) | - | ||||||||||||
| 393 | \obsolete | - | ||||||||||||
| 394 | - | |||||||||||||
| 395 | This function does nothing. It is provided for compatibility with Qt 4 code | - | ||||||||||||
| 396 | that attempted to set a different decoding function for file names. That | - | ||||||||||||
| 397 | feature is flawed and no longer supported in Qt 5. | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | \sa setEncodingFunction(), decodeName() | - | ||||||||||||
| 400 | */ | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | /*! | - | ||||||||||||
| 403 | \overload | - | ||||||||||||
| 404 | - | |||||||||||||
| 405 | Returns \c true if the file specified by fileName() exists; otherwise | - | ||||||||||||
| 406 | returns \c false. | - | ||||||||||||
| 407 | - | |||||||||||||
| 408 | \sa fileName(), setFileName() | - | ||||||||||||
| 409 | */ | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | bool | - | ||||||||||||
| 412 | QFile::exists() const | - | ||||||||||||
| 413 | { | - | ||||||||||||
| 414 | Q_D(const QFile); | - | ||||||||||||
| 415 | // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update | - | ||||||||||||
| 416 | return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask executed 2405 times by 57 tests: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);Executed by:
| 2405 | ||||||||||||
| 417 | | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag); executed 2405 times by 57 tests: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);Executed by:
| 2405 | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | /*! | - | ||||||||||||
| 421 | Returns \c true if the file specified by \a fileName exists; otherwise | - | ||||||||||||
| 422 | returns \c false. | - | ||||||||||||
| 423 | - | |||||||||||||
| 424 | \note If \a fileName is a symlink that points to a non-existing | - | ||||||||||||
| 425 | file, false is returned. | - | ||||||||||||
| 426 | */ | - | ||||||||||||
| 427 | - | |||||||||||||
| 428 | bool | - | ||||||||||||
| 429 | QFile::exists(const QString &fileName) | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | return QFileInfo::exists(fileName); executed 114113 times by 217 tests: return QFileInfo::exists(fileName);Executed by:
| 114113 | ||||||||||||
| 432 | } | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | /*! | - | ||||||||||||
| 435 | \fn QString QFile::symLinkTarget() const | - | ||||||||||||
| 436 | \since 4.2 | - | ||||||||||||
| 437 | \overload | - | ||||||||||||
| 438 | - | |||||||||||||
| 439 | Returns the absolute path of the file or directory a symlink (or shortcut | - | ||||||||||||
| 440 | on Windows) points to, or a an empty string if the object isn't a symbolic | - | ||||||||||||
| 441 | link. | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | This name may not represent an existing file; it is only a string. | - | ||||||||||||
| 444 | QFile::exists() returns \c true if the symlink points to an existing file. | - | ||||||||||||
| 445 | - | |||||||||||||
| 446 | \sa fileName(), setFileName() | - | ||||||||||||
| 447 | */ | - | ||||||||||||
| 448 | - | |||||||||||||
| 449 | /*! | - | ||||||||||||
| 450 | \obsolete | - | ||||||||||||
| 451 | - | |||||||||||||
| 452 | Use symLinkTarget() instead. | - | ||||||||||||
| 453 | */ | - | ||||||||||||
| 454 | QString | - | ||||||||||||
| 455 | QFile::readLink() const | - | ||||||||||||
| 456 | { | - | ||||||||||||
| 457 | Q_D(const QFile); | - | ||||||||||||
| 458 | return d->engine()->fileName(QAbstractFileEngine::LinkName); executed 2 times by 1 test: return d->engine()->fileName(QAbstractFileEngine::LinkName);Executed by:
| 2 | ||||||||||||
| 459 | } | - | ||||||||||||
| 460 | - | |||||||||||||
| 461 | /*! | - | ||||||||||||
| 462 | \fn static QString QFile::symLinkTarget(const QString &fileName) | - | ||||||||||||
| 463 | \since 4.2 | - | ||||||||||||
| 464 | - | |||||||||||||
| 465 | Returns the absolute path of the file or directory referred to by the | - | ||||||||||||
| 466 | symlink (or shortcut on Windows) specified by \a fileName, or returns an | - | ||||||||||||
| 467 | empty string if the \a fileName does not correspond to a symbolic link. | - | ||||||||||||
| 468 | - | |||||||||||||
| 469 | This name may not represent an existing file; it is only a string. | - | ||||||||||||
| 470 | QFile::exists() returns \c true if the symlink points to an existing file. | - | ||||||||||||
| 471 | */ | - | ||||||||||||
| 472 | - | |||||||||||||
| 473 | /*! | - | ||||||||||||
| 474 | \obsolete | - | ||||||||||||
| 475 | - | |||||||||||||
| 476 | Use symLinkTarget() instead. | - | ||||||||||||
| 477 | */ | - | ||||||||||||
| 478 | QString | - | ||||||||||||
| 479 | QFile::readLink(const QString &fileName) | - | ||||||||||||
| 480 | { | - | ||||||||||||
| 481 | return QFileInfo(fileName).readLink(); executed 1 time by 1 test: return QFileInfo(fileName).readLink();Executed by:
| 1 | ||||||||||||
| 482 | } | - | ||||||||||||
| 483 | - | |||||||||||||
| 484 | /*! | - | ||||||||||||
| 485 | Removes the file specified by fileName(). Returns \c true if successful; | - | ||||||||||||
| 486 | otherwise returns \c false. | - | ||||||||||||
| 487 | - | |||||||||||||
| 488 | The file is closed before it is removed. | - | ||||||||||||
| 489 | - | |||||||||||||
| 490 | \sa setFileName() | - | ||||||||||||
| 491 | */ | - | ||||||||||||
| 492 | - | |||||||||||||
| 493 | bool | - | ||||||||||||
| 494 | QFile::remove() | - | ||||||||||||
| 495 | { | - | ||||||||||||
| 496 | Q_D(QFile); | - | ||||||||||||
| 497 | if (d->fileName.isEmpty()) {
| 0-12710 | ||||||||||||
| 498 | qWarning("QFile::remove: Empty or null file name"); | - | ||||||||||||
| 499 | return false; never executed: return false; | 0 | ||||||||||||
| 500 | } | - | ||||||||||||
| 501 | unsetError(); | - | ||||||||||||
| 502 | close(); | - | ||||||||||||
| 503 | if(error() == QFile::NoError) {
| 0-12710 | ||||||||||||
| 504 | if (d->engine()->remove()) {
| 584-12126 | ||||||||||||
| 505 | unsetError(); | - | ||||||||||||
| 506 | return true; executed 12126 times by 75 tests: return true;Executed by:
| 12126 | ||||||||||||
| 507 | } | - | ||||||||||||
| 508 | d->setError(QFile::RemoveError, d->fileEngine->errorString()); | - | ||||||||||||
| 509 | } executed 584 times by 21 tests: end of blockExecuted by:
| 584 | ||||||||||||
| 510 | return false; executed 584 times by 21 tests: return false;Executed by:
| 584 | ||||||||||||
| 511 | } | - | ||||||||||||
| 512 | - | |||||||||||||
| 513 | /*! | - | ||||||||||||
| 514 | \overload | - | ||||||||||||
| 515 | - | |||||||||||||
| 516 | Removes the file specified by the \a fileName given. | - | ||||||||||||
| 517 | - | |||||||||||||
| 518 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||
| 519 | - | |||||||||||||
| 520 | \sa remove() | - | ||||||||||||
| 521 | */ | - | ||||||||||||
| 522 | - | |||||||||||||
| 523 | bool | - | ||||||||||||
| 524 | QFile::remove(const QString &fileName) | - | ||||||||||||
| 525 | { | - | ||||||||||||
| 526 | return QFile(fileName).remove(); executed 11293 times by 66 tests: return QFile(fileName).remove();Executed by:
| 11293 | ||||||||||||
| 527 | } | - | ||||||||||||
| 528 | - | |||||||||||||
| 529 | /*! | - | ||||||||||||
| 530 | Renames the file currently specified by fileName() to \a newName. | - | ||||||||||||
| 531 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||
| 532 | - | |||||||||||||
| 533 | If a file with the name \a newName already exists, rename() returns \c false | - | ||||||||||||
| 534 | (i.e., QFile will not overwrite it). | - | ||||||||||||
| 535 | - | |||||||||||||
| 536 | The file is closed before it is renamed. | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | If the rename operation fails, Qt will attempt to copy this file's | - | ||||||||||||
| 539 | contents to \a newName, and then remove this file, keeping only | - | ||||||||||||
| 540 | \a newName. If that copy operation fails or this file can't be removed, | - | ||||||||||||
| 541 | the destination file \a newName is removed to restore the old state. | - | ||||||||||||
| 542 | - | |||||||||||||
| 543 | \sa setFileName() | - | ||||||||||||
| 544 | */ | - | ||||||||||||
| 545 | - | |||||||||||||
| 546 | bool | - | ||||||||||||
| 547 | QFile::rename(const QString &newName) | - | ||||||||||||
| 548 | { | - | ||||||||||||
| 549 | Q_D(QFile); | - | ||||||||||||
| 550 | if (d->fileName.isEmpty()) {
| 0-257 | ||||||||||||
| 551 | qWarning("QFile::rename: Empty or null file name"); | - | ||||||||||||
| 552 | return false; never executed: return false; | 0 | ||||||||||||
| 553 | } | - | ||||||||||||
| 554 | if (d->fileName == newName) {
| 1-256 | ||||||||||||
| 555 | d->setError(QFile::RenameError, tr("Destination file is the same file.")); | - | ||||||||||||
| 556 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 557 | } | - | ||||||||||||
| 558 | if (!exists()) {
| 2-254 | ||||||||||||
| 559 | d->setError(QFile::RenameError, tr("Source file does not exist.")); | - | ||||||||||||
| 560 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 561 | } | - | ||||||||||||
| 562 | // If the file exists and it is a case-changing rename ("foo" -> "Foo"), | - | ||||||||||||
| 563 | // compare Ids to make sure it really is a different file. | - | ||||||||||||
| 564 | if (QFile::exists(newName)) {
| 4-250 | ||||||||||||
| 565 | if (d->fileName.compare(newName, Qt::CaseInsensitive)
| 0-4 | ||||||||||||
| 566 | || QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName))) {
| 0 | ||||||||||||
| 567 | // ### Race condition. If a file is moved in after this, it /will/ be | - | ||||||||||||
| 568 | // overwritten. On Unix, the proper solution is to use hardlinks: | - | ||||||||||||
| 569 | // return ::link(old, new) && ::remove(old); | - | ||||||||||||
| 570 | d->setError(QFile::RenameError, tr("Destination file exists")); | - | ||||||||||||
| 571 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||
| 572 | } | - | ||||||||||||
| 573 | #ifndef QT_NO_TEMPORARYFILE | - | ||||||||||||
| 574 | // This #ifndef disables the workaround it encloses. Therefore, this configuration is not recommended. | - | ||||||||||||
| 575 | #ifdef Q_OS_LINUX | - | ||||||||||||
| 576 | // rename() on Linux simply does nothing when renaming "foo" to "Foo" on a case-insensitive | - | ||||||||||||
| 577 | // FS, such as FAT32. Move the file away and rename in 2 steps to work around. | - | ||||||||||||
| 578 | QTemporaryFile tempFile(d->fileName + QStringLiteral(".XXXXXX")); never executed: return qstring_literal_temp; | 0 | ||||||||||||
| 579 | tempFile.setAutoRemove(false); | - | ||||||||||||
| 580 | if (!tempFile.open(QIODevice::ReadWrite)) {
| 0 | ||||||||||||
| 581 | d->setError(QFile::RenameError, tempFile.errorString()); | - | ||||||||||||
| 582 | return false; never executed: return false; | 0 | ||||||||||||
| 583 | } | - | ||||||||||||
| 584 | tempFile.close(); | - | ||||||||||||
| 585 | if (!d->engine()->rename(tempFile.fileName())) {
| 0 | ||||||||||||
| 586 | d->setError(QFile::RenameError, tr("Error while renaming.")); | - | ||||||||||||
| 587 | return false; never executed: return false; | 0 | ||||||||||||
| 588 | } | - | ||||||||||||
| 589 | if (tempFile.rename(newName)) {
| 0 | ||||||||||||
| 590 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 591 | d->fileName = newName; | - | ||||||||||||
| 592 | return true; never executed: return true; | 0 | ||||||||||||
| 593 | } | - | ||||||||||||
| 594 | d->setError(QFile::RenameError, tempFile.errorString()); | - | ||||||||||||
| 595 | // We need to restore the original file. | - | ||||||||||||
| 596 | if (!tempFile.rename(d->fileName)) {
| 0 | ||||||||||||
| 597 | d->setError(QFile::RenameError, errorString() + QLatin1Char('\n') | - | ||||||||||||
| 598 | + tr("Unable to restore from %1: %2"). | - | ||||||||||||
| 599 | arg(QDir::toNativeSeparators(tempFile.fileName()), tempFile.errorString())); | - | ||||||||||||
| 600 | } never executed: end of block | 0 | ||||||||||||
| 601 | return false; never executed: return false; | 0 | ||||||||||||
| 602 | #endif // Q_OS_LINUX | - | ||||||||||||
| 603 | #endif // QT_NO_TEMPORARYFILE | - | ||||||||||||
| 604 | } | - | ||||||||||||
| 605 | unsetError(); | - | ||||||||||||
| 606 | close(); | - | ||||||||||||
| 607 | if(error() == QFile::NoError) {
| 0-250 | ||||||||||||
| 608 | if (d->engine()->rename(newName)) {
| 4-246 | ||||||||||||
| 609 | unsetError(); | - | ||||||||||||
| 610 | // engine was able to handle the new name so we just reset it | - | ||||||||||||
| 611 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 612 | d->fileName = newName; | - | ||||||||||||
| 613 | return true; executed 246 times by 13 tests: return true;Executed by:
| 246 | ||||||||||||
| 614 | } | - | ||||||||||||
| 615 | - | |||||||||||||
| 616 | if (isSequential()) {
| 0-4 | ||||||||||||
| 617 | d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy")); | - | ||||||||||||
| 618 | return false; never executed: return false; | 0 | ||||||||||||
| 619 | } | - | ||||||||||||
| 620 | - | |||||||||||||
| 621 | QFile out(newName); | - | ||||||||||||
| 622 | if (open(QIODevice::ReadOnly)) {
| 0-4 | ||||||||||||
| 623 | if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
| 1-3 | ||||||||||||
| 624 | bool error = false; | - | ||||||||||||
| 625 | char block[4096]; | - | ||||||||||||
| 626 | qint64 bytes; | - | ||||||||||||
| 627 | while ((bytes = read(block, sizeof(block))) > 0) {
| 1 | ||||||||||||
| 628 | if (bytes != out.write(block, bytes)) {
| 0-1 | ||||||||||||
| 629 | d->setError(QFile::RenameError, out.errorString()); | - | ||||||||||||
| 630 | error = true; | - | ||||||||||||
| 631 | break; never executed: break; | 0 | ||||||||||||
| 632 | } | - | ||||||||||||
| 633 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 634 | if (bytes == -1) {
| 0-1 | ||||||||||||
| 635 | d->setError(QFile::RenameError, errorString()); | - | ||||||||||||
| 636 | error = true; | - | ||||||||||||
| 637 | } never executed: end of block | 0 | ||||||||||||
| 638 | if(!error) {
| 0-1 | ||||||||||||
| 639 | if (!remove()) {
| 0-1 | ||||||||||||
| 640 | d->setError(QFile::RenameError, tr("Cannot remove source file")); | - | ||||||||||||
| 641 | error = true; | - | ||||||||||||
| 642 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 643 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 644 | if (error) {
| 0-1 | ||||||||||||
| 645 | out.remove(); | - | ||||||||||||
| 646 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 647 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 648 | setPermissions(permissions()); | - | ||||||||||||
| 649 | unsetError(); | - | ||||||||||||
| 650 | setFileName(newName); | - | ||||||||||||
| 651 | } never executed: end of block | 0 | ||||||||||||
| 652 | close(); | - | ||||||||||||
| 653 | return !error; executed 1 time by 1 test: return !error;Executed by:
| 1 | ||||||||||||
| 654 | } | - | ||||||||||||
| 655 | close(); | - | ||||||||||||
| 656 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||
| 657 | d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString()); | - | ||||||||||||
| 658 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||
| 659 | return false; executed 3 times by 3 tests: return false;Executed by:
| 3 | ||||||||||||
| 660 | } | - | ||||||||||||
| 661 | - | |||||||||||||
| 662 | /*! | - | ||||||||||||
| 663 | \overload | - | ||||||||||||
| 664 | - | |||||||||||||
| 665 | Renames the file \a oldName to \a newName. Returns \c true if | - | ||||||||||||
| 666 | successful; otherwise returns \c false. | - | ||||||||||||
| 667 | - | |||||||||||||
| 668 | If a file with the name \a newName already exists, rename() returns \c false | - | ||||||||||||
| 669 | (i.e., QFile will not overwrite it). | - | ||||||||||||
| 670 | - | |||||||||||||
| 671 | \sa rename() | - | ||||||||||||
| 672 | */ | - | ||||||||||||
| 673 | - | |||||||||||||
| 674 | bool | - | ||||||||||||
| 675 | QFile::rename(const QString &oldName, const QString &newName) | - | ||||||||||||
| 676 | { | - | ||||||||||||
| 677 | return QFile(oldName).rename(newName); executed 8 times by 3 tests: return QFile(oldName).rename(newName);Executed by:
| 8 | ||||||||||||
| 678 | } | - | ||||||||||||
| 679 | - | |||||||||||||
| 680 | /*! | - | ||||||||||||
| 681 | - | |||||||||||||
| 682 | Creates a link named \a linkName that points to the file currently specified by | - | ||||||||||||
| 683 | fileName(). What a link is depends on the underlying filesystem (be it a | - | ||||||||||||
| 684 | shortcut on Windows or a symbolic link on Unix). Returns \c true if successful; | - | ||||||||||||
| 685 | otherwise returns \c false. | - | ||||||||||||
| 686 | - | |||||||||||||
| 687 | This function will not overwrite an already existing entity in the file system; | - | ||||||||||||
| 688 | in this case, \c link() will return false and set \l{QFile::}{error()} to | - | ||||||||||||
| 689 | return \l{QFile::}{RenameError}. | - | ||||||||||||
| 690 | - | |||||||||||||
| 691 | \note To create a valid link on Windows, \a linkName must have a \c{.lnk} file extension. | - | ||||||||||||
| 692 | - | |||||||||||||
| 693 | \sa setFileName() | - | ||||||||||||
| 694 | */ | - | ||||||||||||
| 695 | - | |||||||||||||
| 696 | bool | - | ||||||||||||
| 697 | QFile::link(const QString &linkName) | - | ||||||||||||
| 698 | { | - | ||||||||||||
| 699 | Q_D(QFile); | - | ||||||||||||
| 700 | if (d->fileName.isEmpty()) {
| 0-161 | ||||||||||||
| 701 | qWarning("QFile::link: Empty or null file name"); | - | ||||||||||||
| 702 | return false; never executed: return false; | 0 | ||||||||||||
| 703 | } | - | ||||||||||||
| 704 | QFileInfo fi(linkName); | - | ||||||||||||
| 705 | if (d->engine()->link(fi.absoluteFilePath())) {
| 0-161 | ||||||||||||
| 706 | unsetError(); | - | ||||||||||||
| 707 | return true; executed 161 times by 8 tests: return true;Executed by:
| 161 | ||||||||||||
| 708 | } | - | ||||||||||||
| 709 | d->setError(QFile::RenameError, d->fileEngine->errorString()); | - | ||||||||||||
| 710 | return false; never executed: return false; | 0 | ||||||||||||
| 711 | } | - | ||||||||||||
| 712 | - | |||||||||||||
| 713 | /*! | - | ||||||||||||
| 714 | \overload | - | ||||||||||||
| 715 | - | |||||||||||||
| 716 | Creates a link named \a linkName that points to the file \a fileName. What a link is | - | ||||||||||||
| 717 | depends on the underlying filesystem (be it a shortcut on Windows | - | ||||||||||||
| 718 | or a symbolic link on Unix). Returns \c true if successful; otherwise | - | ||||||||||||
| 719 | returns \c false. | - | ||||||||||||
| 720 | - | |||||||||||||
| 721 | \sa link() | - | ||||||||||||
| 722 | */ | - | ||||||||||||
| 723 | - | |||||||||||||
| 724 | bool | - | ||||||||||||
| 725 | QFile::link(const QString &fileName, const QString &linkName) | - | ||||||||||||
| 726 | { | - | ||||||||||||
| 727 | return QFile(fileName).link(linkName); executed 151 times by 5 tests: return QFile(fileName).link(linkName);Executed by:
| 151 | ||||||||||||
| 728 | } | - | ||||||||||||
| 729 | - | |||||||||||||
| 730 | /*! | - | ||||||||||||
| 731 | Copies the file currently specified by fileName() to a file called | - | ||||||||||||
| 732 | \a newName. Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||
| 733 | - | |||||||||||||
| 734 | Note that if a file with the name \a newName already exists, | - | ||||||||||||
| 735 | copy() returns \c false (i.e. QFile will not overwrite it). | - | ||||||||||||
| 736 | - | |||||||||||||
| 737 | The source file is closed before it is copied. | - | ||||||||||||
| 738 | - | |||||||||||||
| 739 | \sa setFileName() | - | ||||||||||||
| 740 | */ | - | ||||||||||||
| 741 | - | |||||||||||||
| 742 | bool | - | ||||||||||||
| 743 | QFile::copy(const QString &newName) | - | ||||||||||||
| 744 | { | - | ||||||||||||
| 745 | Q_D(QFile); | - | ||||||||||||
| 746 | if (d->fileName.isEmpty()) {
| 0-135 | ||||||||||||
| 747 | qWarning("QFile::copy: Empty or null file name"); | - | ||||||||||||
| 748 | return false; never executed: return false; | 0 | ||||||||||||
| 749 | } | - | ||||||||||||
| 750 | if (QFile::exists(newName)) {
| 3-132 | ||||||||||||
| 751 | // ### Race condition. If a file is moved in after this, it /will/ be | - | ||||||||||||
| 752 | // overwritten. On Unix, the proper solution is to use hardlinks: | - | ||||||||||||
| 753 | // return ::link(old, new) && ::remove(old); See also rename(). | - | ||||||||||||
| 754 | d->setError(QFile::CopyError, tr("Destination file exists")); | - | ||||||||||||
| 755 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||
| 756 | } | - | ||||||||||||
| 757 | unsetError(); | - | ||||||||||||
| 758 | close(); | - | ||||||||||||
| 759 | if(error() == QFile::NoError) {
| 0-132 | ||||||||||||
| 760 | if (d->engine()->copy(newName)) {
| 0-132 | ||||||||||||
| 761 | unsetError(); | - | ||||||||||||
| 762 | return true; never executed: return true; | 0 | ||||||||||||
| 763 | } else { | - | ||||||||||||
| 764 | bool error = false; | - | ||||||||||||
| 765 | if(!open(QFile::ReadOnly)) {
| 1-131 | ||||||||||||
| 766 | error = true; | - | ||||||||||||
| 767 | d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName)); | - | ||||||||||||
| 768 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 769 | QString fileTemplate = QLatin1String("%1/qt_temp.XXXXXX"); | - | ||||||||||||
| 770 | #ifdef QT_NO_TEMPORARYFILE | - | ||||||||||||
| 771 | QFile out(fileTemplate.arg(QFileInfo(newName).path())); | - | ||||||||||||
| 772 | if (!out.open(QIODevice::ReadWrite)) | - | ||||||||||||
| 773 | error = true; | - | ||||||||||||
| 774 | #else | - | ||||||||||||
| 775 | QTemporaryFile out(fileTemplate.arg(QFileInfo(newName).path())); | - | ||||||||||||
| 776 | if (!out.open()) {
| 0-131 | ||||||||||||
| 777 | out.setFileTemplate(fileTemplate.arg(QDir::tempPath())); | - | ||||||||||||
| 778 | if (!out.open())
| 0 | ||||||||||||
| 779 | error = true; never executed: error = true; | 0 | ||||||||||||
| 780 | } never executed: end of block | 0 | ||||||||||||
| 781 | #endif | - | ||||||||||||
| 782 | if (error) {
| 0-131 | ||||||||||||
| 783 | out.close(); | - | ||||||||||||
| 784 | close(); | - | ||||||||||||
| 785 | d->setError(QFile::CopyError, tr("Cannot open for output")); | - | ||||||||||||
| 786 | } else { never executed: end of block | 0 | ||||||||||||
| 787 | char block[4096]; | - | ||||||||||||
| 788 | qint64 totalRead = 0; | - | ||||||||||||
| 789 | while(!atEnd()) {
| 131-1269 | ||||||||||||
| 790 | qint64 in = read(block, sizeof(block)); | - | ||||||||||||
| 791 | if (in <= 0)
| 0-1269 | ||||||||||||
| 792 | break; never executed: break; | 0 | ||||||||||||
| 793 | totalRead += in; | - | ||||||||||||
| 794 | if(in != out.write(block, in)) {
| 0-1269 | ||||||||||||
| 795 | close(); | - | ||||||||||||
| 796 | d->setError(QFile::CopyError, tr("Failure to write block")); | - | ||||||||||||
| 797 | error = true; | - | ||||||||||||
| 798 | break; never executed: break; | 0 | ||||||||||||
| 799 | } | - | ||||||||||||
| 800 | } executed 1269 times by 4 tests: end of blockExecuted by:
| 1269 | ||||||||||||
| 801 | - | |||||||||||||
| 802 | if (totalRead != size()) {
| 0-131 | ||||||||||||
| 803 | // Unable to read from the source. The error string is | - | ||||||||||||
| 804 | // already set from read(). | - | ||||||||||||
| 805 | error = true; | - | ||||||||||||
| 806 | } never executed: end of block | 0 | ||||||||||||
| 807 | if (!error && !out.rename(newName)) {
| 0-131 | ||||||||||||
| 808 | error = true; | - | ||||||||||||
| 809 | close(); | - | ||||||||||||
| 810 | d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName)); | - | ||||||||||||
| 811 | } never executed: end of block | 0 | ||||||||||||
| 812 | #ifdef QT_NO_TEMPORARYFILE | - | ||||||||||||
| 813 | if (error) | - | ||||||||||||
| 814 | out.remove(); | - | ||||||||||||
| 815 | #else | - | ||||||||||||
| 816 | if (!error)
| 0-131 | ||||||||||||
| 817 | out.setAutoRemove(false); executed 131 times by 4 tests: out.setAutoRemove(false);Executed by:
| 131 | ||||||||||||
| 818 | #endif | - | ||||||||||||
| 819 | } executed 131 times by 4 tests: end of blockExecuted by:
| 131 | ||||||||||||
| 820 | } | - | ||||||||||||
| 821 | if(!error) {
| 1-131 | ||||||||||||
| 822 | QFile::setPermissions(newName, permissions()); | - | ||||||||||||
| 823 | close(); | - | ||||||||||||
| 824 | unsetError(); | - | ||||||||||||
| 825 | return true; executed 131 times by 4 tests: return true;Executed by:
| 131 | ||||||||||||
| 826 | } | - | ||||||||||||
| 827 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 828 | } | - | ||||||||||||
| 829 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 830 | } | - | ||||||||||||
| 831 | - | |||||||||||||
| 832 | /*! | - | ||||||||||||
| 833 | \overload | - | ||||||||||||
| 834 | - | |||||||||||||
| 835 | Copies the file \a fileName to \a newName. Returns \c true if successful; | - | ||||||||||||
| 836 | otherwise returns \c false. | - | ||||||||||||
| 837 | - | |||||||||||||
| 838 | If a file with the name \a newName already exists, copy() returns \c false | - | ||||||||||||
| 839 | (i.e., QFile will not overwrite it). | - | ||||||||||||
| 840 | - | |||||||||||||
| 841 | \sa rename() | - | ||||||||||||
| 842 | */ | - | ||||||||||||
| 843 | - | |||||||||||||
| 844 | bool | - | ||||||||||||
| 845 | QFile::copy(const QString &fileName, const QString &newName) | - | ||||||||||||
| 846 | { | - | ||||||||||||
| 847 | return QFile(fileName).copy(newName); executed 101 times by 3 tests: return QFile(fileName).copy(newName);Executed by:
| 101 | ||||||||||||
| 848 | } | - | ||||||||||||
| 849 | - | |||||||||||||
| 850 | /*! | - | ||||||||||||
| 851 | Opens the file using OpenMode \a mode, returning true if successful; | - | ||||||||||||
| 852 | otherwise false. | - | ||||||||||||
| 853 | - | |||||||||||||
| 854 | The \a mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or | - | ||||||||||||
| 855 | QIODevice::ReadWrite. It may also have additional flags, such as | - | ||||||||||||
| 856 | QIODevice::Text and QIODevice::Unbuffered. | - | ||||||||||||
| 857 | - | |||||||||||||
| 858 | \note In \l{QIODevice::}{WriteOnly} or \l{QIODevice::}{ReadWrite} | - | ||||||||||||
| 859 | mode, if the relevant file does not already exist, this function | - | ||||||||||||
| 860 | will try to create a new file before opening it. | - | ||||||||||||
| 861 | - | |||||||||||||
| 862 | \sa QIODevice::OpenMode, setFileName() | - | ||||||||||||
| 863 | */ | - | ||||||||||||
| 864 | bool QFile::open(OpenMode mode) | - | ||||||||||||
| 865 | { | - | ||||||||||||
| 866 | Q_D(QFile); | - | ||||||||||||
| 867 | if (isOpen()) {
| 0-43318 | ||||||||||||
| 868 | qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); | - | ||||||||||||
| 869 | return false; never executed: return false; | 0 | ||||||||||||
| 870 | } | - | ||||||||||||
| 871 | if (mode & Append)
| 259-43059 | ||||||||||||
| 872 | mode |= WriteOnly; executed 259 times by 6 tests: mode |= WriteOnly;Executed by:
| 259 | ||||||||||||
| 873 | - | |||||||||||||
| 874 | unsetError(); | - | ||||||||||||
| 875 | if ((mode & (ReadOnly | WriteOnly)) == 0) {
| 0-43318 | ||||||||||||
| 876 | qWarning("QIODevice::open: File access not specified"); | - | ||||||||||||
| 877 | return false; never executed: return false; | 0 | ||||||||||||
| 878 | } | - | ||||||||||||
| 879 | - | |||||||||||||
| 880 | // QIODevice provides the buffering, so there's no need to request it from the file engine. | - | ||||||||||||
| 881 | if (d->engine()->open(mode | QIODevice::Unbuffered)) {
| 3495-39823 | ||||||||||||
| 882 | QIODevice::open(mode); | - | ||||||||||||
| 883 | if (mode & Append)
| 258-39565 | ||||||||||||
| 884 | seek(size()); executed 258 times by 6 tests: seek(size());Executed by:
| 258 | ||||||||||||
| 885 | return true; executed 39823 times by 175 tests: return true;Executed by:
| 39823 | ||||||||||||
| 886 | } | - | ||||||||||||
| 887 | QFile::FileError err = d->fileEngine->error(); | - | ||||||||||||
| 888 | if(err == QFile::UnspecifiedError)
| 215-3280 | ||||||||||||
| 889 | err = QFile::OpenError; executed 215 times by 8 tests: err = QFile::OpenError;Executed by:
| 215 | ||||||||||||
| 890 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||
| 891 | return false; executed 3495 times by 52 tests: return false;Executed by:
| 3495 | ||||||||||||
| 892 | } | - | ||||||||||||
| 893 | - | |||||||||||||
| 894 | /*! | - | ||||||||||||
| 895 | \overload | - | ||||||||||||
| 896 | - | |||||||||||||
| 897 | Opens the existing file handle \a fh in the given \a mode. | - | ||||||||||||
| 898 | \a handleFlags may be used to specify additional options. | - | ||||||||||||
| 899 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||
| 900 | - | |||||||||||||
| 901 | Example: | - | ||||||||||||
| 902 | \snippet code/src_corelib_io_qfile.cpp 3 | - | ||||||||||||
| 903 | - | |||||||||||||
| 904 | When a QFile is opened using this function, behaviour of close() is | - | ||||||||||||
| 905 | controlled by the AutoCloseHandle flag. | - | ||||||||||||
| 906 | If AutoCloseHandle is specified, and this function succeeds, | - | ||||||||||||
| 907 | then calling close() closes the adopted handle. | - | ||||||||||||
| 908 | Otherwise, close() does not actually close the file, but only flushes it. | - | ||||||||||||
| 909 | - | |||||||||||||
| 910 | \b{Warning:} | - | ||||||||||||
| 911 | \list 1 | - | ||||||||||||
| 912 | \li If \a fh does not refer to a regular file, e.g., it is \c stdin, | - | ||||||||||||
| 913 | \c stdout, or \c stderr, you may not be able to seek(). size() | - | ||||||||||||
| 914 | returns \c 0 in those cases. See QIODevice::isSequential() for | - | ||||||||||||
| 915 | more information. | - | ||||||||||||
| 916 | \li Since this function opens the file without specifying the file name, | - | ||||||||||||
| 917 | you cannot use this QFile with a QFileInfo. | - | ||||||||||||
| 918 | \endlist | - | ||||||||||||
| 919 | - | |||||||||||||
| 920 | \note For Windows CE you may not be able to call resize(). | - | ||||||||||||
| 921 | - | |||||||||||||
| 922 | \sa close() | - | ||||||||||||
| 923 | - | |||||||||||||
| 924 | \b{Note for the Windows Platform} | - | ||||||||||||
| 925 | - | |||||||||||||
| 926 | \a fh must be opened in binary mode (i.e., the mode string must contain | - | ||||||||||||
| 927 | 'b', as in "rb" or "wb") when accessing files and other random-access | - | ||||||||||||
| 928 | devices. Qt will translate the end-of-line characters if you pass | - | ||||||||||||
| 929 | QIODevice::Text to \a mode. Sequential devices, such as stdin and stdout, | - | ||||||||||||
| 930 | are unaffected by this limitation. | - | ||||||||||||
| 931 | - | |||||||||||||
| 932 | You need to enable support for console applications in order to use the | - | ||||||||||||
| 933 | stdin, stdout and stderr streams at the console. To do this, add the | - | ||||||||||||
| 934 | following declaration to your application's project file: | - | ||||||||||||
| 935 | - | |||||||||||||
| 936 | \snippet code/src_corelib_io_qfile.cpp 4 | - | ||||||||||||
| 937 | */ | - | ||||||||||||
| 938 | bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) | - | ||||||||||||
| 939 | { | - | ||||||||||||
| 940 | Q_D(QFile); | - | ||||||||||||
| 941 | if (isOpen()) {
| 0-364 | ||||||||||||
| 942 | qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); | - | ||||||||||||
| 943 | return false; never executed: return false; | 0 | ||||||||||||
| 944 | } | - | ||||||||||||
| 945 | if (mode & Append)
| 0-364 | ||||||||||||
| 946 | mode |= WriteOnly; never executed: mode |= WriteOnly; | 0 | ||||||||||||
| 947 | unsetError(); | - | ||||||||||||
| 948 | if ((mode & (ReadOnly | WriteOnly)) == 0) {
| 0-364 | ||||||||||||
| 949 | qWarning("QFile::open: File access not specified"); | - | ||||||||||||
| 950 | return false; never executed: return false; | 0 | ||||||||||||
| 951 | } | - | ||||||||||||
| 952 | if (d->openExternalFile(mode, fh, handleFlags)) {
| 0-364 | ||||||||||||
| 953 | QIODevice::open(mode); | - | ||||||||||||
| 954 | if (!(mode & Append) && !isSequential()) {
| 0-364 | ||||||||||||
| 955 | qint64 pos = (qint64)QT_FTELL(fh); | - | ||||||||||||
| 956 | if (pos != -1) {
| 0-27 | ||||||||||||
| 957 | // Skip redundant checks in QFileDevice::seek(). | - | ||||||||||||
| 958 | QIODevice::seek(pos); | - | ||||||||||||
| 959 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||
| 960 | } executed 27 times by 2 tests: end of blockExecuted by:
| 27 | ||||||||||||
| 961 | return true; executed 364 times by 5 tests: return true;Executed by:
| 364 | ||||||||||||
| 962 | } | - | ||||||||||||
| 963 | return false; never executed: return false; | 0 | ||||||||||||
| 964 | } | - | ||||||||||||
| 965 | - | |||||||||||||
| 966 | /*! | - | ||||||||||||
| 967 | \overload | - | ||||||||||||
| 968 | - | |||||||||||||
| 969 | Opens the existing file descriptor \a fd in the given \a mode. | - | ||||||||||||
| 970 | \a handleFlags may be used to specify additional options. | - | ||||||||||||
| 971 | Returns \c true if successful; otherwise returns \c false. | - | ||||||||||||
| 972 | - | |||||||||||||
| 973 | When a QFile is opened using this function, behaviour of close() is | - | ||||||||||||
| 974 | controlled by the AutoCloseHandle flag. | - | ||||||||||||
| 975 | If AutoCloseHandle is specified, and this function succeeds, | - | ||||||||||||
| 976 | then calling close() closes the adopted handle. | - | ||||||||||||
| 977 | Otherwise, close() does not actually close the file, but only flushes it. | - | ||||||||||||
| 978 | - | |||||||||||||
| 979 | The QFile that is opened using this function is automatically set | - | ||||||||||||
| 980 | to be in raw mode; this means that the file input/output functions | - | ||||||||||||
| 981 | are slow. If you run into performance issues, you should try to | - | ||||||||||||
| 982 | use one of the other open functions. | - | ||||||||||||
| 983 | - | |||||||||||||
| 984 | \warning If \a fd is not a regular file, e.g, it is 0 (\c stdin), | - | ||||||||||||
| 985 | 1 (\c stdout), or 2 (\c stderr), you may not be able to seek(). In | - | ||||||||||||
| 986 | those cases, size() returns \c 0. See QIODevice::isSequential() | - | ||||||||||||
| 987 | for more information. | - | ||||||||||||
| 988 | - | |||||||||||||
| 989 | \warning For Windows CE you may not be able to call seek(), and size() | - | ||||||||||||
| 990 | returns \c 0. | - | ||||||||||||
| 991 | - | |||||||||||||
| 992 | \warning Since this function opens the file without specifying the file name, | - | ||||||||||||
| 993 | you cannot use this QFile with a QFileInfo. | - | ||||||||||||
| 994 | - | |||||||||||||
| 995 | \sa close() | - | ||||||||||||
| 996 | */ | - | ||||||||||||
| 997 | bool QFile::open(int fd, OpenMode mode, FileHandleFlags handleFlags) | - | ||||||||||||
| 998 | { | - | ||||||||||||
| 999 | Q_D(QFile); | - | ||||||||||||
| 1000 | if (isOpen()) {
| 0-29 | ||||||||||||
| 1001 | qWarning("QFile::open: File (%s) already open", qPrintable(fileName())); | - | ||||||||||||
| 1002 | return false; never executed: return false; | 0 | ||||||||||||
| 1003 | } | - | ||||||||||||
| 1004 | if (mode & Append)
| 0-29 | ||||||||||||
| 1005 | mode |= WriteOnly; never executed: mode |= WriteOnly; | 0 | ||||||||||||
| 1006 | unsetError(); | - | ||||||||||||
| 1007 | if ((mode & (ReadOnly | WriteOnly)) == 0) {
| 0-29 | ||||||||||||
| 1008 | qWarning("QFile::open: File access not specified"); | - | ||||||||||||
| 1009 | return false; never executed: return false; | 0 | ||||||||||||
| 1010 | } | - | ||||||||||||
| 1011 | if (d->openExternalFile(mode, fd, handleFlags)) {
| 0-29 | ||||||||||||
| 1012 | QIODevice::open(mode); | - | ||||||||||||
| 1013 | if (!(mode & Append) && !isSequential()) {
| 0-29 | ||||||||||||
| 1014 | qint64 pos = (qint64)QT_LSEEK(fd, QT_OFF_T(0), SEEK_CUR); | - | ||||||||||||
| 1015 | if (pos != -1) {
| 0-24 | ||||||||||||
| 1016 | // Skip redundant checks in QFileDevice::seek(). | - | ||||||||||||
| 1017 | QIODevice::seek(pos); | - | ||||||||||||
| 1018 | } executed 24 times by 2 tests: end of blockExecuted by:
| 24 | ||||||||||||
| 1019 | } executed 24 times by 2 tests: end of blockExecuted by:
| 24 | ||||||||||||
| 1020 | return true; executed 29 times by 3 tests: return true;Executed by:
| 29 | ||||||||||||
| 1021 | } | - | ||||||||||||
| 1022 | return false; never executed: return false; | 0 | ||||||||||||
| 1023 | } | - | ||||||||||||
| 1024 | - | |||||||||||||
| 1025 | /*! | - | ||||||||||||
| 1026 | \reimp | - | ||||||||||||
| 1027 | */ | - | ||||||||||||
| 1028 | bool QFile::resize(qint64 sz) | - | ||||||||||||
| 1029 | { | - | ||||||||||||
| 1030 | return QFileDevice::resize(sz); // for now executed 295 times by 7 tests: return QFileDevice::resize(sz);Executed by:
| 295 | ||||||||||||
| 1031 | } | - | ||||||||||||
| 1032 | - | |||||||||||||
| 1033 | /*! | - | ||||||||||||
| 1034 | \overload | - | ||||||||||||
| 1035 | - | |||||||||||||
| 1036 | Sets \a fileName to size (in bytes) \a sz. Returns \c true if the file if | - | ||||||||||||
| 1037 | the resize succeeds; false otherwise. If \a sz is larger than \a | - | ||||||||||||
| 1038 | fileName currently is the new bytes will be set to 0, if \a sz is | - | ||||||||||||
| 1039 | smaller the file is simply truncated. | - | ||||||||||||
| 1040 | - | |||||||||||||
| 1041 | \sa resize() | - | ||||||||||||
| 1042 | */ | - | ||||||||||||
| 1043 | - | |||||||||||||
| 1044 | bool | - | ||||||||||||
| 1045 | QFile::resize(const QString &fileName, qint64 sz) | - | ||||||||||||
| 1046 | { | - | ||||||||||||
| 1047 | return QFile(fileName).resize(sz); executed 3 times by 1 test: return QFile(fileName).resize(sz);Executed by:
| 3 | ||||||||||||
| 1048 | } | - | ||||||||||||
| 1049 | - | |||||||||||||
| 1050 | /*! | - | ||||||||||||
| 1051 | \reimp | - | ||||||||||||
| 1052 | */ | - | ||||||||||||
| 1053 | QFile::Permissions QFile::permissions() const | - | ||||||||||||
| 1054 | { | - | ||||||||||||
| 1055 | return QFileDevice::permissions(); // for now executed 198 times by 11 tests: return QFileDevice::permissions();Executed by:
| 198 | ||||||||||||
| 1056 | } | - | ||||||||||||
| 1057 | - | |||||||||||||
| 1058 | /*! | - | ||||||||||||
| 1059 | \overload | - | ||||||||||||
| 1060 | - | |||||||||||||
| 1061 | Returns the complete OR-ed together combination of | - | ||||||||||||
| 1062 | QFile::Permission for \a fileName. | - | ||||||||||||
| 1063 | */ | - | ||||||||||||
| 1064 | - | |||||||||||||
| 1065 | QFile::Permissions | - | ||||||||||||
| 1066 | QFile::permissions(const QString &fileName) | - | ||||||||||||
| 1067 | { | - | ||||||||||||
| 1068 | return QFile(fileName).permissions(); executed 11 times by 3 tests: return QFile(fileName).permissions();Executed by:
| 11 | ||||||||||||
| 1069 | } | - | ||||||||||||
| 1070 | - | |||||||||||||
| 1071 | /*! | - | ||||||||||||
| 1072 | Sets the permissions for the file to the \a permissions specified. | - | ||||||||||||
| 1073 | Returns \c true if successful, or \c false if the permissions cannot be | - | ||||||||||||
| 1074 | modified. | - | ||||||||||||
| 1075 | - | |||||||||||||
| 1076 | \warning This function does not manipulate ACLs, which may limit its | - | ||||||||||||
| 1077 | effectiveness. | - | ||||||||||||
| 1078 | - | |||||||||||||
| 1079 | \sa permissions(), setFileName() | - | ||||||||||||
| 1080 | */ | - | ||||||||||||
| 1081 | - | |||||||||||||
| 1082 | bool QFile::setPermissions(Permissions permissions) | - | ||||||||||||
| 1083 | { | - | ||||||||||||
| 1084 | return QFileDevice::setPermissions(permissions); // for now executed 620 times by 16 tests: return QFileDevice::setPermissions(permissions);Executed by:
| 620 | ||||||||||||
| 1085 | } | - | ||||||||||||
| 1086 | - | |||||||||||||
| 1087 | /*! | - | ||||||||||||
| 1088 | \overload | - | ||||||||||||
| 1089 | - | |||||||||||||
| 1090 | Sets the permissions for \a fileName file to \a permissions. | - | ||||||||||||
| 1091 | */ | - | ||||||||||||
| 1092 | - | |||||||||||||
| 1093 | bool | - | ||||||||||||
| 1094 | QFile::setPermissions(const QString &fileName, Permissions permissions) | - | ||||||||||||
| 1095 | { | - | ||||||||||||
| 1096 | return QFile(fileName).setPermissions(permissions); executed 157 times by 5 tests: return QFile(fileName).setPermissions(permissions);Executed by:
| 157 | ||||||||||||
| 1097 | } | - | ||||||||||||
| 1098 | - | |||||||||||||
| 1099 | /*! | - | ||||||||||||
| 1100 | \reimp | - | ||||||||||||
| 1101 | */ | - | ||||||||||||
| 1102 | qint64 QFile::size() const | - | ||||||||||||
| 1103 | { | - | ||||||||||||
| 1104 | return QFileDevice::size(); // for now executed 164647 times by 162 tests: return QFileDevice::size();Executed by:
| 164647 | ||||||||||||
| 1105 | } | - | ||||||||||||
| 1106 | - | |||||||||||||
| 1107 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |