Handle site packages based on which egg file is parsed

Signed-off-by: Dan Luhring <dan.luhring@anchore.com>
This commit is contained in:
Dan Luhring 2020-12-22 17:41:27 -05:00
parent 558781eed6
commit 183b8f79d0
No known key found for this signature in database
GPG Key ID: 9CEE23D079426CEF

View File

@ -3,6 +3,7 @@ package python
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"github.com/anchore/syft/internal/file"
"io" "io"
"path/filepath" "path/filepath"
"strings" "strings"
@ -70,11 +71,28 @@ func parseWheelOrEggMetadata(path string, reader io.Reader) (pkg.PythonPackageMe
// add additional metadata not stored in the egg/wheel metadata file // add additional metadata not stored in the egg/wheel metadata file
metadata.SitePackagesRootPath = filepath.Clean(filepath.Join(filepath.Dir(path), "..")) metadata.SitePackagesRootPath = determineSitePackagesRootPath(path)
return metadata, nil return metadata, nil
} }
// isEggRegularFile determines if the specified path is the regular file variant
// of egg metadata (as opposed to a directory that contains more metadata
// files).
func isEggRegularFile(path string) bool {
return file.GlobMatch(eggFileMetadataGlob, path)
}
// determineSitePackagesRootPath returns the path of the site packages root,
// given the egg metadata file or directory specified in the path.
func determineSitePackagesRootPath(path string) string {
if isEggRegularFile(path) {
return filepath.Clean(filepath.Dir(path))
}
return filepath.Clean(filepath.Dir(filepath.Dir(path)))
}
// handleFieldBodyContinuation returns the updated value for the specified field after processing the specified line. // handleFieldBodyContinuation returns the updated value for the specified field after processing the specified line.
// If the continuation cannot be processed, it returns an error. // If the continuation cannot be processed, it returns an error.
func handleFieldBodyContinuation(key, line string, fields map[string]string) (string, error) { func handleFieldBodyContinuation(key, line string, fields map[string]string) (string, error) {