Browse Source

Potential fix for ADD .

Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Frank Macreery 11 years ago
parent
commit
93ff70a3e7
2 changed files with 23 additions and 1 deletions
  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() {
 			var subfiles []string
 			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)
 				}
 			}

+ 20 - 0
integration/buildfile_test.go

@@ -592,6 +592,26 @@ func TestBuildADDLocalFileWithoutCache(t *testing.T) {
 	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) {
 	template := testContextTemplate{`
         from {IMAGE}