summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfsfileengine.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-04-17 02:08:48 +0200
committerAhmad Samir <a.samirh78@gmail.com>2024-04-20 04:29:31 +0200
commitdf6b74f4617bf0ba14420ed15fcc5866cccfb7d0 (patch)
tree42eb97c82d52e266888fcb7b5e2dba623215c662 /src/corelib/io/qfsfileengine.cpp
parentd691872b865c735f9d35886388c89f7ace7df5c8 (diff)
QFSFileEngine: update d->fileEntry after a successful rename
Otherwise member methods such as size() could return incorrect info. Add setFileEntry(QFileSystemEntry &&); to reuse a QFileSystemEntry if we have already constructed one. As a result of this, a QTemporaryFileEngine::setFileName() call has become redundant and can be removed; the code it executed is already taken care of: - QFSFileEngine::close(): already called by QTFEngine::rename() a couple of lines above - QFSFileEngine::setFileName(): QTFEngine::rename() calls QFSFileEngine::rename() which in turn updates the `fileEntry` This commit is covered by tst_QTemporaryFile::rename(), i.e. if QFSFileEngine::rename() didn't update the fileEntry, that test would fail. Change-Id: I312f35cf7fdf9b1a8cd0bce5e98ba7a48cf9426e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfsfileengine.cpp')
-rw-r--r--src/corelib/io/qfsfileengine.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp
index a4d0cc0e4f0..f49106edd4e 100644
--- a/src/corelib/io/qfsfileengine.cpp
+++ b/src/corelib/io/qfsfileengine.cpp
@@ -990,6 +990,17 @@ bool QFSFileEngine::remove()
return ret;
}
+/*
+ An alternative to setFileName() when you have already constructed
+ a QFileSystemEntry.
+*/
+void QFSFileEngine::setFileEntry(QFileSystemEntry &&entry)
+{
+ Q_D(QFSFileEngine);
+ d->init();
+ d->fileEntry = std::move(entry);
+}
+
bool QFSFileEngine::rename_helper(const QString &newName, RenameMode mode)
{
Q_D(QFSFileEngine);
@@ -997,10 +1008,14 @@ bool QFSFileEngine::rename_helper(const QString &newName, RenameMode mode)
auto func = mode == Rename ? QFileSystemEngine::renameFile
: QFileSystemEngine::renameOverwriteFile;
QSystemError error;
- const bool ret = func(d->fileEntry, QFileSystemEntry(newName), error);
- if (!ret)
+ auto newEntry = QFileSystemEntry(newName);
+ const bool ret = func(d->fileEntry, newEntry, error);
+ if (!ret) {
setError(QFile::RenameError, error.toString());
- return ret;
+ return false;
+ }
+ setFileEntry(std::move(newEntry));
+ return true;
}
/*!