From 2e7b4bf6739b8b9d803bfb3e96c6d0b4ec26077a Mon Sep 17 00:00:00 2001 From: Vincent A Date: Tue, 27 Mar 2012 23:02:22 +0200 Subject: [PATCH] Document QFile::rename and QDir::rename's copy operation Change-Id: Ie81804f77510cfb73917332c8faaf921525fc26e Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 9 +++++++-- src/corelib/io/qfile.cpp | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 1dedc7c5c8..23bf3c5f4b 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1741,11 +1741,16 @@ bool QDir::remove(const QString &fileName) true if successful; otherwise returns false. On most file systems, rename() fails only if \a oldName does not - exist, if \a newName and \a oldName are not on the same - partition or if a file with the new name already exists. + exist, or if a file with the new name already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if \a newName points to an open file. + + If \a oldName is a file (not a directory) that can't be renamed + right away, Qt will try to copy \a oldName to \a newName and remove + \a oldName. + + \sa QFile::rename() */ bool QDir::rename(const QString &oldName, const QString &newName) { diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 6640dca70b..6e7b39fcf4 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -698,6 +698,11 @@ QFile::remove(const QString &fileName) The file is closed before it is renamed. + If the rename operation fails, Qt will attempt to copy this file's + contents to \a newName, and then remove this file, keeping only + \a newName. If that copy operation fails or this file can't be removed, + the destination file \a newName is removed to restore the old state. + \sa setFileName() */