瀏覽代碼

Add directory contents instead of while directory for docker build

Guillaume J. Charmes 12 年之前
父節點
當前提交
2897cb0476
共有 2 個文件被更改,包括 24 次插入7 次删除
  1. 20 1
      buildfile.go
  2. 4 6
      utils/utils.go

+ 20 - 1
buildfile.go

@@ -213,9 +213,28 @@ func (b *buildFile) CmdAdd(args string) error {
 		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
 	}
+	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)
 }

+ 4 - 6
utils/utils.go

@@ -69,7 +69,7 @@ type progressReader struct {
 	readProgress int           // How much has been read so far (bytes)
 	lastUpdate   int           // How many bytes read at least update
 	template     string        // Template to print. Default "%v/%v (%v)"
-	json bool
+	json         bool
 }
 
 func (r *progressReader) Read(p []byte) (n int, err error) {
@@ -102,7 +102,7 @@ func (r *progressReader) Close() error {
 	return io.ReadCloser(r.reader).Close()
 }
 func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, json bool) *progressReader {
-      	if template == "" {
+	if template == "" {
 		template = "%v/%v (%v)\r"
 	}
 	return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json}
@@ -533,8 +533,8 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
 }
 
 func CopyDirectory(source, dest string) error {
-	if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil {
-		return err
+	if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil {
+		return fmt.Errorf("Error copy: %s (%s)", err, output)
 	}
 	return nil
 }
@@ -577,5 +577,3 @@ func FormatProgress(str string, json bool) string {
 	}
 	return "Downloading " + str + "\r"
 }
-
-