mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix issue with file caching + prevent wrong cache hit
Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
This commit is contained in:
parent
ef7e000a13
commit
f3103e5c91
2 changed files with 26 additions and 8 deletions
19
buildfile.go
19
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue