-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow restricting filesystem walk to specific folders #5481
Conversation
66dc684
to
75aabe4
Compare
@@ -91,5 +100,17 @@ func (w *walker) shouldSkipDir(dir string) bool { | |||
} | |||
} | |||
|
|||
if dir != "." && len(w.onlyDirs) > 0 { | |||
for _, onlyDir := range w.onlyDirs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work with the nested dir? Let's say --only-dirs /*/bar/**
is passed. Then, Trivy walks from the root and reaches /foo
. This function returns false as /*/bar/**
doesn't match /foo
. It never reaches /foo/bar
even though /foo/bar/baz.txt
exists. I may be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct. At first I didn't support wildcards but when rebasing, I saw the use of "doublestar.Match" and switched to it. In this case, it only works with leading "wildcards" - which brings no value - because of the case you mentionned.
I suggest toswitch back to use regular paths. WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the patterns but apply them when considering files. When possible, it also skips some directories to avoid having traversing them.
0fe6eb8
to
7bacd88
Compare
2dd828c
to
f3265c6
Compare
@knqyf263 Could you please have an other look ? Thanks ! |
I'm sorry for the late reply. I'm moving to a new country and busy with paperwork, transportation, etc. |
This PR is stale because it has been labeled with inactivity. |
Description
This PR passes a new parameter to the walker to only parse the files
in a specified set of folders.
This can greatly improve the performance when a specific set of parsers
is used and the required paths for these parsers is known.
Related issues
Related PRs
Remove this section if you don't have related PRs.
Checklist