hearts of palm

This commit is contained in:
Mark Bates 2019-08-18 17:54:59 +01:00
parent eda2fccb1d
commit 9c88246fad
5 changed files with 7 additions and 36 deletions

View File

@ -1,13 +1,13 @@
TAGS ?= "" TAGS ?= ""
GO_BIN ?= "go" GO_BIN ?= "go"
tidy:
$(GO_BIN) mod tidy
install: tidy install: tidy
cd ./cmd/pkger && $(GO_BIN) install -tags ${TAGS} -v . cd ./cmd/pkger && $(GO_BIN) install -tags ${TAGS} -v .
make tidy make tidy
tidy:
$(GO_BIN) mod tidy
build: tidy build: tidy
$(GO_BIN) build -v . $(GO_BIN) build -v .
make tidy make tidy

BIN
internal/examples/walk/walk Executable file

Binary file not shown.

View File

@ -45,27 +45,11 @@ func Parse(name string) (Results, error) {
root = filepath.Join(her.Dir, root) root = filepath.Join(her.Dir, root)
} }
if !strings.HasPrefix(root, her.Dir) {
_, err = os.Stat(filepath.Join(root, "go.mod"))
if err == nil {
return Results{}, nil
}
}
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() {
if path != her.Dir {
_, err = os.Stat(filepath.Join(path, "go.mod"))
if err == nil {
return filepath.SkipDir
}
}
}
base := filepath.Base(path) base := filepath.Base(path)
for _, ig := range DefaultIgnoredFolders { for _, ig := range DefaultIgnoredFolders {
@ -154,25 +138,11 @@ func sourceFiles(pt pkger.Path) ([]pkger.Path, error) {
return res, nil return res, nil
} }
c, err := pkger.Stat()
if err != nil {
return res, err
}
err = filepath.Walk(fp, func(p string, info os.FileInfo, err error) error { err = filepath.Walk(fp, func(p string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if info.IsDir() {
if p != c.Dir {
_, err = os.Stat(filepath.Join(p, "go.mod"))
if err == nil {
return filepath.SkipDir
}
}
}
base := filepath.Base(p) base := filepath.Base(p)
if base == "." { if base == "." {

View File

@ -20,6 +20,8 @@ var pathsCache = &pathsMap{}
var curOnce = &sync.Once{} var curOnce = &sync.Once{}
var currentInfo here.Info var currentInfo here.Info
var packed bool
var packMU = &sync.RWMutex{} var packMU = &sync.RWMutex{}
func dubeg(key, format string, args ...interface{}) { func dubeg(key, format string, args ...interface{}) {
@ -28,6 +30,7 @@ func dubeg(key, format string, args ...interface{}) {
} }
func Unpack(ind string) error { func Unpack(ind string) error {
packed = true
packMU.Lock() packMU.Lock()
defer packMU.Unlock() defer packMU.Unlock()
b, err := hex.DecodeString(ind) b, err := hex.DecodeString(ind)

View File

@ -17,7 +17,6 @@ func Walk(p string, wf WalkFunc) error {
return err return err
} }
var cacheFound bool
filesCache.Range(func(k Path, v *File) bool { filesCache.Range(func(k Path, v *File) bool {
if k.Pkg != pt.Pkg { if k.Pkg != pt.Pkg {
return true return true
@ -25,7 +24,6 @@ func Walk(p string, wf WalkFunc) error {
if !strings.HasPrefix(k.Name, pt.Name) { if !strings.HasPrefix(k.Name, pt.Name) {
return true return true
} }
cacheFound = true
if err = wf(k, v.info); err != nil { if err = wf(k, v.info); err != nil {
if err == filepath.SkipDir { if err == filepath.SkipDir {
return true return true
@ -35,7 +33,7 @@ func Walk(p string, wf WalkFunc) error {
return true return true
}) })
if cacheFound { if packed {
return nil return nil
} }