-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
fix(cli): Handle empty ignore files more gracefully #7962
base: main
Are you sure you want to change the base?
Conversation
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.
It looks good! I left small comments.
log.Debug("Found an ignore yaml", log.FilePath(ignoreFile)) | ||
|
||
// Parse the YAML content | ||
var ignoreConfig IgnoreConfig | ||
if err = yaml.NewDecoder(f).Decode(&ignoreConfig); err != nil { | ||
if err = yaml.Unmarshal(b, &ignoreConfig); err != nil { |
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.
Decode
is better in terms of memory efficiency. We should leave a comment explaining why we use Unmarshal
here. Otherwise, someone may change it back in the future for performance reasons.
@@ -184,7 +184,8 @@ func (c *IgnoreConfig) MatchLicense(licenseID, filePath string) *IgnoreFinding { | |||
func ParseIgnoreFile(ctx context.Context, ignoreFile string) (IgnoreConfig, error) { | |||
var conf IgnoreConfig | |||
if _, err := os.Stat(ignoreFile); errors.Is(err, fs.ErrNotExist) { | |||
// .trivyignore doesn't necessarily exist | |||
// .trivyignore doesn't necessarily exist or maybe empty |
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.
Empty files are not handled here now.
// .trivyignore doesn't necessarily exist or maybe empty | |
// .trivyignore doesn't necessarily exist |
Description
Also adds a log message to the debug stream when such a case occurs.
Related issues
Checklist