From f8e3dea19012ccf05965d10255789eec33c2ebcf Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Thu, 23 Aug 2018 22:51:21 +0100 Subject: Update deps --- vendor/github.com/gobuffalo/packr/walk.go | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 vendor/github.com/gobuffalo/packr/walk.go (limited to 'vendor/github.com/gobuffalo/packr/walk.go') diff --git a/vendor/github.com/gobuffalo/packr/walk.go b/vendor/github.com/gobuffalo/packr/walk.go new file mode 100644 index 0000000..21f2563 --- /dev/null +++ b/vendor/github.com/gobuffalo/packr/walk.go @@ -0,0 +1,63 @@ +package packr + +import ( + "os" + "path/filepath" + "strings" + + "github.com/pkg/errors" +) + +type WalkFunc func(string, File) error + +// Walk will traverse the box and call the WalkFunc for each file in the box/folder. +func (b Box) Walk(wf WalkFunc) error { + if data[b.Path] == nil { + base, err := filepath.EvalSymlinks(filepath.Join(b.callingDir, b.Path)) + if err != nil { + return errors.WithStack(err) + } + return filepath.Walk(base, func(path string, info os.FileInfo, err error) error { + cleanName, err := filepath.Rel(base, path) + if err != nil { + cleanName = strings.TrimPrefix(path, base) + } + cleanName = filepath.ToSlash(filepath.Clean(cleanName)) + cleanName = strings.TrimPrefix(cleanName, "/") + cleanName = filepath.FromSlash(cleanName) + if info == nil || info.IsDir() { + return nil + } + + file, err := fileFor(path, cleanName) + if err != nil { + return err + } + return wf(cleanName, file) + }) + } + for n := range data[b.Path] { + f, err := b.find(n) + if err != nil { + return err + } + err = wf(n, f) + if err != nil { + return err + } + } + return nil +} + +// WalkPrefix will call box.Walk and call the WalkFunc when it finds paths that have a matching prefix +func (b Box) WalkPrefix(prefix string, wf WalkFunc) error { + opre := osPath(prefix) + return b.Walk(func(path string, f File) error { + if strings.HasPrefix(osPath(path), opre) { + if err := wf(path, f); err != nil { + return errors.WithStack(err) + } + } + return nil + }) +} -- cgit v1.2.3