From ea3cbd3274664f5b16fce78d7df036f6b5c94e30 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 20 Apr 2016 17:08:47 -0700 Subject: Safer file io for configuration files Signed-off-by: Tonis Tiigi --- reference/store.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'reference') diff --git a/reference/store.go b/reference/store.go index 91c5c2aed2..00a2a09e78 100644 --- a/reference/store.go +++ b/reference/store.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "sort" @@ -12,6 +11,7 @@ import ( "github.com/docker/distribution/digest" "github.com/docker/docker/image" + "github.com/docker/docker/pkg/ioutils" ) var ( @@ -256,18 +256,7 @@ func (store *store) save() error { if err != nil { return err } - - tempFilePath := store.jsonPath + ".tmp" - - if err := ioutil.WriteFile(tempFilePath, jsonData, 0600); err != nil { - return err - } - - if err := os.Rename(tempFilePath, store.jsonPath); err != nil { - return err - } - - return nil + return ioutils.AtomicWriteFile(store.jsonPath, jsonData, 0600) } func (store *store) reload() error { -- cgit v1.2.1