This commit is contained in:
Jeff Carr 2024-12-02 05:15:39 -06:00
parent 425cb042b9
commit 4b83d18db4
3 changed files with 27 additions and 3 deletions

3
.protobuf Normal file
View File

@ -0,0 +1,3 @@
gitTag.proto
goDep.proto
repo.proto

View File

@ -40,7 +40,7 @@ func (repo *Repo) RedoGoMod() (bool, error) {
if repo.Exists("go.sum") { if repo.Exists("go.sum") {
// return the attempt to parse go.mod & go.sum // return the attempt to parse go.mod & go.sum
return repo.parseGoSum() return repo.ParseGoSum()
} }
repo.GoDeps = new(GoDeps) repo.GoDeps = new(GoDeps)
repo.GoPrimitive = false repo.GoPrimitive = false
@ -61,7 +61,8 @@ func (repo *Repo) RedoGoMod() (bool, error) {
} }
// reads and parses the go.sum file // reads and parses the go.sum file
func (repo *Repo) parseGoSum() (bool, error) { // does not change anything
func (repo *Repo) ParseGoSum() (bool, error) {
// empty out what was there before // empty out what was there before
repo.GoDeps = nil repo.GoDeps = nil
tmp := filepath.Join(repo.FullPath, "go.sum") tmp := filepath.Join(repo.FullPath, "go.sum")

View File

@ -57,6 +57,8 @@ func (repo *Repo) IsProtobuf() (bool, []string, error) {
return anyfound, allc, err return anyfound, allc, err
} }
// look for any proto files. do not enter directories
// note: good golang libraries are best done in a single directory
func scanForProtobuf(srcDir string) ([]string, []string, error) { func scanForProtobuf(srcDir string) ([]string, []string, error) {
var protofiles []string var protofiles []string
var compiled []string var compiled []string
@ -66,6 +68,11 @@ func scanForProtobuf(srcDir string) ([]string, []string, error) {
return err return err
} }
// ignore the start dir
if srcDir == path {
return nil
}
if strings.HasSuffix(path, ".proto") { if strings.HasSuffix(path, ".proto") {
// //
protofiles = append(protofiles, path) protofiles = append(protofiles, path)
@ -75,6 +82,10 @@ func scanForProtobuf(srcDir string) ([]string, []string, error) {
compiled = append(compiled, path) compiled = append(compiled, path)
} }
// don't go into any directories
if info.IsDir() {
return filepath.SkipDir
}
return nil return nil
}) })
@ -83,17 +94,26 @@ func scanForProtobuf(srcDir string) ([]string, []string, error) {
func (repo *Repo) GetProtoFiles() ([]string, error) { func (repo *Repo) GetProtoFiles() ([]string, error) {
var protofiles []string var protofiles []string
err := filepath.Walk(repo.GetFullPath(), func(path string, info os.FileInfo, err error) error { srcDir := repo.GetFullPath()
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
log.Log(GITPBWARN, "Error accessing path:", path, err) log.Log(GITPBWARN, "Error accessing path:", path, err)
return err return err
} }
// ignore the start dir
if srcDir == path {
return nil
}
if strings.HasSuffix(path, ".proto") { if strings.HasSuffix(path, ".proto") {
// //
protofiles = append(protofiles, path) protofiles = append(protofiles, path)
} }
if info.IsDir() {
return filepath.SkipDir
}
return nil return nil
}) })