mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
container: minor cleanup/refactor
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
5c0b694ef3
commit
f4aafedc48
1 changed files with 9 additions and 8 deletions
|
@ -43,7 +43,10 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const configFileName = "config.v2.json"
|
||||
const (
|
||||
configFileName = "config.v2.json"
|
||||
hostConfigFileName = "hostconfig.json"
|
||||
)
|
||||
|
||||
// ExitStatus provides exit reasons for a container.
|
||||
type ExitStatus struct {
|
||||
|
@ -158,12 +161,9 @@ func (container *Container) FromDisk() error {
|
|||
return container.readHostConfig()
|
||||
}
|
||||
|
||||
// toDisk saves the container configuration on disk and returns a deep copy.
|
||||
// toDisk writes the container's configuration (config.v2.json, hostconfig.json)
|
||||
// to disk and returns a deep copy.
|
||||
func (container *Container) toDisk() (*Container, error) {
|
||||
var (
|
||||
buf bytes.Buffer
|
||||
deepCopy Container
|
||||
)
|
||||
pth, err := container.ConfigPath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -176,11 +176,13 @@ func (container *Container) toDisk() (*Container, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
w := io.MultiWriter(&buf, f)
|
||||
if err := json.NewEncoder(w).Encode(container); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var deepCopy Container
|
||||
if err := json.NewDecoder(&buf).Decode(&deepCopy); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -188,7 +190,6 @@ func (container *Container) toDisk() (*Container, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &deepCopy, nil
|
||||
}
|
||||
|
||||
|
@ -348,7 +349,7 @@ func (container *Container) ExitOnNext() {
|
|||
|
||||
// HostConfigPath returns the path to the container's JSON hostconfig
|
||||
func (container *Container) HostConfigPath() (string, error) {
|
||||
return container.GetRootResourcePath("hostconfig.json")
|
||||
return container.GetRootResourcePath(hostConfigFileName)
|
||||
}
|
||||
|
||||
// ConfigPath returns the path to the container's JSON config
|
||||
|
|
Loading…
Add table
Reference in a new issue