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:
parent
2c6351a4a5
commit
cf02b369e0
|
@ -112,17 +112,21 @@ func (container *Container) fromDisk() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) toDisk() error {
|
func (container *Container) toDisk() error {
|
||||||
data, err := json.Marshal(container)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pth, err := container.jsonPath()
|
pth, err := container.jsonPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue