Skip to content

Commit

Permalink
fix Windows file paths in local go mod cache (#2654)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
willmurphyscode authored May 9, 2024
1 parent 1892f24 commit b2ca5fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions syft/internal/fileresolver/unindexed_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/fs"
"os"
"path"
"path/filepath"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions syft/pkg/cataloger/golang/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package golang

import (
"os"
"path"
"path/filepath"
"strings"

"github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2ca5fb

Please sign in to comment.