Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
| ... | ... |
@@ -407,18 +407,20 @@ func (b *buildFile) CmdAdd(args string) error {
|
| 407 | 407 |
hash string |
| 408 | 408 |
sums = b.context.GetSums() |
| 409 | 409 |
) |
| 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 |
+ |
|
| 410 | 419 |
if fi, err := os.Stat(path.Join(b.contextPath, origPath)); err != nil {
|
| 411 | 420 |
return err |
| 412 | 421 |
} else if fi.IsDir() {
|
| 413 | 422 |
var subfiles []string |
| 414 | 423 |
for file, sum := range sums {
|
| 415 |
- // Has tarsum stips the '.' and './', we put it back for comparaison. |
|
| 416 |
- if len(file) == 0 {
|
|
| 417 |
- file = "./" |
|
| 418 |
- } |
|
| 419 |
- if file[0] != '.' && file[0] != '/' {
|
|
| 420 |
- file = "./" + file |
|
| 421 |
- } |
|
| 422 | 424 |
if strings.HasPrefix(file, origPath) {
|
| 423 | 425 |
subfiles = append(subfiles, sum) |
| 424 | 426 |
} |
| ... | ... |
@@ -435,7 +437,8 @@ func (b *buildFile) CmdAdd(args string) error {
|
| 435 | 435 |
if err != nil {
|
| 436 | 436 |
return err |
| 437 | 437 |
} |
| 438 |
- if hit {
|
|
| 438 |
+ // If we do not have a hash, never use the cache |
|
| 439 |
+ if hit && hash != "" {
|
|
| 439 | 440 |
return nil |
| 440 | 441 |
} |
| 441 | 442 |
} |
| ... | ... |
@@ -532,6 +532,21 @@ func TestBuildADDLocalFileWithCache(t *testing.T) {
|
| 532 | 532 |
if id5 == id6 {
|
| 533 | 533 |
t.Fatal("The cache should have been invalided but hasn't.")
|
| 534 | 534 |
} |
| 535 |
+ |
|
| 536 |
+ template.dockerfile += ` |
|
| 537 |
+ add bar /src2/bar2 |
|
| 538 |
+ add /bar /src2/bar3 |
|
| 539 |
+ run ls /src2/bar2 /src2/bar3 |
|
| 540 |
+ ` |
|
| 541 |
+ id7 := checkCacheBehaviorFromEngime(t, template, true, eng) |
|
| 542 |
+ if id6 == id7 {
|
|
| 543 |
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
| 544 |
+ } |
|
| 545 |
+ template.files[1][1] = "hello5" |
|
| 546 |
+ id8 := checkCacheBehaviorFromEngime(t, template, true, eng) |
|
| 547 |
+ if id7 == id8 {
|
|
| 548 |
+ t.Fatal("The cache should have been invalided but hasn't.")
|
|
| 549 |
+ } |
|
| 535 | 550 |
} |
| 536 | 551 |
|
| 537 | 552 |
func TestBuildADDLocalFileWithoutCache(t *testing.T) {
|