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()