blob: 70630eaaa17590eadf4c6aa1696e4ecec87fe38b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
--- a/src/core/download_store.cc
+++ b/src/core/download_store.cc
@@ -38,6 +38,7 @@
#include "config.h"
+#include <fcntl.h>
#include <fstream>
#include <stdio.h>
#include <unistd.h>
@@ -102,6 +103,7 @@ bool
DownloadStore::write_bencode(const std::string& filename, const torrent::Object& obj, uint32_t skip_mask) {
torrent::Object tmp;
std::fstream output(filename.c_str(), std::ios::out | std::ios::trunc);
+ int fd = -1;
if (!output.is_open())
goto download_store_save_error;
@@ -121,6 +123,15 @@ DownloadStore::write_bencode(const std::
goto download_store_save_error;
output.close();
+
+ // Ensure that the new file is actually written to the disk
+ fd = ::open(filename.c_str(), O_WRONLY);
+ if (fd < 0)
+ goto download_store_save_error;
+
+ fsync(fd);
+ ::close(fd);
+
return true;
download_store_save_error:
|