diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-01-09 09:11:17 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-15 16:36:20 +0100 |
commit | d3dc0f21225845f404262ea563870044cbbbe53f (patch) | |
tree | 595c5553aa6abd5fba4c6c22bb8762c812dafc11 /src/corelib/io/qfile.cpp | |
parent | cd7ba89a07f794b17fc66ba29515b104c4d21f27 (diff) |
Fix renaming of files that differ only in case.
This currently fails on case-insensitive file
systems since the check for existence then triggered
and indicated "file already exists".
Check on the file id (inode or file id) whether
the target file is really a different file for a
case-changing rename.
Task-number: QTBUG-3570
Change-Id: I1b2d40850692e02142ee23d2c753428de00aedc6
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfile.cpp')
-rw-r--r-- | src/corelib/io/qfile.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index d9f2c5c605..24f0eba1b7 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -48,6 +48,7 @@ #include "qfileinfo.h" #include "private/qiodevice_p.h" #include "private/qfile_p.h" +#include "private/qfilesystemengine_p.h" #include "private/qsystemerror_p.h" #if defined(QT_BUILD_CORE_LIB) # include "qcoreapplication.h" @@ -548,7 +549,19 @@ QFile::rename(const QString &newName) qWarning("QFile::rename: Empty or null file name"); return false; } - if (QFile(newName).exists()) { + if (d->fileName == newName) { + d->setError(QFile::RenameError, tr("Destination file is the same file.")); + return false; + } + if (!exists()) { + d->setError(QFile::RenameError, tr("Source file does not exist.")); + return false; + } + // If the file exists and it is a case-changing rename ("foo" -> "Foo"), + // compare Ids to make sure it really is a different file. + if (QFile::exists(newName) + && (d->fileName.compare(newName, Qt::CaseInsensitive) + || QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName)))) { // ### Race condition. If a file is moved in after this, it /will/ be // overwritten. On Unix, the proper solution is to use hardlinks: // return ::link(old, new) && ::remove(old); |