1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

Fix call to nil stat

Fixes #10242

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 811b138f7e6c742b821da15e34338651f33f9ec2
Component: engine
This commit is contained in:
Brian Goff
2015-01-21 12:04:43 -05:00
parent dcea23baf1
commit 5752ad288d
2 changed files with 8 additions and 20 deletions

View File

@@ -53,6 +53,8 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.
if err := parseSecurityOpt(container, hostConfig); err != nil {
return err
}
// FIXME: this should be handled by the volume subsystem
// Validate the HostConfig binds. Make sure that:
// the source exists
for _, bind := range hostConfig.Binds {

View File

@@ -86,30 +86,14 @@ func (v *Volume) AddContainer(containerId string) {
v.lock.Unlock()
}
func (v *Volume) createIfNotExist() error {
if stat, err := os.Stat(v.Path); err != nil && os.IsNotExist(err) {
if stat.IsDir() {
os.MkdirAll(v.Path, 0755)
}
if err := os.MkdirAll(filepath.Dir(v.Path), 0755); err != nil {
return err
}
f, err := os.OpenFile(v.Path, os.O_CREATE, 0755)
if err != nil {
return err
}
f.Close()
}
return nil
}
func (v *Volume) initialize() error {
v.lock.Lock()
defer v.lock.Unlock()
if err := v.createIfNotExist(); err != nil {
return err
if _, err := os.Stat(v.Path); err != nil && os.IsNotExist(err) {
if err := os.MkdirAll(v.Path, 0755); err != nil {
return err
}
}
if err := os.MkdirAll(v.configPath, 0755); err != nil {
@@ -133,6 +117,7 @@ func (v *Volume) ToDisk() error {
defer v.lock.Unlock()
return v.toDisk()
}
func (v *Volume) toDisk() error {
data, err := json.Marshal(v)
if err != nil {
@@ -146,6 +131,7 @@ func (v *Volume) toDisk() error {
return ioutil.WriteFile(pth, data, 0666)
}
func (v *Volume) FromDisk() error {
v.lock.Lock()
defer v.lock.Unlock()