Skip to content

Commit

Permalink
fix(terraform): ensure consistent path handling across OS
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin committed Feb 19, 2024
1 parent 32a02a9 commit ed197d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/iac/scanners/terraform/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"io/fs"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -195,7 +196,7 @@ func (p *Parser) ParseFile(_ context.Context, fullPath string) error {
// ParseFS parses a root module, where it exists at the root of the provided filesystem
func (p *Parser) ParseFS(ctx context.Context, dir string) error {

dir = filepath.Clean(dir)
dir = path.Clean(dir)

if p.projectRoot == "" {
p.debug.Log("Setting project/module root to '%s'", dir)
Expand All @@ -212,7 +213,7 @@ func (p *Parser) ParseFS(ctx context.Context, dir string) error {

var paths []string
for _, info := range fileInfos {
realPath := filepath.Join(dir, info.Name())
realPath := path.Join(dir, info.Name())
if info.Type()&os.ModeSymlink != 0 {
extra, ok := p.moduleFS.(extrafs.FS)
if !ok {
Expand Down
3 changes: 2 additions & 1 deletion pkg/iac/scanners/terraform/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"io"
"io/fs"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -334,7 +335,7 @@ func (s *Scanner) findRootModules(target fs.FS, scanDir string, dirs ...string)
continue
}
for _, file := range files {
realPath := filepath.Join(dir, file.Name())
realPath := path.Join(dir, file.Name())
if symFS, ok := target.(extrafs.ReadLinkFS); ok {
realPath, err = symFS.ResolveSymlink(realPath, scanDir)
if err != nil {
Expand Down

0 comments on commit ed197d0

Please sign in to comment.