1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix call to nil stat

Fixes #10242

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-01-21 12:04:43 -05:00
parent f3aed2a297
commit 811b138f7e
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()