Merge pull request #973 from harshavardhana/atomic-sync

atomic: do not sync by default, if needed use CloseAndSync()
master
Harshavardhana 9 years ago
commit ffa22cf31e
  1. 20
      vendor.json
  2. 17
      vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go

@ -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"
}
]
}

@ -23,6 +23,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings"
) )
// File container provided for atomic file writes // File container provided for atomic file writes
@ -31,13 +32,20 @@ type File struct {
file string file string
} }
// Close the file replacing, returns an error if any // CloseAndSync sync file to disk and close, returns an error if any
func (f *File) Close() error { func (f *File) CloseAndSync() error {
// sync to the disk // sync to the disk
err := f.Sync() if err := f.File.Sync(); err != nil {
if err != nil { return err
}
if err := f.Close(); err != nil {
return err return err
} }
return nil
}
// Close the file, returns an error if any
func (f *File) Close() error {
// close the embedded fd // close the embedded fd
if err := f.File.Close(); err != nil { if err := f.File.Close(); err != nil {
return err return err
@ -74,6 +82,7 @@ func FileCreateWithPrefix(filePath string, prefix string) (*File, error) {
if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil {
return nil, err return nil, err
} }
prefix = strings.TrimSpace(prefix)
f, err := ioutil.TempFile(filepath.Dir(filePath), prefix+filepath.Base(filePath)) f, err := ioutil.TempFile(filepath.Dir(filePath), prefix+filepath.Base(filePath))
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save