Mercurial > hg > orthanc
diff OrthancFramework/Sources/SystemToolbox.cpp @ 4185:b289a1234822
giving a try to cross-platform compilation of SyncStorageArea
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 Sep 2020 18:09:30 +0200 |
parents | bf7b9edf6b81 |
children | e99d1ad11cfe |
line wrap: on
line diff
--- a/OrthancFramework/Sources/SystemToolbox.cpp Sat Sep 12 16:03:48 2020 +0200 +++ b/OrthancFramework/Sources/SystemToolbox.cpp Mon Sep 14 18:09:30 2020 +0200 @@ -56,6 +56,8 @@ #include "OrthancException.h" #include "Toolbox.h" +#include <boost/iostreams/device/file_descriptor.hpp> +#include <boost/iostreams/stream.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/date_time/posix_time/posix_time.hpp> @@ -278,9 +280,12 @@ void SystemToolbox::WriteFile(const void* content, size_t size, - const std::string& path) + const std::string& path, + bool callFsync) { - boost::filesystem::ofstream f; + //boost::filesystem::ofstream f; + boost::iostreams::stream<boost::iostreams::file_descriptor_sink> f; + f.open(path, std::ofstream::out | std::ofstream::binary); if (!f.good()) { @@ -298,15 +303,23 @@ } } + if (callFsync) + { + // https://stackoverflow.com/a/23826489/881731 + f.flush(); + ::fdatasync(f->handle()); + } + f.close(); } void SystemToolbox::WriteFile(const std::string& content, - const std::string& path) + const std::string& path, + bool callFsync) { WriteFile(content.size() > 0 ? content.c_str() : NULL, - content.size(), path); + content.size(), path, callFsync); }