Merge pull request #330 from priyawadhwa/bug

Make sure paths are absolute before matching files to wildcard sources
This commit is contained in:
priyawadhwa 2018-08-31 15:10:25 -07:00 committed by GitHub
commit 2e10d2761c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"path/filepath"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/google/go-containerregistry/pkg/v1"
"github.com/moby/buildkit/frontend/dockerfile/instructions"
"github.com/moby/buildkit/frontend/dockerfile/parser"
@ -116,6 +117,9 @@ func matchSources(srcs, files []string) ([]string, error) {
}
src = filepath.Clean(src)
for _, file := range files {
if filepath.IsAbs(src) {
file = filepath.Join(constants.RootDir, file)
}
matched, err := filepath.Match(src, file)
if err != nil {
return nil, err

View File

@ -219,6 +219,7 @@ var matchSourcesTests = []struct {
{
srcs: []string{
"pkg/*",
"/root/dir?",
testUrl,
},
files: []string{
@ -227,8 +228,10 @@ var matchSourcesTests = []struct {
"/pkg/d",
"pkg/b/d/",
"dir/",
"root/dir1",
},
expectedFiles: []string{
"/root/dir1",
"pkg/a",
"pkg/b",
testUrl,

View File

@ -73,7 +73,7 @@ func GetFSFromImage(root string, img v1.Image) error {
base := filepath.Base(path)
dir := filepath.Dir(path)
if strings.HasPrefix(base, ".wh.") {
logrus.Infof("Whiting out %s", path)
logrus.Debugf("Whiting out %s", path)
name := strings.TrimPrefix(base, ".wh.")
if err := os.RemoveAll(filepath.Join(dir, name)); err != nil {
return errors.Wrapf(err, "removing whiteout %s", hdr.Name)
@ -85,7 +85,7 @@ func GetFSFromImage(root string, img v1.Image) error {
return err
}
if whitelisted && !checkWhitelistRoot(root) {
logrus.Infof("Not adding %s because it is whitelisted", path)
logrus.Debugf("Not adding %s because it is whitelisted", path)
continue
}
if hdr.Typeflag == tar.TypeSymlink {