diff options
author | Özgür Kesim <oec@codeblau.de> | 2025-08-15 11:23:11 +0200 |
---|---|---|
committer | Özgür Kesim <oec@codeblau.de> | 2025-08-15 11:23:11 +0200 |
commit | 86d626fd8d98484a7e7f01c9d15f4a8100c8c909 (patch) | |
tree | 708b882bb25e64947e88d8af5f603d67fd818e4c | |
parent | 15f17c5c92b1421dfe08d292b475b2d91772d6ab (diff) |
fixed recursion
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | main.go | 36 |
3 files changed, 36 insertions, 6 deletions
@@ -1,5 +1,5 @@ module kesim.org/goosebumps -go 1.16 +go 1.25 -require golang.org/x/mod v0.4.2 +require golang.org/x/mod v0.27.0 // indirect @@ -2,6 +2,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= +golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -7,7 +7,6 @@ import ( "go/parser" "go/token" "io/fs" - "io/ioutil" "log" "os" "path/filepath" @@ -18,7 +17,8 @@ import ( ) var ( - file = flag.String("mod", "go.mod", "go.mod file") + dir = flag.String("d", ".", "directory with go.mod file") + recurse = flag.Bool("r", false, "recursively search for go.mod files") cache = flag.String("modcache", getmodcache(), "location of go mod cache") excheckm = flag.String("exempt", "golang.org", "domains exempt from the search, seperated by space") @@ -54,20 +54,35 @@ func main() { return } - data, err := ioutil.ReadFile(*file) + if !*recurse { + file := filepath.Join(*dir, "go.mod") + singleFile(file) + return + } + + recursive(*dir) +} + +func singleFile(file string) { + data, err := os.ReadFile(file) if err != nil { log.Fatal(err) } - mf, err := modfile.Parse(*file, data, nil) + mf, err := modfile.Parse(file, data, nil) if err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(len(mf.Require)) + pathcache := map[string]bool{} for _, r := range mf.Require { path := strings.Join(r.Syntax.Token, "@") + if _, done := pathcache[path]; done { + continue + } + pathcache[path] = true go func() { defer wg.Done() checkPath(*cache + "/" + path) @@ -75,7 +90,20 @@ func main() { } wg.Wait() +} +func recursive(dir string) { + filepath.WalkDir(dir, func(p string, info fs.DirEntry, err error) error { + if err != nil { + return err + } else if info.IsDir() { + return nil + } else if "go.mod" == filepath.Base(p) { + fmt.Printf("analyzing %s\n", p) + singleFile(p) + } + return nil + }) } func isExempt(path string) bool { |