mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
fix: separate golang license caches from mod dir (#2852)
Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package directorysource
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/anchore/syft/internal/cache"
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/syft/internal/fileresolver"
|
||||
)
|
||||
|
||||
// we do not want to cache things and then subsequently scan them, if, for example a user runs `syft /` twice
|
||||
func excludeCachePathVisitors() []fileresolver.PathIndexVisitor {
|
||||
var out []fileresolver.PathIndexVisitor
|
||||
for _, dir := range cache.GetManager().RootDirs() {
|
||||
out = append(out, excludeCacheDirPathVisitor{
|
||||
dir: dir,
|
||||
}.excludeCacheDir)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type excludeCacheDirPathVisitor struct {
|
||||
dir string
|
||||
}
|
||||
|
||||
func (d excludeCacheDirPathVisitor) excludeCacheDir(_, path string, _ os.FileInfo, _ error) error {
|
||||
if strings.HasPrefix(path, d.dir) {
|
||||
log.Tracef("skipping cache path: %s", path)
|
||||
return fileresolver.ErrSkipPath
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -142,6 +142,9 @@ func (s *directorySource) FileResolver(_ source.Scope) (file.Resolver, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// this should be the only file resolver that might have overlap with where files are cached
|
||||
exclusionFunctions = append(exclusionFunctions, excludeCachePathVisitors()...)
|
||||
|
||||
res, err := fileresolver.NewFromDirectory(s.config.Path, s.config.Base, exclusionFunctions...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create directory resolver: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user