summaryrefslogtreecommitdiff
path: root/src/AbstractDiskWriter.cc
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2020-06-17 09:51:04 +0300
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2020-06-17 11:07:03 +0300
commit01969fc5304a738718c00b6153d672ce4f085747 (patch)
tree7e22ccb113b3c916fc37bc32a55fef438e08e80d /src/AbstractDiskWriter.cc
parent870e2a6014462c55cc252140f5e215374881c6e9 (diff)
flush OS write buffers before saving control file
This ensures that pieces are physically written to disk before marking them as finished in the control file. This should prevent data loss and corruption when resuming downloads after a system crash. Signed-off-by: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com>
Diffstat (limited to 'src/AbstractDiskWriter.cc')
-rw-r--r--src/AbstractDiskWriter.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc
index ff4f8856..f21c5261 100644
--- a/src/AbstractDiskWriter.cc
+++ b/src/AbstractDiskWriter.cc
@@ -590,4 +590,16 @@ void AbstractDiskWriter::dropCache(int64_t len, int64_t offset)
#endif // HAVE_POSIX_FADVISE
}
+void AbstractDiskWriter::flushOSBuffers()
+{
+ if (fd_ == A2_BAD_FD) {
+ return;
+ }
+#ifdef __MINGW32__
+ FlushFileBuffers(fd_);
+#else // !__MINGW32__
+ fsync(fd_);
+#endif // __MINGW32__
+}
+
} // namespace aria2