diff --git a/Makefile b/Makefile index 1f8baf5..19e7dba 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ TAGS ?= "" GO_BIN ?= "go" -tidy: - $(GO_BIN) mod tidy - install: tidy cd ./cmd/pkger && $(GO_BIN) install -tags ${TAGS} -v . make tidy +tidy: + $(GO_BIN) mod tidy + build: tidy $(GO_BIN) build -v . make tidy diff --git a/internal/examples/walk/walk b/internal/examples/walk/walk new file mode 100755 index 0000000..5b4b3b0 Binary files /dev/null and b/internal/examples/walk/walk differ diff --git a/parser/parser.go b/parser/parser.go index 15c67c3..6a9face 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -45,27 +45,11 @@ func Parse(name string) (Results, error) { 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 { if err != nil { 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) for _, ig := range DefaultIgnoredFolders { @@ -154,25 +138,11 @@ func sourceFiles(pt pkger.Path) ([]pkger.Path, error) { 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 { if err != nil { 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) if base == "." { diff --git a/pkger.go b/pkger.go index 0fde63a..7591728 100644 --- a/pkger.go +++ b/pkger.go @@ -20,6 +20,8 @@ var pathsCache = &pathsMap{} var curOnce = &sync.Once{} var currentInfo here.Info +var packed bool + var packMU = &sync.RWMutex{} func dubeg(key, format string, args ...interface{}) { @@ -28,6 +30,7 @@ func dubeg(key, format string, args ...interface{}) { } func Unpack(ind string) error { + packed = true packMU.Lock() defer packMU.Unlock() b, err := hex.DecodeString(ind) diff --git a/walk.go b/walk.go index 1cdd5b5..ec88089 100644 --- a/walk.go +++ b/walk.go @@ -17,7 +17,6 @@ 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 @@ -25,7 +24,6 @@ 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 @@ -35,7 +33,7 @@ func Walk(p string, wf WalkFunc) error { return true }) - if cacheFound { + if packed { return nil }