diff options
author | Tonis Tiigi <tonistiigi@gmail.com> | 2016-04-20 17:08:47 -0700 |
---|---|---|
committer | Tonis Tiigi <tonistiigi@gmail.com> | 2016-04-21 11:31:15 -0700 |
commit | ea3cbd3274664f5b16fce78d7df036f6b5c94e30 (patch) | |
tree | 7b2fbcb619e4e04108333e73f31060becd75550e /reference | |
parent | 6f67c13d20b207e5ab9a038b04ccc44d337131ed (diff) | |
download | docker-ea3cbd3274664f5b16fce78d7df036f6b5c94e30.tar.gz |
Safer file io for configuration files
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Diffstat (limited to 'reference')
-rw-r--r-- | reference/store.go | 15 |
1 files changed, 2 insertions, 13 deletions
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 { |