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:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user