Skip to content

Commit

Permalink
WriteFileAtomic: add fsync
Browse files Browse the repository at this point in the history
closes #27
  • Loading branch information
joonas-fi committed Oct 8, 2024
1 parent 1fcc3ef commit 168ace4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions os/osutil/writefileatomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 168ace4

Please sign in to comment.