From e66674d8d4e64ad9838c3d8843a28d2f0a39e8f1 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 15 Feb 2022 18:25:18 -0500 Subject: [PATCH] include all file types when looking at all files Signed-off-by: Alex Goodman --- syft/file/all_regular_files.go | 24 +++++++++++----------- syft/file/classification_cataloger_test.go | 8 ++------ syft/file/classifier.go | 3 +-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/syft/file/all_regular_files.go b/syft/file/all_regular_files.go index 622115927812..6349c518043d 100644 --- a/syft/file/all_regular_files.go +++ b/syft/file/all_regular_files.go @@ -8,25 +8,25 @@ import ( func allRegularFiles(resolver source.FileResolver) (locations []source.Location) { for location := range resolver.AllLocations() { - metadata, err := resolver.FileMetadataByLocation(location) + resolvedLocations, err := resolver.FilesByPath(location.RealPath) if err != nil { - log.Warnf("unable to get metadata for %+v: %+v", location, err) + log.Warnf("unable to resolve %+v: %+v", location, err) continue } - // filter out anything that is not a regular file. Why not evaluate symlinks here? All symlinks resolve to - // either a) another path with a file/dir or b) nothing. Any other existing path will already be returned - // from resolver.AllLocations(). + for _, resolvedLocation := range resolvedLocations { + metadata, err := resolver.FileMetadataByLocation(resolvedLocation) + if err != nil { + log.Warnf("unable to get metadata for %+v: %+v", location, err) + continue + } - // TODO: a challenge for the future: can we allow for symlink resolution here for consumers that need to observe file nodes with the virtual paths intact? - // I tried this out but ran into a problem with the directory resolver; the requestPath() call misinterprets the real input path as if it's from - // the root of the resolver directory. - if metadata.Type != source.RegularFile { - continue + if metadata.Type != source.RegularFile { + continue + } + locations = append(locations, resolvedLocation) } - locations = append(locations, location) - } return locations } diff --git a/syft/file/classification_cataloger_test.go b/syft/file/classification_cataloger_test.go index bc34a36f1a12..da6fb37cb7bb 100644 --- a/syft/file/classification_cataloger_test.go +++ b/syft/file/classification_cataloger_test.go @@ -117,11 +117,9 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases(t *testing.T) { actualResults, err := c.Catalog(resolver) test.expectedErr(t, err) - loc := source.NewLocation(test.location) - ok := false for actualLoc, actualClassification := range actualResults { - if loc.RealPath == actualLoc.RealPath { + if test.location == actualLoc.RealPath { ok = true assert.Equal(t, test.expected, actualClassification) } @@ -175,11 +173,9 @@ func TestClassifierCataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T actualResults, err := c.Catalog(resolver) test.expectedErr(t, err) - loc := source.NewLocation(test.location) - ok := false for actuaLoc, actualClassification := range actualResults { - if loc.RealPath == actuaLoc.RealPath { + if actuaLoc.RealPath == test.location { ok = true assert.Equal(t, test.expected, actualClassification) } diff --git a/syft/file/classifier.go b/syft/file/classifier.go index f35bfa34d03a..d4efa538a1e8 100644 --- a/syft/file/classifier.go +++ b/syft/file/classifier.go @@ -52,8 +52,7 @@ var DefaultClassifiers = []Classifier{ { Class: "busybox-binary", FilepathPatterns: []*regexp.Regexp{ - // we match on either files called "busybox" or "[", which busybox tends to link to (at least in the busybox image) - regexp.MustCompile(`(.*/|^)(busybox|\[)$`), + regexp.MustCompile(`(.*/|^)busybox$`), }, EvidencePatternTemplates: []string{ `(?m)BusyBox\s+v(?P[0-9]+\.[0-9]+\.[0-9]+)`,