mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
chore: simplify and cleanup
Signed-off-by: Keith Zantow <keith.zantow@anchore.com>
This commit is contained in:
@@ -46,7 +46,7 @@ func (z ZipFileManifest) Add(entry string, info os.FileInfo) {
|
||||
}
|
||||
|
||||
// GlobMatch returns the path keys to files (not directories) that match the given value(s).
|
||||
func (z ZipFileManifest) GlobMatch(caseInsensitive bool, patterns ...string) []string {
|
||||
func (z ZipFileManifest) GlobMatch(patterns ...string) []string {
|
||||
uniqueMatches := strset.New()
|
||||
|
||||
for _, pattern := range patterns {
|
||||
@@ -58,11 +58,7 @@ func (z ZipFileManifest) GlobMatch(caseInsensitive bool, patterns ...string) []s
|
||||
|
||||
// We want to match globs as if entries begin with a leading slash (akin to an absolute path)
|
||||
// so that glob logic is consistent inside and outside of ZIP archives
|
||||
normalizedEntry := normalizeZipEntryName(caseInsensitive, entry)
|
||||
|
||||
if caseInsensitive {
|
||||
pattern = strings.ToLower(pattern)
|
||||
}
|
||||
normalizedEntry := normalizeZipEntryName(entry)
|
||||
|
||||
matches, err := doublestar.Match(pattern, normalizedEntry)
|
||||
if err != nil {
|
||||
@@ -82,10 +78,7 @@ func (z ZipFileManifest) GlobMatch(caseInsensitive bool, patterns ...string) []s
|
||||
}
|
||||
|
||||
// normalizeZipEntryName takes the given path entry and ensures it is prefixed with "/".
|
||||
func normalizeZipEntryName(caseInsensitive bool, entry string) string {
|
||||
if caseInsensitive {
|
||||
entry = strings.ToLower(entry)
|
||||
}
|
||||
func normalizeZipEntryName(entry string) string {
|
||||
if !strings.HasPrefix(entry, "/") {
|
||||
return "/" + entry
|
||||
}
|
||||
|
||||
@@ -122,10 +122,6 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
|
||||
"**/a-file.txt",
|
||||
[]string{"some-dir/a-file.txt"},
|
||||
},
|
||||
{
|
||||
"**/A-file.txt",
|
||||
[]string{"some-dir/a-file.txt"},
|
||||
},
|
||||
{
|
||||
"**/*.zip",
|
||||
[]string{"nested.zip"},
|
||||
@@ -136,7 +132,7 @@ func TestZipFileManifest_GlobMatch(t *testing.T) {
|
||||
t.Run(tc.glob, func(t *testing.T) {
|
||||
glob := tc.glob
|
||||
|
||||
results := z.GlobMatch(true, glob)
|
||||
results := z.GlobMatch(glob)
|
||||
|
||||
require.ElementsMatch(t, tc.expected, results)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user