Use json.Encoder for container.toDisk

* for simmetry with fromDisk
* it might be slightly better for GC because of internal sync.Pool

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-10-30 09:04:25 -07:00
parent 2c6351a4a5
commit cf02b369e0
1 changed files with 10 additions and 6 deletions

View File

@ -112,17 +112,21 @@ func (container *Container) fromDisk() error {
}
func (container *Container) toDisk() error {
data, err := json.Marshal(container)
if err != nil {
return err
}
pth, err := container.jsonPath()
if err != nil {
return err
}
if err := ioutil.WriteFile(pth, data, 0666); err != nil {
jsonSource, err := os.Create(pth)
if err != nil {
return err
}
defer jsonSource.Close()
enc := json.NewEncoder(jsonSource)
// Save container settings
if err := enc.Encode(container); err != nil {
return err
}