Merge pull request #330 from priyawadhwa/bug
Make sure paths are absolute before matching files to wildcard sources
This commit is contained in:
commit
2e10d2761c
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/GoogleContainerTools/kaniko/pkg/constants"
|
||||||
"github.com/google/go-containerregistry/pkg/v1"
|
"github.com/google/go-containerregistry/pkg/v1"
|
||||||
"github.com/moby/buildkit/frontend/dockerfile/instructions"
|
"github.com/moby/buildkit/frontend/dockerfile/instructions"
|
||||||
"github.com/moby/buildkit/frontend/dockerfile/parser"
|
"github.com/moby/buildkit/frontend/dockerfile/parser"
|
||||||
|
|
@ -116,6 +117,9 @@ func matchSources(srcs, files []string) ([]string, error) {
|
||||||
}
|
}
|
||||||
src = filepath.Clean(src)
|
src = filepath.Clean(src)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
if filepath.IsAbs(src) {
|
||||||
|
file = filepath.Join(constants.RootDir, file)
|
||||||
|
}
|
||||||
matched, err := filepath.Match(src, file)
|
matched, err := filepath.Match(src, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,7 @@ var matchSourcesTests = []struct {
|
||||||
{
|
{
|
||||||
srcs: []string{
|
srcs: []string{
|
||||||
"pkg/*",
|
"pkg/*",
|
||||||
|
"/root/dir?",
|
||||||
testUrl,
|
testUrl,
|
||||||
},
|
},
|
||||||
files: []string{
|
files: []string{
|
||||||
|
|
@ -227,8 +228,10 @@ var matchSourcesTests = []struct {
|
||||||
"/pkg/d",
|
"/pkg/d",
|
||||||
"pkg/b/d/",
|
"pkg/b/d/",
|
||||||
"dir/",
|
"dir/",
|
||||||
|
"root/dir1",
|
||||||
},
|
},
|
||||||
expectedFiles: []string{
|
expectedFiles: []string{
|
||||||
|
"/root/dir1",
|
||||||
"pkg/a",
|
"pkg/a",
|
||||||
"pkg/b",
|
"pkg/b",
|
||||||
testUrl,
|
testUrl,
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ func GetFSFromImage(root string, img v1.Image) error {
|
||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
if strings.HasPrefix(base, ".wh.") {
|
if strings.HasPrefix(base, ".wh.") {
|
||||||
logrus.Infof("Whiting out %s", path)
|
logrus.Debugf("Whiting out %s", path)
|
||||||
name := strings.TrimPrefix(base, ".wh.")
|
name := strings.TrimPrefix(base, ".wh.")
|
||||||
if err := os.RemoveAll(filepath.Join(dir, name)); err != nil {
|
if err := os.RemoveAll(filepath.Join(dir, name)); err != nil {
|
||||||
return errors.Wrapf(err, "removing whiteout %s", hdr.Name)
|
return errors.Wrapf(err, "removing whiteout %s", hdr.Name)
|
||||||
|
|
@ -85,7 +85,7 @@ func GetFSFromImage(root string, img v1.Image) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if whitelisted && !checkWhitelistRoot(root) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
if hdr.Typeflag == tar.TypeSymlink {
|
if hdr.Typeflag == tar.TypeSymlink {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue