Skip to content

Commit

Permalink
include all file types when looking at all files
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman committed Feb 15, 2022
1 parent 7b51519 commit 74c48cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
24 changes: 12 additions & 12 deletions syft/file/all_regular_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 2 additions & 6 deletions syft/file/classification_cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions syft/file/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>[0-9]+\.[0-9]+\.[0-9]+)`,
Expand Down

0 comments on commit 74c48cf

Please sign in to comment.