summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-04-15 12:24:43 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-05-22 12:33:39 (GMT)
commitf1e9c0f3d22d611bfaa14c30a34e6042500a0cb8 (patch)
tree43f3176a2b0034ea8059502dfb5fce209eac6191 /src/corelib/io
parent562adecf4f938f593674f03b425a79b89e238518 (diff)
downloadQt-f1e9c0f3d22d611bfaa14c30a34e6042500a0cb8.zip
Qt-f1e9c0f3d22d611bfaa14c30a34e6042500a0cb8.tar.gz
Qt-f1e9c0f3d22d611bfaa14c30a34e6042500a0cb8.tar.bz2
Allow renaming QTemporaryFiles on windows
Changed the fallback implementation to use 'this' instead of a new QFile. This allows a QTemporaryFile to be block-copied to the destination and the source to be removed (QTemporaryFile is special because it isn't really closed). Reviewed-by: Peter Hartmann Reviewed-by: Thiago
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfile.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 4110494..d3cee9a 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -723,26 +723,25 @@ QFile::rename(const QString &newName)
return false;
}
- QFile in(fileName());
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;
}
@@ -751,10 +750,12 @@ QFile::rename(const QString &newName)
out.remove();
else
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;
}