Skip to content

Commit

Permalink
Merge pull request #330 from priyawadhwa/bug
Browse files Browse the repository at this point in the history
Make sure paths are absolute before matching files to wildcard sources
  • Loading branch information
priyawadhwa committed Aug 31, 2018
2 parents 9cc1d27 + 1513295 commit 2e10d27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/command_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var matchSourcesTests = []struct {
{
srcs: []string{
"pkg/*",
"/root/dir?",
testUrl,
},
files: []string{
Expand All @@ -227,8 +228,10 @@ var matchSourcesTests = []struct {
"/pkg/d",
"pkg/b/d/",
"dir/",
"root/dir1",
},
expectedFiles: []string{
"/root/dir1",
"pkg/a",
"pkg/b",
testUrl,
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 2e10d27

Please sign in to comment.