went from 160k os.Stat to 90 on my box. duh
This commit is contained in:
parent
be026e8edc
commit
f5d41d782a
|
@ -0,0 +1,45 @@
|
|||
package forgepb
|
||||
|
||||
import (
|
||||
"go.wit.com/lib/protobuf/gitpb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// this is a final check to make sure, before pushing
|
||||
// a golang repo, that the go.sum file has the correct
|
||||
// and current version of every package
|
||||
//
|
||||
// it re-scans the go.sum file. DOES NOT MODIFY ANYTHING
|
||||
// this is the last thing to run to double check everything
|
||||
// before 'git tag' or git push --tags
|
||||
func (f *Forge) FinalGoDepsCheck(check *gitpb.Repo) bool {
|
||||
var good bool = true
|
||||
if check == nil {
|
||||
log.Info("boo, check == nil")
|
||||
return false
|
||||
}
|
||||
// clear out the protobuf and rescan from the file
|
||||
check.GoDeps = nil
|
||||
check.ParseGoSum()
|
||||
|
||||
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
|
||||
deps := check.GoDeps.SortByGoPath()
|
||||
for deps.Scan() {
|
||||
depRepo := deps.Next()
|
||||
found := f.Repos.FindByGoPath(depRepo.GetGoPath())
|
||||
if found == nil {
|
||||
log.Info("not found:", depRepo.GetGoPath())
|
||||
return false
|
||||
}
|
||||
// log.Info("found dep", depRepo.GetGoPath())
|
||||
if depRepo.GetVersion() != found.GetMasterVersion() {
|
||||
if f.IsReadOnly(depRepo.GetGoPath()) {
|
||||
log.Printf("%-48s ok error %10s vs %10s (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion())
|
||||
} else {
|
||||
log.Printf("%-48s error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion())
|
||||
good = false
|
||||
}
|
||||
}
|
||||
}
|
||||
return good
|
||||
}
|
42
goSrcScan.go
42
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)
|
||||
|
||||
/*
|
||||
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)
|
||||
}
|
||||
}
|
||||
*/
|
||||
return true, err
|
||||
}
|
||||
|
||||
func gitDirectories(srcDir string) ([]string, error) {
|
||||
// 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
|
||||
}
|
||||
|
||||
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 gitDirectoriesOld(srcDir string) ([]string, error) {
|
||||
var all []string
|
||||
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue