Add directory contents instead of while directory for docker build

This commit is contained in:
Guillaume J. Charmes 2013-05-28 15:22:01 -07:00
parent fe0c0c208c
commit 2897cb0476
2 changed files with 24 additions and 7 deletions

View File

@ -213,9 +213,28 @@ func (b *buildFile) CmdAdd(args string) error {
return err return err
} }
if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil { origPath := path.Join(b.context, orig)
destPath := path.Join(container.rwPath(), dest)
fi, err := os.Stat(origPath)
if err != nil {
return err return err
} }
if fi.IsDir() {
files, err := ioutil.ReadDir(path.Join(b.context, orig))
if err != nil {
return err
}
for _, fi := range files {
if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil {
return err
}
}
} else {
if err := utils.CopyDirectory(origPath, destPath); err != nil {
return err
}
}
return b.commit(cid) return b.commit(cid)
} }

View File

@ -533,8 +533,8 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
} }
func CopyDirectory(source, dest string) error { func CopyDirectory(source, dest string) error {
if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil { if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil {
return err return fmt.Errorf("Error copy: %s (%s)", err, output)
} }
return nil return nil
} }
@ -577,5 +577,3 @@ func FormatProgress(str string, json bool) string {
} }
return "Downloading " + str + "\r" return "Downloading " + str + "\r"
} }