Просмотр исходного кода

Merge pull request #27805 from Microsoft/jjh/fixbuildercache

Windows: Fix builder cache bug
Vincent Demeester 8 лет назад
Родитель
Сommit
9e206b5512
3 измененных файлов с 39 добавлено и 6 удалено
  1. 1 1
      builder/tarsum.go
  2. 33 0
      integration-cli/docker_cli_build_test.go
  3. 5 5
      integration-cli/docker_utils.go

+ 1 - 1
builder/tarsum.go

@@ -63,7 +63,7 @@ func (c *tarSumContext) Stat(path string) (string, FileInfo, error) {
 	sum := path
 	// Use the checksum of the followed path(not the possible symlink) because
 	// 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()
 	}
 	fi := &HashedFileInfo{PathFileInfo{st, fullpath, filepath.Base(cleanpath)}, sum}

+ 33 - 0
integration-cli/docker_cli_build_test.go

@@ -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) {
 	testRequires(c, DaemonIsLinux) // Linux specific test
 	name := "testaddimg"

+ 5 - 5
integration-cli/docker_utils.go

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