浏览代码

Potential fix for ADD .

Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Frank Macreery 11 年之前
父节点
当前提交
93ff70a3e7
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 3 1
      buildfile.go
  2. 20 0
      integration/buildfile_test.go

+ 3 - 1
buildfile.go

@@ -421,7 +421,9 @@ func (b *buildFile) CmdAdd(args string) error {
 		} else if fi.IsDir() {
 		} else if fi.IsDir() {
 			var subfiles []string
 			var subfiles []string
 			for file, sum := range sums {
 			for file, sum := range sums {
-				if strings.HasPrefix(file, origPath) {
+				absFile := path.Join(b.contextPath, file)
+				absOrigPath := path.Join(b.contextPath, origPath)
+				if strings.HasPrefix(absFile, absOrigPath) {
 					subfiles = append(subfiles, sum)
 					subfiles = append(subfiles, sum)
 				}
 				}
 			}
 			}

+ 20 - 0
integration/buildfile_test.go

@@ -592,6 +592,26 @@ func TestBuildADDLocalFileWithoutCache(t *testing.T) {
 	checkCacheBehavior(t, template, false)
 	checkCacheBehavior(t, template, false)
 }
 }
 
 
+func TestBuildADDCurrentDirectoryWithCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        add . /usr/lib/bla
+        `,
+		nil, nil}
+	checkCacheBehavior(t, template, true)
+}
+
+func TestBuildADDCurrentDirectoryWithoutCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        add . /usr/lib/bla
+        `,
+		nil, nil}
+	checkCacheBehavior(t, template, false)
+}
+
 func TestBuildADDRemoteFileWithCache(t *testing.T) {
 func TestBuildADDRemoteFileWithCache(t *testing.T) {
 	template := testContextTemplate{`
 	template := testContextTemplate{`
         from {IMAGE}
         from {IMAGE}