From 150e8f78bf78213a7ebaed38e96ebcf2d2a7bfed Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Jul 2022 18:31:58 +0200 Subject: [PATCH] io/FileOutputStream: use fsync() if fdatasync() is unavailable Fixes the macOS build which apparently doesn't implement the POSIX function fdatasync(). --- src/io/FileOutputStream.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/io/FileOutputStream.cxx b/src/io/FileOutputStream.cxx index ec573b5f3..a7cd50fe3 100644 --- a/src/io/FileOutputStream.cxx +++ b/src/io/FileOutputStream.cxx @@ -252,7 +252,12 @@ FileOutputStream::Sync() { assert(IsDefined()); - if (fdatasync(fd.Get()) < 0) +#ifdef __linux__ + const bool success = fdatasync(fd.Get()) == 0; +#else + const bool success = fsync(fd.Get()) == 0; +#endif + if (!success) throw FormatErrno("Failed to sync %s", GetPath().c_str()); }