Browse code

Make sure file are cached correctly during build

Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)

Guillaume J. Charmes authored on 2014/01/09 05:16:23
Showing 1 changed files
... ...
@@ -408,14 +408,6 @@ func (b *buildFile) CmdAdd(args string) error {
408 408
 			sums = b.context.GetSums()
409 409
 		)
410 410
 
411
-		// Has tarsum strips the '.' and './', we put it back for comparaison.
412
-		for file, sum := range sums {
413
-			if len(file) == 0 || file[0] != '.' && file[0] != '/' {
414
-				delete(sums, file)
415
-				sums["./"+file] = sum
416
-			}
417
-		}
418
-
419 411
 		if fi, err := os.Stat(path.Join(b.contextPath, origPath)); err != nil {
420 412
 			return err
421 413
 		} else if fi.IsDir() {
... ...
@@ -432,7 +424,13 @@ func (b *buildFile) CmdAdd(args string) error {
432 432
 			hasher.Write([]byte(strings.Join(subfiles, ",")))
433 433
 			hash = "dir:" + hex.EncodeToString(hasher.Sum(nil))
434 434
 		} else {
435
-			hash = "file:" + sums[origPath]
435
+			if origPath[0] == '/' && len(origPath) > 1 {
436
+				origPath = origPath[1:]
437
+			}
438
+			origPath = strings.TrimPrefix(origPath, "./")
439
+			if h, ok := sums[origPath]; ok {
440
+				hash = "file:" + h
441
+			}
436 442
 		}
437 443
 		b.config.Cmd = []string{"/bin/sh", "-c", fmt.Sprintf("#(nop) ADD %s in %s", hash, dest)}
438 444
 		hit, err := b.probeCache()