Skip to content

Minor updates for #911 #936

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

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/analyzer/nodes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (

// Information about extracted files.
type fileMetadata struct {
// If true, the file has executable permissions.
// If true, the file is regular and has executable permissions.
isExecutable bool
// If true, contents can be extracted from the filesystem.
isExtractable bool
}

var _ analyzer.Files = (*filesMap)(nil)

// filesMap is an analyzer.Files implementation mapping files extracted from
// filesystem directories. In this implementation the file content is read lazily
// when calls to Get() are made. If an error occurs during content read the map
Expand All @@ -40,7 +42,7 @@ type filesMap struct {
readError error
}

// Components contains the result of a node analyzis, listing the O.S. namespace,
// Components contains the result of a node analysis, listing the OS namespace,
// components and language components.
type Components struct {
OSNamespace *database.Namespace
Expand All @@ -64,7 +66,7 @@ func Analyze(nodeName, rootFSdir string, uncertifiedRHEL bool) (*Components, err
if err != nil {
return nil, nil
}
// File reading errors during analysis are not exposed to DetectFiles, hence we
// File reading errors during analysis are not exposed to DetectComponents, hence we
// check it and if there were any we fail.
if err := files.readErr(); err != nil {
return nil, errors.Wrapf(err, "analysis of node %q failed", nodeName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/nodes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func Test_filesMap_extractFile(t *testing.T) {
wantErr: assert.NoError,
},
{
name: "when file is extractable and size is bigger then the limit then return nothing",
name: "when file is extractable and size is bigger than the limit then return nothing",
maxFileSize: 1, // minimal size set to fail
args: args{
fileMatcherMock: matcherMock{
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/extractfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func (m *FileExtractionMetrics) Emit() {
fileExtractionCountMetric.Observe(m.matchCount)
fileExtractionMatchCountMetric.Observe(m.fileCount)
fileExtractionInaccessibleCountMetric.Observe(m.inaccessibleCount)
*m = FileExtractionMetrics{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the most important one, as without this change, there is potential for nil-dereference

}
*m = FileExtractionMetrics{}
}