diff --git a/buildfile.go b/buildfile.go index 8e92702ae0..ef4b95c064 100644 --- a/buildfile.go +++ b/buildfile.go @@ -407,18 +407,20 @@ func (b *buildFile) CmdAdd(args string) error { hash string sums = b.context.GetSums() ) + + // Has tarsum strips the '.' and './', we put it back for comparaison. + for file, sum := range sums { + if len(file) == 0 || file[0] != '.' && file[0] != '/' { + delete(sums, file) + sums["./"+file] = sum + } + } + if fi, err := os.Stat(path.Join(b.contextPath, origPath)); err != nil { return err } else if fi.IsDir() { var subfiles []string for file, sum := range sums { - // Has tarsum stips the '.' and './', we put it back for comparaison. - if len(file) == 0 { - file = "./" - } - if file[0] != '.' && file[0] != '/' { - file = "./" + file - } if strings.HasPrefix(file, origPath) { subfiles = append(subfiles, sum) } @@ -435,7 +437,8 @@ func (b *buildFile) CmdAdd(args string) error { if err != nil { return err } - if hit { + // If we do not have a hash, never use the cache + if hit && hash != "" { return nil } } diff --git a/integration/buildfile_test.go b/integration/buildfile_test.go index 5f3991636d..efbdc54951 100644 --- a/integration/buildfile_test.go +++ b/integration/buildfile_test.go @@ -532,6 +532,21 @@ func TestBuildADDLocalFileWithCache(t *testing.T) { if id5 == id6 { t.Fatal("The cache should have been invalided but hasn't.") } + + template.dockerfile += ` + add bar /src2/bar2 + add /bar /src2/bar3 + run ls /src2/bar2 /src2/bar3 + ` + id7 := checkCacheBehaviorFromEngime(t, template, true, eng) + if id6 == id7 { + t.Fatal("The cache should have been invalided but hasn't.") + } + template.files[1][1] = "hello5" + id8 := checkCacheBehaviorFromEngime(t, template, true, eng) + if id7 == id8 { + t.Fatal("The cache should have been invalided but hasn't.") + } } func TestBuildADDLocalFileWithoutCache(t *testing.T) {