From 29a3bbf2b375111b9494df1ce5ee457508f7acad Mon Sep 17 00:00:00 2001 From: Ankush Agarwal Date: Mon, 20 Apr 2015 13:05:48 -0700 Subject: [PATCH] Eliminate json.Marshal from graph/export.go and volumes/volume.go Fixes #12531 Fixes #12530 Signed-off-by: Ankush Agarwal --- graph/export.go | 11 +++++++++-- volumes/volume.go | 13 +++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/graph/export.go b/graph/export.go index 00cfa8975a..91382c60e5 100644 --- a/graph/export.go +++ b/graph/export.go @@ -85,8 +85,15 @@ func (s *TagStore) ImageExport(imageExportConfig *ImageExportConfig) error { } // write repositories, if there is something to write if len(rootRepoMap) > 0 { - rootRepoJson, _ := json.Marshal(rootRepoMap) - if err := ioutil.WriteFile(path.Join(tempdir, "repositories"), rootRepoJson, os.FileMode(0644)); err != nil { + f, err := os.OpenFile(path.Join(tempdir, "repositories"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + if err != nil { + f.Close() + return err + } + if err := json.NewEncoder(f).Encode(rootRepoMap); err != nil { + return err + } + if err := f.Close(); err != nil { return err } } else { diff --git a/volumes/volume.go b/volumes/volume.go index 87aa4ad25a..1644692655 100644 --- a/volumes/volume.go +++ b/volumes/volume.go @@ -2,7 +2,6 @@ package volumes import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "sync" @@ -81,17 +80,19 @@ func (v *Volume) ToDisk() error { } func (v *Volume) toDisk() error { - data, err := json.Marshal(v) + jsonPath, err := v.jsonPath() if err != nil { return err } - - pth, err := v.jsonPath() + f, err := os.OpenFile(jsonPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return err } - - return ioutil.WriteFile(pth, data, 0666) + if err := json.NewEncoder(f).Encode(v); err != nil { + f.Close() + return err + } + return f.Close() } func (v *Volume) FromDisk() error {