mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
fs: use new atomic package - use FileCreateWithPrefix() API
This commit is contained in:
13
vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go
generated
vendored
13
vendor/github.com/minio/minio-xl/pkg/atomic/atomic.go
generated
vendored
@@ -33,6 +33,11 @@ type File struct {
|
||||
|
||||
// Close the file replacing, returns an error if any
|
||||
func (f *File) Close() error {
|
||||
// sync to the disk
|
||||
err := f.Sync()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// close the embedded fd
|
||||
if err := f.File.Close(); err != nil {
|
||||
return err
|
||||
@@ -58,12 +63,18 @@ func (f *File) CloseAndPurge() error {
|
||||
|
||||
// FileCreate creates a new file at filePath for atomic writes, it also creates parent directories if they don't exist
|
||||
func FileCreate(filePath string) (*File, error) {
|
||||
return FileCreateWithPrefix(filePath, "$deleteme.")
|
||||
}
|
||||
|
||||
// FileCreateWithPrefix creates a new file at filePath for atomic writes, it also creates parent directories if they don't exist
|
||||
// prefix specifies the prefix of the temporary files so that cleaning stale temp files is easy
|
||||
func FileCreateWithPrefix(filePath string, prefix string) (*File, error) {
|
||||
// if parent directories do not exist, ioutil.TempFile doesn't create them
|
||||
// handle such a case with os.MkdirAll()
|
||||
if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := ioutil.TempFile(filepath.Dir(filePath), filepath.Base(filePath))
|
||||
f, err := ioutil.TempFile(filepath.Dir(filePath), prefix+filepath.Base(filePath))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
11
vendor/github.com/minio/minio-xl/pkg/quick/quick.go
generated
vendored
11
vendor/github.com/minio/minio-xl/pkg/quick/quick.go
generated
vendored
@@ -30,6 +30,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/minio/minio-xl/pkg/atomic"
|
||||
"github.com/minio/minio-xl/pkg/probe"
|
||||
)
|
||||
|
||||
@@ -193,7 +194,15 @@ func (d config) Save(filename string) *probe.Error {
|
||||
jsonData = []byte(strings.Replace(string(jsonData), "\n", "\r\n", -1))
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filename, jsonData, 0600)
|
||||
atomicFile, err := atomic.FileCreate(filename)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
_, err = atomicFile.Write(jsonData)
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
err = atomicFile.Close()
|
||||
if err != nil {
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
8
vendor/vendor.json
vendored
8
vendor/vendor.json
vendored
@@ -39,8 +39,8 @@
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-xl/pkg/atomic",
|
||||
"revision": "a5fc6d2430ba2ebcab31b938ab02a42bac85dc2e",
|
||||
"revisionTime": "2015-10-20T11:16:42-07:00"
|
||||
"revision": "008404af67dcf66bdde580245cd43951b425ed39",
|
||||
"revisionTime": "2015-11-17T16:21:42-08:00"
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-xl/pkg/cpu",
|
||||
@@ -69,8 +69,8 @@
|
||||
},
|
||||
{
|
||||
"path": "github.com/minio/minio-xl/pkg/quick",
|
||||
"revision": "a5fc6d2430ba2ebcab31b938ab02a42bac85dc2e",
|
||||
"revisionTime": "2015-10-20T11:16:42-07:00"
|
||||
"revision": "008404af67dcf66bdde580245cd43951b425ed39",
|
||||
"revisionTime": "2015-11-17T16:21:42-08:00"
|
||||
},
|
||||
{
|
||||
"path": "github.com/rs/cors",
|
||||
|
||||
Reference in New Issue
Block a user