Eliminate json.Marshal from graph/export.go and volumes/volume.go

Fixes #12531
Fixes #12530

Signed-off-by: Ankush Agarwal <ankushagarwal11@gmail.com>
This commit is contained in:
Ankush Agarwal 2015-04-20 13:05:48 -07:00
parent b31d154294
commit 29a3bbf2b3
2 changed files with 16 additions and 8 deletions

View File

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

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 {