From 93ff70a3e70e14762314f04e2b9f61c8710d5353 Mon Sep 17 00:00:00 2001 From: Frank Macreery Date: Mon, 6 Jan 2014 22:42:57 -0500 Subject: [PATCH] Potential fix for ADD . Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes (github: creack) --- buildfile.go | 4 +++- integration/buildfile_test.go | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/buildfile.go b/buildfile.go index dc86026226..d28d499bfa 100644 --- a/buildfile.go +++ b/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) } } diff --git a/integration/buildfile_test.go b/integration/buildfile_test.go index ef51777390..5dd403274e 100644 --- a/integration/buildfile_test.go +++ b/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}