Merge pull request #12532 from ankushagarwal/eliminate-json-marshal

Eliminate json.Marshal from graph/export.go and volumes/volume.go
This commit is contained in:
Jessie Frazelle 2015-04-27 13:54:20 -05:00
commit 531ec3cac9
2 changed files with 16 additions and 8 deletions

View file

@ -83,8 +83,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 {

View file

@ -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 {