master chld/dgr / cmd / find.go
 1package dgr
 2
 3import (
 4	"io/fs"
 5	"os"
 6	"path/filepath"
 7	"strings"
 8)
 9
10/*
11	find a package in the ports tree
12*/
13
14func FindPkg(pkg string) (string, bool) {
15	var dtrdir string
16	dtrdir = os.Getenv("DTR_DIR")
17	var bool bool = false
18
19	filepath.WalkDir(dtrdir, func(path string, d fs.DirEntry, err error) error {
20		if err != nil {
21			return err // this dont do shit
22			bool = false
23		}
24
25		if d.IsDir() && filepath.Base(path) == pkg { // less permissive, finds correctly
26			pkg = path
27			if !strings.Contains(path, ".git/") {
28				bool = true
29			}
30			return fs.SkipDir // dont go deeper; we found the package
31		}
32		return nil
33	})
34
35	return pkg, bool
36}