Skip to content

Commit

Permalink
refactor(misconf): remove extrafs (#6656)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored May 9, 2024
1 parent 04a6073 commit 357c358
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 95 deletions.
54 changes: 0 additions & 54 deletions pkg/extrafs/extrafs.go

This file was deleted.

24 changes: 1 addition & 23 deletions pkg/iac/scanners/terraform/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/zclconf/go-cty/cty"

"github.com/aquasecurity/trivy/pkg/extrafs"
"github.com/aquasecurity/trivy/pkg/iac/debug"
"github.com/aquasecurity/trivy/pkg/iac/ignore"
"github.com/aquasecurity/trivy/pkg/iac/scanners/options"
Expand Down Expand Up @@ -185,28 +184,7 @@ func (p *Parser) ParseFS(ctx context.Context, dir string) error {
var paths []string
for _, info := range fileInfos {
realPath := path.Join(dir, info.Name())
if info.Type()&os.ModeSymlink != 0 {
extra, ok := p.moduleFS.(extrafs.FS)
if !ok {
// we can't handle symlinks in this fs type for now
p.debug.Log("Cannot resolve symlink '%s' in '%s' for this fs type", info.Name(), dir)
continue
}
realPath, err = extra.ResolveSymlink(info.Name(), dir)
if err != nil {
p.debug.Log("Failed to resolve symlink '%s' in '%s': %s", info.Name(), dir, err)
continue
}
info, err := extra.Stat(realPath)
if err != nil {
p.debug.Log("Failed to stat resolved symlink '%s': %s", realPath, err)
continue
}
if info.IsDir() {
continue
}
p.debug.Log("Resolved symlink '%s' in '%s' to '%s'", info.Name(), dir, realPath)
} else if info.IsDir() {
if info.IsDir() {
continue
}
paths = append(paths, realPath)
Expand Down
19 changes: 1 addition & 18 deletions pkg/iac/scanners/terraform/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"sync"

"github.com/aquasecurity/trivy/pkg/extrafs"
"github.com/aquasecurity/trivy/pkg/iac/debug"
"github.com/aquasecurity/trivy/pkg/iac/framework"
"github.com/aquasecurity/trivy/pkg/iac/rego"
Expand Down Expand Up @@ -281,24 +280,8 @@ func (s *Scanner) findModules(target fs.FS, scanDir string, dirs ...string) []st
continue
}
for _, file := range files {
realPath := path.Join(dir, file.Name())
if symFS, ok := target.(extrafs.ReadLinkFS); ok {
realPath, err = symFS.ResolveSymlink(realPath, scanDir)
if err != nil {
s.debug.Log("failed to resolve symlink '%s': %s", file.Name(), err)
continue
}
}
if file.IsDir() {
others = append(others, realPath)
} else if statFS, ok := target.(fs.StatFS); ok {
info, err := statFS.Stat(filepath.ToSlash(realPath))
if err != nil {
continue
}
if info.IsDir() {
others = append(others, realPath)
}
others = append(others, path.Join(dir, file.Name()))
}
}
}
Expand Down

0 comments on commit 357c358

Please sign in to comment.