From ae1fffb3fd642a8321c8780e366fcfe3cd77a997 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Thu, 23 Mar 2017 13:47:07 -0400 Subject: [PATCH] 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 --- add.go | 3 +++ run.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/add.go b/add.go index cbeb6757..46fabde9 100644 --- a/add.go +++ b/add.go @@ -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. diff --git a/run.go b/run.go index dfe1e3b3..16d26d59 100644 --- a/run.go +++ b/run.go @@ -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