github.com/anchore/syft@v1.38.2/syft/source/directorysource/cache_excludes.go (about) 1 package directorysource 2 3 import ( 4 "os" 5 "strings" 6 7 "github.com/anchore/syft/internal/cache" 8 "github.com/anchore/syft/internal/log" 9 "github.com/anchore/syft/syft/internal/fileresolver" 10 ) 11 12 // we do not want to cache things and then subsequently scan them, if, for example a user runs `syft /` twice 13 func excludeCachePathVisitors() []fileresolver.PathIndexVisitor { 14 var out []fileresolver.PathIndexVisitor 15 for _, dir := range cache.GetManager().RootDirs() { 16 out = append(out, excludeCacheDirPathVisitor{ 17 dir: dir, 18 }.excludeCacheDir) 19 } 20 return out 21 } 22 23 type excludeCacheDirPathVisitor struct { 24 dir string 25 } 26 27 func (d excludeCacheDirPathVisitor) excludeCacheDir(_, path string, _ os.FileInfo, _ error) error { 28 if strings.HasPrefix(path, d.dir) { 29 log.Tracef("skipping cache path: %s", path) 30 return fileresolver.ErrSkipPath 31 } 32 return nil 33 }