Browse code

Add directory contents instead of while directory for docker build

Guillaume J. Charmes authored on 2013/05/29 07:22:01
Showing 2 changed files
... ...
@@ -213,9 +213,28 @@ func (b *buildFile) CmdAdd(args string) error {
213 213
 		return err
214 214
 	}
215 215
 
216
-	if err := utils.CopyDirectory(path.Join(b.context, orig), path.Join(container.rwPath(), dest)); err != nil {
216
+	origPath := path.Join(b.context, orig)
217
+	destPath := path.Join(container.rwPath(), dest)
218
+
219
+	fi, err := os.Stat(origPath)
220
+	if err != nil {
217 221
 		return err
218 222
 	}
223
+	if fi.IsDir() {
224
+		files, err := ioutil.ReadDir(path.Join(b.context, orig))
225
+		if err != nil {
226
+			return err
227
+		}
228
+		for _, fi := range files {
229
+			if err := utils.CopyDirectory(path.Join(origPath, fi.Name()), path.Join(destPath, fi.Name())); err != nil {
230
+				return err
231
+			}
232
+		}
233
+	} else {
234
+		if err := utils.CopyDirectory(origPath, destPath); err != nil {
235
+			return err
236
+		}
237
+	}
219 238
 
220 239
 	return b.commit(cid)
221 240
 }
... ...
@@ -69,7 +69,7 @@ type progressReader struct {
69 69
 	readProgress int           // How much has been read so far (bytes)
70 70
 	lastUpdate   int           // How many bytes read at least update
71 71
 	template     string        // Template to print. Default "%v/%v (%v)"
72
-	json bool
72
+	json         bool
73 73
 }
74 74
 
75 75
 func (r *progressReader) Read(p []byte) (n int, err error) {
... ...
@@ -102,7 +102,7 @@ func (r *progressReader) Close() error {
102 102
 	return io.ReadCloser(r.reader).Close()
103 103
 }
104 104
 func ProgressReader(r io.ReadCloser, size int, output io.Writer, template string, json bool) *progressReader {
105
-      	if template == "" {
105
+	if template == "" {
106 106
 		template = "%v/%v (%v)\r"
107 107
 	}
108 108
 	return &progressReader{r, NewWriteFlusher(output), size, 0, 0, template, json}
... ...
@@ -533,8 +533,8 @@ func GetKernelVersion() (*KernelVersionInfo, error) {
533 533
 }
534 534
 
535 535
 func CopyDirectory(source, dest string) error {
536
-	if _, err := exec.Command("cp", "-ra", source, dest).Output(); err != nil {
537
-		return err
536
+	if output, err := exec.Command("cp", "-ra", source, dest).CombinedOutput(); err != nil {
537
+		return fmt.Errorf("Error copy: %s (%s)", err, output)
538 538
 	}
539 539
 	return nil
540 540
 }
... ...
@@ -577,5 +577,3 @@ func FormatProgress(str string, json bool) string {
577 577
 	}
578 578
 	return "Downloading " + str + "\r"
579 579
 }
580
-
581
-