1From ddcc0779c8562d15085ffa3b453981321f08616a Mon Sep 17 00:00:00 2001 2From: Dmitry Kazakov <dimula73@gmail.com> 3Date: Thu, 3 Oct 2019 19:20:07 +0300 4Subject: [PATCH 20/22] Sync buffers of the destination file after 5 QFile::copy() 6 7After doing native file copying operating system (tested on Windows) 8doesn't sync the buffers of the file for some time. That is, if the 9user faces ome power outage, the file will be lost. 10 11Actually, the other (non-native) copying option already has buffers 12syncing code. So this patch also makes behavior a bit more consistent. 13 14Change-Id: Id1b716ae86f68303ef6a9745a3275628d91e2d93 15--- 16 src/corelib/io/qfile.cpp | 13 +++++++++++++ 17 1 file changed, 13 insertions(+) 18 19diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp 20index 1fb9af576c..c0d9415871 100644 21--- a/src/corelib/io/qfile.cpp 22+++ b/src/corelib/io/qfile.cpp 23@@ -784,6 +784,19 @@ QFile::copy(const QString &newName) 24 close(); 25 if(error() == QFile::NoError) { 26 if (d->engine()->copy(newName)) { 27+ /** 28+ * Force copied file to be synched to disk, like we do it in 29+ * alternative approach 30+ */ 31+ QFile out(newName); 32+ if (out.open(QIODevice::ReadWrite)) { 33+ bool result = out.d_func()->engine()->syncToDisk(); 34+ out.close(); 35+ } else { 36+ d->setError(QFile::CopyError, tr("Cannot open %1 for output").arg(newName)); 37+ return false; 38+ } 39+ 40 unsetError(); 41 return true; 42 } else { 43-- 442.20.1.windows.1 45 46