From 168ace4476d1884803647e533a68031be981df0e Mon Sep 17 00:00:00 2001 From: Joonas Loppi Date: Tue, 8 Oct 2024 12:15:04 +0300 Subject: [PATCH] `WriteFileAtomic`: add fsync closes #27 --- os/osutil/writefileatomic.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/os/osutil/writefileatomic.go b/os/osutil/writefileatomic.go index b1821f8..f669895 100644 --- a/os/osutil/writefileatomic.go +++ b/os/osutil/writefileatomic.go @@ -70,6 +70,11 @@ func WriteFileAtomic(filename string, produce func(io.Writer) error, options ... } } + // `Close()` alone doesn't guarantee that the data has been successfully saved to disk. + if err := file.Sync(); err != nil { + return err + } + if err := file.Close(); err != nil { // double close intentional return err }