1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #27805 from Microsoft/jjh/fixbuildercache

Windows: Fix builder cache bug
This commit is contained in:
Vincent Demeester 2016-10-28 02:49:40 +02:00 committed by GitHub
commit 9e206b5512
3 changed files with 39 additions and 6 deletions

View file

@ -63,7 +63,7 @@ func (c *tarSumContext) Stat(path string) (string, FileInfo, error) {
sum := path sum := path
// Use the checksum of the followed path(not the possible symlink) because // Use the checksum of the followed path(not the possible symlink) because
// this is the file that is actually copied. // this is the file that is actually copied.
if tsInfo := c.sums.GetFile(rel); tsInfo != nil { if tsInfo := c.sums.GetFile(filepath.ToSlash(rel)); tsInfo != nil {
sum = tsInfo.Sum() sum = tsInfo.Sum()
} }
fi := &HashedFileInfo{PathFileInfo{st, fullpath, filepath.Base(cleanpath)}, sum} fi := &HashedFileInfo{PathFileInfo{st, fullpath, filepath.Base(cleanpath)}, sum}

View file

@ -590,6 +590,39 @@ ADD %s/file /`
} }
// Regression for https://github.com/docker/docker/pull/27805
// Makes sure that we don't use the cache if the contents of
// a file in a subfolder of the context is modified and we re-build.
func (s *DockerSuite) TestBuildModifyFileInFolder(c *check.C) {
name := "testbuildmodifyfileinfolder"
ctx, err := fakeContext(`FROM busybox
RUN ["mkdir", "/test"]
ADD folder/file /test/changetarget`,
map[string]string{})
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if err := ctx.Add("folder/file", "first"); err != nil {
c.Fatal(err)
}
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
}
if err := ctx.Add("folder/file", "second"); err != nil {
c.Fatal(err)
}
id2, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
}
if id1 == id2 {
c.Fatal("cache was used even though file contents in folder was changed")
}
}
func (s *DockerSuite) TestBuildAddSingleFileToRoot(c *check.C) { func (s *DockerSuite) TestBuildAddSingleFileToRoot(c *check.C) {
testRequires(c, DaemonIsLinux) // Linux specific test testRequires(c, DaemonIsLinux) // Linux specific test
name := "testaddimg" name := "testaddimg"

View file

@ -578,21 +578,21 @@ func (f *FakeContext) Add(file, content string) error {
} }
func (f *FakeContext) addFile(file string, content []byte) error { func (f *FakeContext) addFile(file string, content []byte) error {
filepath := path.Join(f.Dir, file) fp := filepath.Join(f.Dir, filepath.FromSlash(file))
dirpath := path.Dir(filepath) dirpath := filepath.Dir(fp)
if dirpath != "." { if dirpath != "." {
if err := os.MkdirAll(dirpath, 0755); err != nil { if err := os.MkdirAll(dirpath, 0755); err != nil {
return err return err
} }
} }
return ioutil.WriteFile(filepath, content, 0644) return ioutil.WriteFile(fp, content, 0644)
} }
// Delete a file at a path // Delete a file at a path
func (f *FakeContext) Delete(file string) error { func (f *FakeContext) Delete(file string) error {
filepath := path.Join(f.Dir, file) fp := filepath.Join(f.Dir, filepath.FromSlash(file))
return os.RemoveAll(filepath) return os.RemoveAll(fp)
} }
// Close deletes the context // Close deletes the context