From 454a560f4c8688e43c0c6ae606eb405daed60115 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 23 Oct 2021 23:03:18 +0200 Subject: [PATCH] Take count of os separator in extraction --- pkg/api/core/image/extract.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/api/core/image/extract.go b/pkg/api/core/image/extract.go index d0185b91..e9805dc1 100644 --- a/pkg/api/core/image/extract.go +++ b/pkg/api/core/image/extract.go @@ -146,26 +146,27 @@ func ExtractFiles( return func(h *tar.Header) (bool, error) { + fileName := filepath.Join(string(os.PathSeparator), h.Name) switch { case len(includes) == 0 && len(excludes) != 0: for _, i := range excludeRegexp { - if i.MatchString(filepath.Join(prefixPath, h.Name)) { + if i.MatchString(filepath.Join(prefixPath, fileName)) { return false, nil } } if prefixPath != "" { - return strings.HasPrefix(h.Name, prefixPath), nil + return strings.HasPrefix(fileName, prefixPath), nil } - ctx.Debug("Adding name", h.Name) + ctx.Debug("Adding name", fileName) return true, nil case len(includes) > 0 && len(excludes) == 0: for _, i := range includeRegexp { - if i.MatchString(filepath.Join(prefixPath, h.Name)) { + if i.MatchString(filepath.Join(prefixPath, fileName)) { if prefixPath != "" { return strings.HasPrefix(h.Name, prefixPath), nil } - ctx.Debug("Adding name", h.Name) + ctx.Debug("Adding name", fileName) return true, nil } @@ -173,16 +174,16 @@ func ExtractFiles( return false, nil case len(includes) != 0 && len(excludes) != 0: for _, i := range includeRegexp { - if i.MatchString(filepath.Join(prefixPath, h.Name)) { + if i.MatchString(filepath.Join(prefixPath, fileName)) { for _, e := range excludeRegexp { - if e.MatchString(filepath.Join(prefixPath, h.Name)) { + if e.MatchString(filepath.Join(prefixPath, fileName)) { return false, nil } } if prefixPath != "" { - return strings.HasPrefix(h.Name, prefixPath), nil + return strings.HasPrefix(fileName, prefixPath), nil } - ctx.Debug("Adding name", h.Name) + ctx.Debug("Adding name", fileName) return true, nil } @@ -190,7 +191,7 @@ func ExtractFiles( return false, nil default: if prefixPath != "" { - return strings.HasPrefix(h.Name, prefixPath), nil + return strings.HasPrefix(fileName, prefixPath), nil } return true, nil