From 55bbe7b7aa715a5e611b4d189a4df310e62a0c29 Mon Sep 17 00:00:00 2001 From: Preslav Date: Wed, 29 Jan 2025 11:35:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Return=20empty=20python=20packag?= =?UTF-8?q?es=20if=20dir=20does=20not=20exist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Preslav --- providers/os/resources/python.go | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/providers/os/resources/python.go b/providers/os/resources/python.go index 3b0f8bee4..13848eb36 100644 --- a/providers/os/resources/python.go +++ b/providers/os/resources/python.go @@ -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 { @@ -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) { log.Warn().Err(err).Str("dir", path).Msg("unable to open directory") + return []python.PackageDetails{}, nil } return nil, err }