summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorDavid Faure <faure+bluesystems@kde.org>2013-01-14 09:34:08 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-14 23:44:15 +0100
commit7e7b65c370207fa849ac0ec69fe9209f08d8f2e3 (patch)
treec3e45fa2fcfe34eb5eefdfe6a70aa32eeaa27851 /src/corelib
parent18c916517f3004d34482c20ed66bf09ec274d385 (diff)
Add renameOverwrite() to QAbstractFileEngine.
QFSFileEngine::rename() on Windows doesn't overwrite the existing destination. Keep that unchanged (it's the desired behavior in QFile::rename), and provide cross-platform rename-overwrite behavior in the new method. This is needed by QSaveFile. Change-Id: I5e753d289d8a53692530a48a1783d62e26169cdc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qabstractfileengine.cpp18
-rw-r--r--src/corelib/io/qabstractfileengine_p.h1
-rw-r--r--src/corelib/io/qfsfileengine.cpp5
-rw-r--r--src/corelib/io/qfsfileengine_p.h1
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp6
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp11
-rw-r--r--src/corelib/io/qtemporaryfile.cpp7
7 files changed, 49 insertions, 0 deletions
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp
index d7cf7e3f15..b12dc47c52 100644
--- a/src/corelib/io/qabstractfileengine.cpp
+++ b/src/corelib/io/qabstractfileengine.cpp
@@ -496,6 +496,24 @@ bool QAbstractFileEngine::rename(const QString &newName)
}
/*!
+ \since 5.1
+
+ Requests that the file be renamed to \a newName in the file
+ system. If the new name already exists, it must be overwritten.
+ If the operation succeeds, returns true; otherwise returns
+ false.
+
+ This virtual function must be reimplemented by all subclasses.
+
+ \sa setFileName()
+ */
+bool QAbstractFileEngine::renameOverwrite(const QString &newName)
+{
+ Q_UNUSED(newName);
+ return false;
+}
+
+/*!
Creates a link from the file currently specified by fileName() to
\a newName. What a link is depends on the underlying filesystem
(be it a shortcut on Windows or a symbolic link on Unix). Returns
diff --git a/src/corelib/io/qabstractfileengine_p.h b/src/corelib/io/qabstractfileengine_p.h
index 5d07a3a390..2cbd927968 100644
--- a/src/corelib/io/qabstractfileengine_p.h
+++ b/src/corelib/io/qabstractfileengine_p.h
@@ -131,6 +131,7 @@ public:
virtual bool remove();
virtual bool copy(const QString &newName);
virtual bool rename(const QString &newName);
+ virtual bool renameOverwrite(const QString &newName);
virtual bool link(const QString &newName);
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index 1d3f14f84e..1bc3a7da2e 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -908,6 +908,11 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
\reimp
*/
+
+/*! \fn bool QFSFileEngine::renameOverwrite(const QString &newName)
+ \reimp
+*/
+
/*! \fn bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
\reimp
*/
diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h
index 94aa1828a7..cf70032134 100644
--- a/src/corelib/io/qfsfileengine_p.h
+++ b/src/corelib/io/qfsfileengine_p.h
@@ -88,6 +88,7 @@ public:
bool remove();
bool copy(const QString &newName);
bool rename(const QString &newName);
+ bool renameOverwrite(const QString &newName);
bool link(const QString &newName);
bool mkdir(const QString &dirName, bool createParentDirectories) const;
bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index b91c7d7fe6..8f622d77cd 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -388,6 +388,12 @@ bool QFSFileEngine::copy(const QString &newName)
return ret;
}
+bool QFSFileEngine::renameOverwrite(const QString &newName)
+{
+ // On Unix, rename() overwrites.
+ return rename(newName);
+}
+
bool QFSFileEngine::rename(const QString &newName)
{
Q_D(QFSFileEngine);
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index d12a95f98a..86e9bf971d 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -507,6 +507,17 @@ bool QFSFileEngine::rename(const QString &newName)
return ret;
}
+bool QFSFileEngine::renameOverwrite(const QString &newName)
+{
+ Q_D(QFSFileEngine);
+ bool ret = ::MoveFileEx((wchar_t*)d->fileEntry.nativeFilePath().utf16(),
+ (wchar_t*)QFileSystemEntry(newName).nativeFilePath().utf16(),
+ MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) != 0;
+ if (!ret)
+ setError(QFile::RenameError, QSystemError(::GetLastError(), QSystemError::NativeError).toString());
+ return ret;
+}
+
bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
{
return QFileSystemEngine::createDirectory(QFileSystemEntry(name), createParentDirectories);
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index a647d21f40..161c64a73b 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -242,6 +242,7 @@ public:
bool open(QIODevice::OpenMode flags);
bool remove();
bool rename(const QString &newName);
+ bool renameOverwrite(const QString &newName);
bool close();
bool filePathIsTemplate;
@@ -398,6 +399,12 @@ bool QTemporaryFileEngine::rename(const QString &newName)
return QFSFileEngine::rename(newName);
}
+bool QTemporaryFileEngine::renameOverwrite(const QString &newName)
+{
+ QFSFileEngine::close();
+ return QFSFileEngine::renameOverwrite(newName);
+}
+
bool QTemporaryFileEngine::close()
{
// Don't close the file, just seek to the front.