From b2ca5fbf893c496a670727233b149b828ffbdbf8 Mon Sep 17 00:00:00 2001 From: William Murphy Date: Thu, 9 May 2024 13:08:58 -0400 Subject: [PATCH] fix Windows file paths in local go mod cache (#2654) Previously, the file resolver was created from incorrect calls (path.Join instead of filepath.Join) which resulted Go license searches always missing on Windows. Use filepath.* functions when initializing the Go config, and when the unindexed file resolver is being created. Signed-off-by: Will Murphy --- syft/internal/fileresolver/unindexed_directory.go | 9 +++++---- syft/pkg/cataloger/golang/config.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/syft/internal/fileresolver/unindexed_directory.go b/syft/internal/fileresolver/unindexed_directory.go index ee9e73af36b..4037cc1a817 100644 --- a/syft/internal/fileresolver/unindexed_directory.go +++ b/syft/internal/fileresolver/unindexed_directory.go @@ -8,6 +8,7 @@ import ( "io/fs" "os" "path" + "path/filepath" "slices" "sort" "strings" @@ -61,11 +62,11 @@ func NewFromUnindexedDirectoryFS(fs afero.Fs, dir string, base string) file.Writ } wd, err := os.Getwd() if err == nil { - if !path.IsAbs(dir) { - dir = path.Clean(path.Join(wd, dir)) + if !filepath.IsAbs(dir) { + dir = filepath.Clean(filepath.Join(wd, dir)) } - if base != "" && !path.IsAbs(base) { - base = path.Clean(path.Join(wd, base)) + if base != "" && !filepath.IsAbs(base) { + base = filepath.Clean(filepath.Join(wd, base)) } } return UnindexedDirectory{ diff --git a/syft/pkg/cataloger/golang/config.go b/syft/pkg/cataloger/golang/config.go index b8c7ece5a87..e55ed5d0bda 100644 --- a/syft/pkg/cataloger/golang/config.go +++ b/syft/pkg/cataloger/golang/config.go @@ -2,7 +2,7 @@ package golang import ( "os" - "path" + "path/filepath" "strings" "github.com/mitchellh/go-homedir" @@ -75,11 +75,11 @@ func DefaultCatalogerConfig() CatalogerConfig { if err != nil { log.Debug("unable to determine user home dir: %v", err) } else { - goPath = path.Join(homeDir, "go") + goPath = filepath.Join(homeDir, "go") } } if goPath != "" { - g.LocalModCacheDir = path.Join(goPath, "pkg", "mod") + g.LocalModCacheDir = filepath.Join(goPath, "pkg", "mod") } } return g