From eda2fccb1d90c444f70084065c2e4cf70c430e25 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sun, 18 Aug 2019 17:38:21 +0100 Subject: [PATCH] stop if found in cache --- internal/examples/walk/main.go | 7 +++++++ walk.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/internal/examples/walk/main.go b/internal/examples/walk/main.go index 0eb385a..0a3af04 100644 --- a/internal/examples/walk/main.go +++ b/internal/examples/walk/main.go @@ -16,4 +16,11 @@ func main() { if err != nil { log.Fatal(err) } + err = pkger.Walk("/", func(path pkger.Path, info os.FileInfo) error { + fmt.Println(path) + return nil + }) + if err != nil { + log.Fatal(err) + } } diff --git a/walk.go b/walk.go index f2b1ff6..1cdd5b5 100644 --- a/walk.go +++ b/walk.go @@ -17,6 +17,7 @@ func Walk(p string, wf WalkFunc) error { return err } + var cacheFound bool filesCache.Range(func(k Path, v *File) bool { if k.Pkg != pt.Pkg { return true @@ -24,6 +25,7 @@ func Walk(p string, wf WalkFunc) error { if !strings.HasPrefix(k.Name, pt.Name) { return true } + cacheFound = true if err = wf(k, v.info); err != nil { if err == filepath.SkipDir { return true @@ -33,6 +35,10 @@ func Walk(p string, wf WalkFunc) error { return true }) + if cacheFound { + return nil + } + var info here.Info if pt.Pkg == "." { info, err = Stat()