From 4843affd0eab28e14e89de3f4c9a040d3b2659ca Mon Sep 17 00:00:00 2001 From: Krishna Srinivas <634494+krishnasrinivas@users.noreply.github.com> Date: Sat, 25 Apr 2020 01:18:54 -0700 Subject: [PATCH] Write files in O_SYNC for fs backend to protect against machine crashes (#9434) --- cmd/fs-v1-helpers.go | 2 +- pkg/ioutil/append-file_nix.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/fs-v1-helpers.go b/cmd/fs-v1-helpers.go index a275c08b6..79e27418e 100644 --- a/cmd/fs-v1-helpers.go +++ b/cmd/fs-v1-helpers.go @@ -321,7 +321,7 @@ func fsCreateFile(ctx context.Context, filePath string, reader io.Reader, buf [] return 0, err } - writer, err := lock.Open(filePath, os.O_CREATE|os.O_WRONLY, 0666) + writer, err := lock.Open(filePath, os.O_CREATE|os.O_WRONLY|os.O_SYNC, 0666) if err != nil { return 0, osErrToFSFileErr(err) } diff --git a/pkg/ioutil/append-file_nix.go b/pkg/ioutil/append-file_nix.go index f82367a9f..a5b937fc6 100644 --- a/pkg/ioutil/append-file_nix.go +++ b/pkg/ioutil/append-file_nix.go @@ -25,7 +25,7 @@ import ( // AppendFile - appends the file "src" to the file "dst" func AppendFile(dst string, src string) error { - appendFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666) + appendFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, 0666) if err != nil { return err }