diff options
| author | Jeff Carr <[email protected]> | 2024-12-02 05:14:52 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-02 05:14:52 -0600 |
| commit | f5d41d782af2c8f04971f88d98d4b641997ae870 (patch) | |
| tree | 1187c09533787242681c91da79b10efc001f8d2b /goSrcScan.go | |
| parent | be026e8edc5a9cac0d8923cc00099c150f97e329 (diff) | |
went from 160k os.Stat to 90 on my box. duh
Diffstat (limited to 'goSrcScan.go')
| -rw-r--r-- | goSrcScan.go | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/goSrcScan.go b/goSrcScan.go index 4e23fed..83a6442 100644 --- a/goSrcScan.go +++ b/goSrcScan.go @@ -2,6 +2,7 @@ package forgepb import ( "errors" + "fmt" "os" "path/filepath" "strings" @@ -12,7 +13,9 @@ import ( ) func (f *Forge) ScanGoSrc() (bool, error) { - dirs, err := gitDirectories(f.goSrc) + log.Info("pre dir walk") + dirs, err := gitDirectoriesNew(f.goSrc) + log.Info("post dir walk", len(dirs)) if err != nil { return false, err } @@ -28,23 +31,34 @@ func (f *Forge) ScanGoSrc() (bool, error) { return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir) } } + log.Info("pre rill") f.rillScanDirs(gopaths) + return true, err +} - /* - for _, dir := range dirs { - if strings.HasPrefix(dir, f.goSrc) { - gopath := strings.TrimPrefix(dir, f.goSrc) - gopath = strings.Trim(gopath, "/") - repo, err := f.Repos.NewGoPath(f.goSrc, gopath) - } else { - log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir) - } +// doesn't enter the directory any further when it finds a .git/ +// not stupid like my old version +func gitDirectoriesNew(srcDir string) ([]string, error) { + var all []string + err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error { + if err != nil { + // Handle possible errors, like permission issues + fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err) + return err } - */ - return true, err + + gitdir := filepath.Join(path, ".git") + _, err2 := os.Stat(gitdir) + if !os.IsNotExist(err2) { + all = append(all, path) + return filepath.SkipDir + } + return nil + }) + return all, err } -func gitDirectories(srcDir string) ([]string, error) { +func gitDirectoriesOld(srcDir string) ([]string, error) { var all []string err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { if err != nil { |
