Make sure COPY/ADD on dirs doesn't grab too many files

Add check for / first - per LK4D4's comment.
Add a comment to explain why we're adding a /

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis
2014-09-23 14:16:00 -07:00
parent 7e461915a6
commit cd329d062b
2 changed files with 40 additions and 1 deletions
+9 -1
View File
@@ -293,9 +293,17 @@ func calcCopyInfo(b *Builder, cmdName string, ci *copyInfo, allowRemote bool, al
return err
} else if fi.IsDir() {
var subfiles []string
absOrigPath := path.Join(b.contextPath, ci.origPath)
// Add a trailing / to make sure we only
// pick up nested files under the dir and
// not sibling files of the dir that just
// happen to start with the same chars
if !strings.HasSuffix(absOrigPath, "/") {
absOrigPath += "/"
}
for _, fileInfo := range sums {
absFile := path.Join(b.contextPath, fileInfo.Name())
absOrigPath := path.Join(b.contextPath, ci.origPath)
if strings.HasPrefix(absFile, absOrigPath) {
subfiles = append(subfiles, fileInfo.Sum())
}