Write files in O_SYNC for fs backend to protect against machine crashes (#9434)

master
Krishna Srinivas 5 years ago committed by GitHub
parent 558785a4bb
commit 4843affd0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/fs-v1-helpers.go
  2. 2
      pkg/ioutil/append-file_nix.go

@ -321,7 +321,7 @@ func fsCreateFile(ctx context.Context, filePath string, reader io.Reader, buf []
return 0, err 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 { if err != nil {
return 0, osErrToFSFileErr(err) return 0, osErrToFSFileErr(err)
} }

@ -25,7 +25,7 @@ import (
// AppendFile - appends the file "src" to the file "dst" // AppendFile - appends the file "src" to the file "dst"
func AppendFile(dst string, src string) error { 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 { if err != nil {
return err return err
} }

Loading…
Cancel
Save