stop if found in cache

This commit is contained in:
Mark Bates 2019-08-18 17:38:21 +01:00
parent ba18a032ae
commit eda2fccb1d
2 changed files with 13 additions and 0 deletions

View File

@ -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)
}
}

View File

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