Skip to content
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

🐛 Return empty python packages if dir does not exist. #5132

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
33 changes: 16 additions & 17 deletions providers/os/resources/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ import (
"go.mondoo.com/cnquery/v11/types"
)

var (
defaultPythonPaths = []string{
// Linux
"/usr/local/lib/python*",
"/usr/local/lib64/python*",
"/usr/lib/python*",
"/usr/lib64/python*",
// Windows
"C:\\Python*\\Lib",
// macOS
"/opt/homebrew/lib/python*",
"/System/Library/Frameworks/Python.framework/Versions/*/lib/python*",
// we use 3.x to exclude the macOS 'Current' symlink
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.*/lib/python*",
}
)
var defaultPythonPaths = []string{
// Linux
"/usr/local/lib/python*",
"/usr/local/lib64/python*",
"/usr/lib/python*",
"/usr/lib64/python*",
// Windows
"C:\\Python*\\Lib",
// macOS
"/opt/homebrew/lib/python*",
"/System/Library/Frameworks/Python.framework/Versions/*/lib/python*",
// we use 3.x to exclude the macOS 'Current' symlink
"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.*/lib/python*",
}

func initPython(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) {
if x, ok := args["path"]; ok {
Expand Down Expand Up @@ -210,8 +208,9 @@ func collectPythonPackages(runtime *plugin.Runtime, fs afero.Fs, path string) ([

fileList, err := afs.ReadDir(path)
if err != nil {
if !os.IsNotExist(err) {
if os.IsNotExist(err) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the ! felt wrong to me, i think this should be just if os.IsNotExist instead of if !os...

log.Warn().Err(err).Str("dir", path).Msg("unable to open directory")
return []python.PackageDetails{}, nil
}
return nil, err
}
Expand Down
Loading