Always make sure the working directory exists

Always make sure the working directory exists before attempting to run
anything inside of it, and before attempting to copy contents into it or
one of its subdirectories.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2017-03-23 13:47:07 -04:00
parent 9cb2e7b62b
commit ae1fffb3fd
2 changed files with 6 additions and 0 deletions

3
add.go
View File

@@ -50,6 +50,9 @@ func (b *Builder) Add(destination string, extract bool, source ...string) error
if destination != "" && filepath.IsAbs(destination) {
dest = filepath.Join(dest, destination)
} else {
if err := os.MkdirAll(filepath.Join(dest, b.Workdir), 0755); err != nil {
return fmt.Errorf("error ensuring directory %q exists: %v)", b.Workdir, err)
}
dest = filepath.Join(dest, b.Workdir, destination)
}
// Make sure the destination is usable.

3
run.go
View File

@@ -108,6 +108,9 @@ func (b *Builder) Run(command []string, options RunOptions) error {
if spec.Process.Cwd == "" {
spec.Process.Cwd = DefaultWorkingDir
}
if err := os.MkdirAll(filepath.Join(mountPoint, b.Workdir), 0755); err != nil {
return fmt.Errorf("error ensuring working directory %q exists: %v)", b.Workdir, err)
}
mounts := options.Mounts
for _, specMount := range spec.Mounts {
override := false