Skip to content

Commit

Permalink
feat(listing): add ignorelist for scanning
Browse files Browse the repository at this point in the history
Fixes ossf#1406

Signed-off-by: Furkan <[email protected]>
Co-authored-by: Batuhan <[email protected]>
  • Loading branch information
Dentrax and developer-guy committed Dec 22, 2021
1 parent 3c1e814 commit f5e6279
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions checker/check_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type CheckRequest struct {
OssFuzzRepo clients.RepoClient
Dlogger DetailLogger
Repo clients.Repo
IgnoreDirs []string
// UPGRADEv6: return raw results instead of scores.
RawResults *RawResults
}
26 changes: 20 additions & 6 deletions checks/fileparser/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ func isMatchingPath(pattern, fullpath string, caseSensitive bool) (bool, error)
return match, nil
}

func isTestdataFile(fullpath string) bool {
// testdata/ or /some/dir/testdata/some/other
return strings.HasPrefix(fullpath, "testdata/") ||
strings.Contains(fullpath, "/testdata/")
func containsTestdataFile(fullpath string, ignoreDirs []string) bool {
check := func(name string) bool {
// name/ or /some/dir/name/some/other
return strings.HasPrefix(fullpath, name+"/") ||
strings.Contains(fullpath, "/"+name+"/")
}

if check("testdata") {
return false
}

for _, dir := range ignoreDirs {
if check(dir) {
return false
}
}

return true
}

// FileCbData is any data the caller can act upon
Expand All @@ -79,7 +93,7 @@ func CheckFilesContent(shellPathFnPattern string,
) error {
predicate := func(filepath string) (bool, error) {
// Filter out test files.
if isTestdataFile(filepath) {
if containsTestdataFile(filepath, c.IgnoreDirs) {
return false, nil
}
// Filter out files based on path/names using the pattern.
Expand Down Expand Up @@ -131,7 +145,7 @@ func CheckFilesContentV6(shellPathFnPattern string,
) error {
predicate := func(filepath string) (bool, error) {
// Filter out test files.
if isTestdataFile(filepath) {
if containsTestdataFile(filepath, []string{}) {
return false, nil
}
// Filter out files based on path/names using the pattern.
Expand Down

0 comments on commit f5e6279

Please sign in to comment.