mirror of https://github.com/docker/docs.git
Make sure dirs are created before injecting file
This commit is contained in:
parent
6669c86fdf
commit
20f690f176
13
container.go
13
container.go
|
|
@ -396,7 +396,8 @@ func (container *Container) Inject(file io.Reader, pth string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return error if path exists
|
// Return error if path exists
|
||||||
if _, err := os.Stat(path.Join(container.RootfsPath(), pth)); err == nil {
|
destPath := path.Join(container.RootfsPath(), pth)
|
||||||
|
if _, err := os.Stat(destPath); err == nil {
|
||||||
// Since err is nil, the path could be stat'd and it exists
|
// Since err is nil, the path could be stat'd and it exists
|
||||||
return fmt.Errorf("%s exists", pth)
|
return fmt.Errorf("%s exists", pth)
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
|
|
@ -405,10 +406,18 @@ func (container *Container) Inject(file io.Reader, pth string) error {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dest, err := os.Create(path.Join(container.RootfsPath(), pth))
|
|
||||||
|
// Make sure the directory exists
|
||||||
|
if err := os.MkdirAll(path.Join(container.RootfsPath(), path.Dir(pth)), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dest, err := os.Create(destPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer dest.Close()
|
||||||
|
|
||||||
if _, err := io.Copy(dest, file); err != nil {
|
if _, err := io.Copy(dest, file); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue