From da2a6066c7093c47b1d90f823d9fd3abfa34a46c Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 17 Nov 2015 23:03:55 -0800 Subject: [PATCH] atomic: do not sync by default, if needed use CloseAndSync() --- vendor.json | 20 +++++++++++++++++++ .../minio/minio-xl/pkg/atomic/atomic.go | 17 ++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100755 vendor.json diff --git a/vendor.json b/vendor.json new file mode 100755 index 000000000..8e8762e7b --- /dev/null +++ b/vendor.json @@ -0,0 +1,20 @@ +{ + "comment": "", + "ignore": "", + "package": [ + { + "canonical": "github.com/minio/minio-xl/pkg/atomic", + "comment": "", + "local": "vendor/github.com/minio/minio-xl/pkg/atomic", + "revision": "a32fbc1006b4a09176c91f57d22e87faff22a423", + "revisionTime": "2015-11-17T22:59:41-08:00" + }, + { + "canonical": "github.com/minio/minio-xl/pkg/quick", + "comment": "", + "local": "vendor/github.com/minio/minio-xl/pkg/quick", + "revision": "a32fbc1006b4a09176c91f57d22e87faff22a423", + "revisionTime": "2015-11-17T22:59:41-08:00" + } + ] +} \ No newline at end of file diff --git a/vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go b/vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go index e6969a690..56c7543aa 100644 --- a/vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go +++ b/vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go @@ -23,6 +23,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" ) // File container provided for atomic file writes @@ -31,13 +32,20 @@ type File struct { file string } -// Close the file replacing, returns an error if any -func (f *File) Close() error { +// CloseAndSync sync file to disk and close, returns an error if any +func (f *File) CloseAndSync() error { // sync to the disk - err := f.Sync() - if err != nil { + if err := f.File.Sync(); err != nil { + return err + } + if err := f.Close(); err != nil { return err } + return nil +} + +// Close the file, returns an error if any +func (f *File) Close() error { // close the embedded fd if err := f.File.Close(); err != nil { return err @@ -74,6 +82,7 @@ func FileCreateWithPrefix(filePath string, prefix string) (*File, error) { if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil { return nil, err } + prefix = strings.TrimSpace(prefix) f, err := ioutil.TempFile(filepath.Dir(filePath), prefix+filepath.Base(filePath)) if err != nil { return nil, err