| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfile.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | QFilePrivate::QFilePrivate() | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | QFilePrivate::~QFilePrivate() | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | } | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | bool | - | ||||||||||||
| 20 | QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags) | - | ||||||||||||
| 21 | { | - | ||||||||||||
| 22 | - | |||||||||||||
| 23 | - | |||||||||||||
| 24 | - | |||||||||||||
| 25 | - | |||||||||||||
| 26 | - | |||||||||||||
| 27 | delete fileEngine; | - | ||||||||||||
| 28 | fileEngine = 0; | - | ||||||||||||
| 29 | QFSFileEngine *fe = new QFSFileEngine; | - | ||||||||||||
| 30 | fileEngine = fe; | - | ||||||||||||
| 31 | return fe->open(QIODevice::OpenMode(flags), fd, handleFlags); | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | } | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | bool | - | ||||||||||||
| 36 | QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags) | - | ||||||||||||
| 37 | { | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | - | |||||||||||||
| 40 | - | |||||||||||||
| 41 | - | |||||||||||||
| 42 | - | |||||||||||||
| 43 | delete fileEngine; | - | ||||||||||||
| 44 | fileEngine = 0; | - | ||||||||||||
| 45 | QFSFileEngine *fe = new QFSFileEngine; | - | ||||||||||||
| 46 | fileEngine = fe; | - | ||||||||||||
| 47 | return fe->open(QIODevice::OpenMode(flags), fh, handleFlags); | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | } | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | QAbstractFileEngine *QFilePrivate::engine() const | - | ||||||||||||
| 52 | { | - | ||||||||||||
| 53 | if (!fileEngine) | - | ||||||||||||
| 54 | fileEngine = QAbstractFileEngine::create(fileName); | - | ||||||||||||
| 55 | return fileEngine; | - | ||||||||||||
| 56 | } | - | ||||||||||||
| 57 | QFile::QFile() | - | ||||||||||||
| 58 | : QFileDevice(*new QFilePrivate, 0) | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | QFile::QFile(QObject *parent) | - | ||||||||||||
| 65 | : QFileDevice(*new QFilePrivate, parent) | - | ||||||||||||
| 66 | { | - | ||||||||||||
| 67 | } | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | - | |||||||||||||
| 70 | - | |||||||||||||
| 71 | QFile::QFile(const QString &name) | - | ||||||||||||
| 72 | : QFileDevice(*new QFilePrivate, 0) | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 75 | d->fileName = name; | - | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | - | |||||||||||||
| 79 | - | |||||||||||||
| 80 | - | |||||||||||||
| 81 | QFile::QFile(const QString &name, QObject *parent) | - | ||||||||||||
| 82 | : QFileDevice(*new QFilePrivate, parent) | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 85 | d->fileName = name; | - | ||||||||||||
| 86 | } | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | - | |||||||||||||
| 89 | - | |||||||||||||
| 90 | QFile::QFile(QFilePrivate &dd, QObject *parent) | - | ||||||||||||
| 91 | : QFileDevice(dd, parent) | - | ||||||||||||
| 92 | { | - | ||||||||||||
| 93 | } | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | - | |||||||||||||
| 96 | - | |||||||||||||
| 97 | - | |||||||||||||
| 98 | - | |||||||||||||
| 99 | QFile::~QFile() | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | } | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | - | |||||||||||||
| 104 | - | |||||||||||||
| 105 | - | |||||||||||||
| 106 | - | |||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | QString QFile::fileName() const | - | ||||||||||||
| 110 | { | - | ||||||||||||
| 111 | const QFilePrivate * const d = d_func(); | - | ||||||||||||
| 112 | return d->engine()->fileName(QAbstractFileEngine::DefaultName); | - | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | void | - | ||||||||||||
| 115 | QFile::setFileName(const QString &name) | - | ||||||||||||
| 116 | { | - | ||||||||||||
| 117 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 118 | if (isOpen()) { | - | ||||||||||||
| 119 | QMessageLogger(__FILE__, 318324, __PRETTY_FUNCTION__).warning("QFile::setFileName: File (%s) is already opened", | - | ||||||||||||
| 120 | QString(fileName()).toLocal8Bit().constData()); | - | ||||||||||||
| 121 | close(); | - | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | if(d->fileEngine) { | - | ||||||||||||
| 124 | delete d->fileEngine; | - | ||||||||||||
| 125 | d->fileEngine = 0; | - | ||||||||||||
| 126 | } | - | ||||||||||||
| 127 | d->fileName = name; | - | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | bool | - | ||||||||||||
| 130 | QFile::exists() const | - | ||||||||||||
| 131 | { | - | ||||||||||||
| 132 | const QFilePrivate * const d = d_func(); | - | ||||||||||||
| 133 | - | |||||||||||||
| 134 | return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | - | ||||||||||||
| 135 | | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag); | - | ||||||||||||
| 136 | } | - | ||||||||||||
| 137 | bool | - | ||||||||||||
| 138 | QFile::exists(const QString &fileName) | - | ||||||||||||
| 139 | { | - | ||||||||||||
| 140 | return QFileInfo::exists(fileName); | - | ||||||||||||
| 141 | } | - | ||||||||||||
| 142 | QString | - | ||||||||||||
| 143 | QFile::readLink() const | - | ||||||||||||
| 144 | { | - | ||||||||||||
| 145 | const QFilePrivate * const d = d_func(); | - | ||||||||||||
| 146 | return d->engine()->fileName(QAbstractFileEngine::LinkName); | - | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | QString | - | ||||||||||||
| 149 | QFile::readLink(const QString &fileName) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | return QFileInfo(fileName).readLink(); | - | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | bool | - | ||||||||||||
| 154 | QFile::remove() | - | ||||||||||||
| 155 | { | - | ||||||||||||
| 156 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 157 | if (d->fileName.isEmpty()) { | - | ||||||||||||
| 158 | QMessageLogger(__FILE__, 498504, __PRETTY_FUNCTION__).warning("QFile::remove: Empty or null file name"); | - | ||||||||||||
| 159 | return false; | - | ||||||||||||
| 160 | } | - | ||||||||||||
| 161 | unsetError(); | - | ||||||||||||
| 162 | close(); | - | ||||||||||||
| 163 | if(error() == QFile::NoError) { | - | ||||||||||||
| 164 | if (d->engine()->remove()) { | - | ||||||||||||
| 165 | unsetError(); | - | ||||||||||||
| 166 | return true; | - | ||||||||||||
| 167 | } | - | ||||||||||||
| 168 | d->setError(QFile::RemoveError, d->fileEngine->errorString()); | - | ||||||||||||
| 169 | } | - | ||||||||||||
| 170 | return false; | - | ||||||||||||
| 171 | } | - | ||||||||||||
| 172 | bool | - | ||||||||||||
| 173 | QFile::remove(const QString &fileName) | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | return QFile(fileName).remove(); | - | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | bool | - | ||||||||||||
| 178 | QFile::rename(const QString &newName) | - | ||||||||||||
| 179 | { | - | ||||||||||||
| 180 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 181 | if (d->fileName.isEmpty()
| 0-259 | ||||||||||||
| 182 | QMessageLogger(__FILE__, 551557, __PRETTY_FUNCTION__).warning("QFile::rename: Empty or null file name"); | - | ||||||||||||
| 183 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 184 | } | - | ||||||||||||
| 185 | if (d->fileName == newName
| 1-258 | ||||||||||||
| 186 | d->setError(QFile::RenameError, tr("Destination file is the same file.")); | - | ||||||||||||
| 187 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 188 | } | - | ||||||||||||
| 189 | if (!exists()
| 2-256 | ||||||||||||
| 190 | d->setError(QFile::RenameError, tr("Source file does not exist.")); | - | ||||||||||||
| 191 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | - | |||||||||||||
| 194 | - | |||||||||||||
| 195 | if (QFile::exists(newName)
| 4-252 | ||||||||||||
| 196 | if (d->fileName.compare(newName, Qt::CaseInsensitive)
| 0-4 | ||||||||||||
| 197 | || QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName))
| 0 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | - | |||||||||||||
| 200 | - | |||||||||||||
| 201 | d->setError(QFile::RenameError, tr("Destination file exists")); | - | ||||||||||||
| 202 | return executed 4 times by 1 test: false;return false;Executed by:
executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||
| 203 | } | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | - | |||||||||||||
| 206 | - | |||||||||||||
| 207 | - | |||||||||||||
| 208 | - | |||||||||||||
| 209 | QTemporaryFile tempFile(d->fileName + ([]() -> QString { enum { Size = sizeof(u"" ".XXXXXX")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeofQLatin1String(QStringData) }, u"" ".XXXXXX"}; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));)); | - | ||||||||||||
| 210 | tempFile.setAutoRemove(false); | - | ||||||||||||
| 211 | if (!tempFile.open(QIODevice::ReadWrite)
| 0 | ||||||||||||
| 212 | d->setError(QFile::RenameError, tempFile.errorString()); | - | ||||||||||||
| 213 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 214 | } | - | ||||||||||||
| 215 | tempFile.close(); | - | ||||||||||||
| 216 | if (!d->engine()->rename(tempFile.fileName())
| 0 | ||||||||||||
| 217 | d->setError(QFile::RenameError, tr("Error while renaming.")); | - | ||||||||||||
| 218 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | if (tempFile.rename(newName)
| 0 | ||||||||||||
| 221 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 222 | d->fileName = newName; | - | ||||||||||||
| 223 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | d->setError(QFile::RenameError, tempFile.errorString()); | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | if (!tempFile.rename(d->fileName)
| 0 | ||||||||||||
| 228 | d->setError(QFile::RenameError, errorString() + QLatin1Char('\n') | - | ||||||||||||
| 229 | + tr("Unable to restore from %1: %2"). | - | ||||||||||||
| 230 | arg(QDir::toNativeSeparators(tempFile.fileName()), tempFile.errorString())); | - | ||||||||||||
| 231 | } never executed: end of block | 0 | ||||||||||||
| 232 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | - | |||||||||||||
| 235 | } | - | ||||||||||||
| 236 | unsetError(); | - | ||||||||||||
| 237 | close(); | - | ||||||||||||
| 238 | if(error() == QFile::NoError
| 0-252 | ||||||||||||
| 239 | if (d->engine()->rename(newName)
| 4-248 | ||||||||||||
| 240 | unsetError(); | - | ||||||||||||
| 241 | - | |||||||||||||
| 242 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 243 | d->fileName = newName; | - | ||||||||||||
| 244 | return executed 248 times by 14 tests: true;return true;Executed by:
executed 248 times by 14 tests: return true;Executed by:
| 248 | ||||||||||||
| 245 | } | - | ||||||||||||
| 246 | - | |||||||||||||
| 247 | if (isSequential()
| 0-4 | ||||||||||||
| 248 | d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy")); | - | ||||||||||||
| 249 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | QFile out(newName); | - | ||||||||||||
| 253 | if (open(QIODevice::ReadOnly)
| 0-4 | ||||||||||||
| 254 | if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)
| 1-3 | ||||||||||||
| 255 | bool error = false; | - | ||||||||||||
| 256 | char block[4096]; | - | ||||||||||||
| 257 | qint64 bytes; | - | ||||||||||||
| 258 | while ((
| 1 | ||||||||||||
| 259 | if (bytes != out.write(block, bytes)
| 0-1 | ||||||||||||
| 260 | d->setError(QFile::RenameError, out.errorString()); | - | ||||||||||||
| 261 | error = true; | - | ||||||||||||
| 262 | break; never executed: break; | 0 | ||||||||||||
| 263 | } | - | ||||||||||||
| 264 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 265 | if (bytes == -1
| 0-1 | ||||||||||||
| 266 | d->setError(QFile::RenameError, errorString()); | - | ||||||||||||
| 267 | error = true; | - | ||||||||||||
| 268 | } never executed: end of block | 0 | ||||||||||||
| 269 | if(!error
| 0-1 | ||||||||||||
| 270 | if (!remove()
| 0-1 | ||||||||||||
| 271 | d->setError(QFile::RenameError, tr("Cannot remove source file")); | - | ||||||||||||
| 272 | error = true; | - | ||||||||||||
| 273 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 274 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 275 | if (error
| 0-1 | ||||||||||||
| 276 | out.remove(); | - | ||||||||||||
| 277 | } executed 1 time by 1 test: else {end of blockExecuted by:
| 1 | ||||||||||||
| 278 | d->fileEngine->setFileName(newName); | - | ||||||||||||
| 279 | setPermissions(permissions()); | - | ||||||||||||
| 280 | unsetError(); | - | ||||||||||||
| 281 | setFileName(newName); | - | ||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||
| 283 | close(); | - | ||||||||||||
| 284 | return executed 1 time by 1 test: !error;return !error;Executed by:
executed 1 time by 1 test: return !error;Executed by:
| 1 | ||||||||||||
| 285 | } | - | ||||||||||||
| 286 | close(); | - | ||||||||||||
| 287 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||
| 288 | d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString()); | - | ||||||||||||
| 289 | } executed 3 times by 3 tests: end of blockExecuted by:
| 3 | ||||||||||||
| 290 | return executed 3 times by 3 tests: false;return false;Executed by:
executed 3 times by 3 tests: return false;Executed by:
| 3 | ||||||||||||
| 291 | } | - | ||||||||||||
| 292 | bool | - | ||||||||||||
| 293 | QFile::rename(const QString &oldName, const QString &newName) | - | ||||||||||||
| 294 | { | - | ||||||||||||
| 295 | return QFile(oldName).rename(newName); | - | ||||||||||||
| 296 | } | - | ||||||||||||
| 297 | bool | - | ||||||||||||
| 298 | QFile::link(const QString &linkName) | - | ||||||||||||
| 299 | { | - | ||||||||||||
| 300 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 301 | if (d->fileName.isEmpty()) { | - | ||||||||||||
| 302 | QMessageLogger(__FILE__, 701707, __PRETTY_FUNCTION__).warning("QFile::link: Empty or null file name"); | - | ||||||||||||
| 303 | return false; | - | ||||||||||||
| 304 | } | - | ||||||||||||
| 305 | QFileInfo fi(linkName); | - | ||||||||||||
| 306 | if (d->engine()->link(fi.absoluteFilePath())) { | - | ||||||||||||
| 307 | unsetError(); | - | ||||||||||||
| 308 | return true; | - | ||||||||||||
| 309 | } | - | ||||||||||||
| 310 | d->setError(QFile::RenameError, d->fileEngine->errorString()); | - | ||||||||||||
| 311 | return false; | - | ||||||||||||
| 312 | } | - | ||||||||||||
| 313 | bool | - | ||||||||||||
| 314 | QFile::link(const QString &fileName, const QString &linkName) | - | ||||||||||||
| 315 | { | - | ||||||||||||
| 316 | return QFile(fileName).link(linkName); | - | ||||||||||||
| 317 | } | - | ||||||||||||
| 318 | bool | - | ||||||||||||
| 319 | QFile::copy(const QString &newName) | - | ||||||||||||
| 320 | { | - | ||||||||||||
| 321 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 322 | if (d->fileName.isEmpty()) { | - | ||||||||||||
| 323 | QMessageLogger(__FILE__, 747753, __PRETTY_FUNCTION__).warning("QFile::copy: Empty or null file name"); | - | ||||||||||||
| 324 | return false; | - | ||||||||||||
| 325 | } | - | ||||||||||||
| 326 | if (QFile::exists(newName)) { | - | ||||||||||||
| 327 | - | |||||||||||||
| 328 | - | |||||||||||||
| 329 | - | |||||||||||||
| 330 | d->setError(QFile::CopyError, tr("Destination file exists")); | - | ||||||||||||
| 331 | return false; | - | ||||||||||||
| 332 | } | - | ||||||||||||
| 333 | unsetError(); | - | ||||||||||||
| 334 | close(); | - | ||||||||||||
| 335 | if(error() == QFile::NoError) { | - | ||||||||||||
| 336 | if (d->engine()->copy(newName)) { | - | ||||||||||||
| 337 | unsetError(); | - | ||||||||||||
| 338 | return true; | - | ||||||||||||
| 339 | } else { | - | ||||||||||||
| 340 | bool error = false; | - | ||||||||||||
| 341 | if(!open(QFile::ReadOnly)) { | - | ||||||||||||
| 342 | error = true; | - | ||||||||||||
| 343 | d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName)); | - | ||||||||||||
| 344 | } else { | - | ||||||||||||
| 345 | QString fileTemplate = QLatin1String("%1/qt_temp.XXXXXX"); | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | - | |||||||||||||
| 348 | - | |||||||||||||
| 349 | - | |||||||||||||
| 350 | - | |||||||||||||
| 351 | QTemporaryFile out(fileTemplate.arg(QFileInfo(newName).path())); | - | ||||||||||||
| 352 | if (!out.open()) { | - | ||||||||||||
| 353 | out.setFileTemplate(fileTemplate.arg(QDir::tempPath())); | - | ||||||||||||
| 354 | if (!out.open()) | - | ||||||||||||
| 355 | error = true; | - | ||||||||||||
| 356 | } | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | if (error) { | - | ||||||||||||
| 359 | out.close(); | - | ||||||||||||
| 360 | close(); | - | ||||||||||||
| 361 | d->setError(QFile::CopyError, tr("Cannot open for output")); | - | ||||||||||||
| 362 | } else { | - | ||||||||||||
| 363 | char block[4096]; | - | ||||||||||||
| 364 | qint64 totalRead = 0; | - | ||||||||||||
| 365 | while(!atEnd()) { | - | ||||||||||||
| 366 | qint64 in = read(block, sizeof(block)); | - | ||||||||||||
| 367 | if (in <= 0) | - | ||||||||||||
| 368 | break; | - | ||||||||||||
| 369 | totalRead += in; | - | ||||||||||||
| 370 | if(in != out.write(block, in)) { | - | ||||||||||||
| 371 | close(); | - | ||||||||||||
| 372 | d->setError(QFile::CopyError, tr("Failure to write block")); | - | ||||||||||||
| 373 | error = true; | - | ||||||||||||
| 374 | break; | - | ||||||||||||
| 375 | } | - | ||||||||||||
| 376 | } | - | ||||||||||||
| 377 | - | |||||||||||||
| 378 | if (totalRead != size()) { | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | - | |||||||||||||
| 381 | error = true; | - | ||||||||||||
| 382 | } | - | ||||||||||||
| 383 | if (!error && !out.rename(newName)) { | - | ||||||||||||
| 384 | error = true; | - | ||||||||||||
| 385 | close(); | - | ||||||||||||
| 386 | d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName)); | - | ||||||||||||
| 387 | } | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | - | |||||||||||||
| 390 | - | |||||||||||||
| 391 | - | |||||||||||||
| 392 | if (!error) | - | ||||||||||||
| 393 | out.setAutoRemove(false); | - | ||||||||||||
| 394 | - | |||||||||||||
| 395 | } | - | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | if(!error) { | - | ||||||||||||
| 398 | QFile::setPermissions(newName, permissions()); | - | ||||||||||||
| 399 | close(); | - | ||||||||||||
| 400 | unsetError(); | - | ||||||||||||
| 401 | return true; | - | ||||||||||||
| 402 | } | - | ||||||||||||
| 403 | } | - | ||||||||||||
| 404 | } | - | ||||||||||||
| 405 | return false; | - | ||||||||||||
| 406 | } | - | ||||||||||||
| 407 | bool | - | ||||||||||||
| 408 | QFile::copy(const QString &fileName, const QString &newName) | - | ||||||||||||
| 409 | { | - | ||||||||||||
| 410 | return QFile(fileName).copy(newName); | - | ||||||||||||
| 411 | } | - | ||||||||||||
| 412 | bool QFile::open(OpenMode mode) | - | ||||||||||||
| 413 | { | - | ||||||||||||
| 414 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 415 | if (isOpen()) { | - | ||||||||||||
| 416 | QMessageLogger(__FILE__, 868874, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData()); | - | ||||||||||||
| 417 | return false; | - | ||||||||||||
| 418 | } | - | ||||||||||||
| 419 | if (mode & Append) | - | ||||||||||||
| 420 | mode |= WriteOnly; | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | unsetError(); | - | ||||||||||||
| 423 | if ((mode & (ReadOnly | WriteOnly)) == 0) { | - | ||||||||||||
| 424 | QMessageLogger(__FILE__, 876882, __PRETTY_FUNCTION__).warning("QIODevice::open: File access not specified"); | - | ||||||||||||
| 425 | return false; | - | ||||||||||||
| 426 | } | - | ||||||||||||
| 427 | - | |||||||||||||
| 428 | - | |||||||||||||
| 429 | if (d->engine()->open(mode | QIODevice::Unbuffered)) { | - | ||||||||||||
| 430 | QIODevice::open(mode); | - | ||||||||||||
| 431 | if (mode & Append) | - | ||||||||||||
| 432 | seek(size()); | - | ||||||||||||
| 433 | return true; | - | ||||||||||||
| 434 | } | - | ||||||||||||
| 435 | QFile::FileError err = d->fileEngine->error(); | - | ||||||||||||
| 436 | if(err == QFile::UnspecifiedError) | - | ||||||||||||
| 437 | err = QFile::OpenError; | - | ||||||||||||
| 438 | d->setError(err, d->fileEngine->errorString()); | - | ||||||||||||
| 439 | return false; | - | ||||||||||||
| 440 | } | - | ||||||||||||
| 441 | bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags) | - | ||||||||||||
| 442 | { | - | ||||||||||||
| 443 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 444 | if (isOpen()) { | - | ||||||||||||
| 445 | QMessageLogger(__FILE__, 942946, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData()); | - | ||||||||||||
| 446 | return false; | - | ||||||||||||
| 447 | } | - | ||||||||||||
| 448 | if (mode & Append) | - | ||||||||||||
| 449 | mode |= WriteOnly; | - | ||||||||||||
| 450 | unsetError(); | - | ||||||||||||
| 451 | if ((mode & (ReadOnly | WriteOnly)) == 0) { | - | ||||||||||||
| 452 | QMessageLogger(__FILE__, 949953, __PRETTY_FUNCTION__).warning("QFile::open: File access not specified"); | - | ||||||||||||
| 453 | return false; | - | ||||||||||||
| 454 | } | - | ||||||||||||
| 455 | if (d->openExternalFile(mode, fh, handleFlags)) { | - | ||||||||||||
| 456 | QIODevice::open(mode); | - | ||||||||||||
| 457 | if (!(mode & Append) && !isSequential()) { | - | ||||||||||||
| 458 | qint64 pos = (qint64)::ftello64(fh); | - | ||||||||||||
| 459 | if (pos != -1) { | - | ||||||||||||
| 460 | - | |||||||||||||
| 461 | QIODevice::seek(pos); | - | ||||||||||||
| 462 | } | - | ||||||||||||
| 463 | } | - | ||||||||||||
| 464 | return true; | - | ||||||||||||
| 465 | } | - | ||||||||||||
| 466 | return false; | - | ||||||||||||
| 467 | } | - | ||||||||||||
| 468 | bool QFile::open(int fd, OpenMode mode, FileHandleFlags handleFlags) | - | ||||||||||||
| 469 | { | - | ||||||||||||
| 470 | QFilePrivate * const d = d_func(); | - | ||||||||||||
| 471 | if (isOpen()) { | - | ||||||||||||
| 472 | QMessageLogger(__FILE__, 10011002, __PRETTY_FUNCTION__).warning("QFile::open: File (%s) already open", QString(fileName()).toLocal8Bit().constData()); | - | ||||||||||||
| 473 | return false; | - | ||||||||||||
| 474 | } | - | ||||||||||||
| 475 | if (mode & Append) | - | ||||||||||||
| 476 | mode |= WriteOnly; | - | ||||||||||||
| 477 | unsetError(); | - | ||||||||||||
| 478 | if ((mode & (ReadOnly | WriteOnly)) == 0) { | - | ||||||||||||
| 479 | QMessageLogger(__FILE__, 10081009, __PRETTY_FUNCTION__).warning("QFile::open: File access not specified"); | - | ||||||||||||
| 480 | return false; | - | ||||||||||||
| 481 | } | - | ||||||||||||
| 482 | if (d->openExternalFile(mode, fd, handleFlags)) { | - | ||||||||||||
| 483 | QIODevice::open(mode); | - | ||||||||||||
| 484 | if (!(mode & Append) && !isSequential()) { | - | ||||||||||||
| 485 | qint64 pos = (qint64)::lseek64(fd, off64_t(0), 1); | - | ||||||||||||
| 486 | if (pos != -1) { | - | ||||||||||||
| 487 | - | |||||||||||||
| 488 | QIODevice::seek(pos); | - | ||||||||||||
| 489 | } | - | ||||||||||||
| 490 | } | - | ||||||||||||
| 491 | return true; | - | ||||||||||||
| 492 | } | - | ||||||||||||
| 493 | return false; | - | ||||||||||||
| 494 | } | - | ||||||||||||
| 495 | - | |||||||||||||
| 496 | - | |||||||||||||
| 497 | - | |||||||||||||
| 498 | - | |||||||||||||
| 499 | bool QFile::resize(qint64 sz) | - | ||||||||||||
| 500 | { | - | ||||||||||||
| 501 | return QFileDevice::resize(sz); | - | ||||||||||||
| 502 | } | - | ||||||||||||
| 503 | bool | - | ||||||||||||
| 504 | QFile::resize(const QString &fileName, qint64 sz) | - | ||||||||||||
| 505 | { | - | ||||||||||||
| 506 | return QFile(fileName).resize(sz); | - | ||||||||||||
| 507 | } | - | ||||||||||||
| 508 | - | |||||||||||||
| 509 | - | |||||||||||||
| 510 | - | |||||||||||||
| 511 | - | |||||||||||||
| 512 | QFile::Permissions QFile::permissions() const | - | ||||||||||||
| 513 | { | - | ||||||||||||
| 514 | return QFileDevice::permissions(); | - | ||||||||||||
| 515 | } | - | ||||||||||||
| 516 | QFile::Permissions | - | ||||||||||||
| 517 | QFile::permissions(const QString &fileName) | - | ||||||||||||
| 518 | { | - | ||||||||||||
| 519 | return QFile(fileName).permissions(); | - | ||||||||||||
| 520 | } | - | ||||||||||||
| 521 | bool QFile::setPermissions(Permissions permissions) | - | ||||||||||||
| 522 | { | - | ||||||||||||
| 523 | return QFileDevice::setPermissions(permissions); | - | ||||||||||||
| 524 | } | - | ||||||||||||
| 525 | - | |||||||||||||
| 526 | - | |||||||||||||
| 527 | - | |||||||||||||
| 528 | - | |||||||||||||
| 529 | - | |||||||||||||
| 530 | - | |||||||||||||
| 531 | - | |||||||||||||
| 532 | bool | - | ||||||||||||
| 533 | QFile::setPermissions(const QString &fileName, Permissions permissions) | - | ||||||||||||
| 534 | { | - | ||||||||||||
| 535 | return QFile(fileName).setPermissions(permissions); | - | ||||||||||||
| 536 | } | - | ||||||||||||
| 537 | - | |||||||||||||
| 538 | - | |||||||||||||
| 539 | - | |||||||||||||
| 540 | - | |||||||||||||
| 541 | qint64 QFile::size() const | - | ||||||||||||
| 542 | { | - | ||||||||||||
| 543 | return QFileDevice::size(); | - | ||||||||||||
| 544 | } | - | ||||||||||||
| 545 | - | |||||||||||||
| 546 | - | |||||||||||||
| Switch to Source code | Preprocessed file |