# HG changeset patch # User Sebastien Jodogne # Date 1600104475 -7200 # Node ID e99d1ad11cfe82511e50acc6a2ae897734b81466 # Parent b289a1234822bf6935f3357145e3cb597554fc47 fix build diff -r b289a1234822 -r e99d1ad11cfe OrthancFramework/Resources/CMake/BoostConfiguration.cmake --- a/OrthancFramework/Resources/CMake/BoostConfiguration.cmake Mon Sep 14 18:09:30 2020 +0200 +++ b/OrthancFramework/Resources/CMake/BoostConfiguration.cmake Mon Sep 14 19:27:55 2020 +0200 @@ -240,7 +240,7 @@ ## - ## Configuration of boost::filesystem + ## Configuration of boost::filesystem and boost::iostreams ## if (CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR @@ -277,6 +277,10 @@ endif() endif() + list(APPEND BOOST_SOURCES + ${BOOST_NAME}/libs/iostreams/src/file_descriptor.cpp + ) + ## ## Configuration of boost::locale diff -r b289a1234822 -r e99d1ad11cfe OrthancFramework/Sources/SystemToolbox.cpp --- a/OrthancFramework/Sources/SystemToolbox.cpp Mon Sep 14 18:09:30 2020 +0200 +++ b/OrthancFramework/Sources/SystemToolbox.cpp Mon Sep 14 19:27:55 2020 +0200 @@ -26,6 +26,7 @@ #if defined(_WIN32) # include +# include // For "FlushFileBuffers()" # include // For "_spawnvp()" and "_getpid()" # include // For "environ" #else @@ -307,7 +308,29 @@ { // https://stackoverflow.com/a/23826489/881731 f.flush(); - ::fdatasync(f->handle()); + + bool success = false; + + /** + * "f->handle()" corresponds to "FILE*" (aka "HANDLE") on + * Microsoft Windows, and to "int" (file descriptor) on other + * systems: + * https://github.com/boostorg/iostreams/blob/develop/include/boost/iostreams/detail/file_handle.hpp + **/ + +#if defined(_WIN32) + // https://docs.microsoft.com/fr-fr/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers + success = (::FlushFileBuffers(f->handle()) != 0); +#elif (_POSIX_C_SOURCE >= 199309L || _XOPEN_SOURCE >= 500) + success = (::fdatasync(f->handle()) == 0); +#else + success = (::fsync(f->handle()) == 0); +#endif + + if (!success) + { + throw OrthancException(ErrorCode_FileStorageCannotWrite, "Cannot force flush to disk"); + } } f.close(); diff -r b289a1234822 -r e99d1ad11cfe OrthancFramework/UnitTestsSources/FrameworkTests.cpp --- a/OrthancFramework/UnitTestsSources/FrameworkTests.cpp Mon Sep 14 18:09:30 2020 +0200 +++ b/OrthancFramework/UnitTestsSources/FrameworkTests.cpp Mon Sep 14 19:27:55 2020 +0200 @@ -603,6 +603,15 @@ std::string u; ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException); + + { + TemporaryFile tmp; + std::string s = "Hello"; + SystemToolbox::WriteFile(s, tmp.GetPath(), true /* call fsync() */); + std::string t; + SystemToolbox::ReadFile(t, tmp.GetPath()); + ASSERT_EQ(s, t); + } }