Move atomic file writes into its own package, use them inside quick and disk packages

This commit is contained in:
Harshavardhana
2015-07-07 12:29:08 -07:00
parent fadadf0e1a
commit 52cd23ad9f
4 changed files with 143 additions and 40 deletions

View File

@@ -31,6 +31,7 @@ import (
"github.com/fatih/structs"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/utils/atomic"
)
// Config - generic config interface functions
@@ -115,11 +116,10 @@ func (d config) Save(filename string) (err error) {
return iodine.New(err, nil)
}
file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
file, err := atomic.FileCreate(filename)
if err != nil {
return iodine.New(err, nil)
}
defer file.Close()
if runtime.GOOS == "windows" {
jsonData = []byte(strings.Replace(string(jsonData), "\n", "\r\n", -1))
@@ -128,6 +128,10 @@ func (d config) Save(filename string) (err error) {
if err != nil {
return iodine.New(err, nil)
}
if err := file.Close(); err != nil {
return iodine.New(err, nil)
}
return nil
}