mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
commit
531ec3cac9
2 changed files with 16 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue