diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-05-22 16:50:30 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-05-22 16:50:30 (GMT) |
commit | d9ab330f613bd2c921ba00ed36b6eea8927aec80 (patch) | |
tree | 8a5337dac7617fe8e654fd4ffd1302c587967c76 /src/corelib/io/qfile.cpp | |
parent | dacc8cb0b2abd5ec3e9603c9bcf5b8f489639404 (diff) | |
parent | 701bdcbc8b7751834f6d24844bcb91a23cbdc409 (diff) | |
download | Qt-d9ab330f613bd2c921ba00ed36b6eea8927aec80.zip Qt-d9ab330f613bd2c921ba00ed36b6eea8927aec80.tar.gz Qt-d9ab330f613bd2c921ba00ed36b6eea8927aec80.tar.bz2 |
Merge branch '4.5'
Conflicts:
src/corelib/kernel/qsharedmemory_unix.cpp
Diffstat (limited to 'src/corelib/io/qfile.cpp')
-rw-r--r-- | src/corelib/io/qfile.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 04750b0..4deaddb 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -719,38 +719,47 @@ QFile::rename(const QString &newName) return true; } - QFile in(fileName()); + if (isSequential()) { + d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy")); + return false; + } + QFile out(newName); - if (in.open(QIODevice::ReadOnly)) { + if (open(QIODevice::ReadOnly)) { if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) { bool error = false; char block[4096]; - qint64 read; - while ((read = in.read(block, sizeof(block))) > 0) { - if (read != out.write(block, read)) { + qint64 bytes; + while ((bytes = read(block, sizeof(block))) > 0) { + if (bytes != out.write(block, bytes)) { d->setError(QFile::RenameError, out.errorString()); error = true; break; } } - if (read == -1) { - d->setError(QFile::RenameError, in.errorString()); + if (bytes == -1) { + d->setError(QFile::RenameError, errorString()); error = true; } if(!error) { - if (!in.remove()) { + if (!remove()) { d->setError(QFile::RenameError, tr("Cannot remove source file")); error = true; } } if (error) out.remove(); - else + else { + setPermissions(permissions()); + unsetError(); setFileName(newName); + } + close(); return !error; } + close(); } - d->setError(QFile::RenameError, out.isOpen() ? in.errorString() : out.errorString()); + d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString()); } return false; } |