diff --git a/v2/box.go b/v2/box.go index ab2a290..bd4bdde 100644 --- a/v2/box.go +++ b/v2/box.go @@ -186,7 +186,7 @@ func (b *Box) List() []string { } // Resolve will attempt to find the file in the box, -// returning an error if the find can not be found. +// returning an error if the file can not be found. func (b *Box) Resolve(key string) (file.File, error) { key = strings.TrimPrefix(key, "/") diff --git a/v2/helpers.go b/v2/helpers.go index 072afcb..4e20a9f 100644 --- a/v2/helpers.go +++ b/v2/helpers.go @@ -7,16 +7,24 @@ import ( "strings" "github.com/gobuffalo/envy" + "github.com/gobuffalo/packr/v2/file/resolver" "github.com/gobuffalo/packr/v2/plog" ) func construct(name string, path string) *Box { + var dr resolver.Resolver + rd := resolutionDir(path) + if len(rd) > 0 { + dr = &resolver.Disk{Root: resolver.OsPath(rd)} + } + return &Box{ - Path: path, - Name: name, - ResolutionDir: resolutionDir(path), - resolvers: resolversMap{}, - dirs: dirsMap{}, + Path: path, + Name: name, + ResolutionDir: rd, + DefaultResolver: dr, + resolvers: resolversMap{}, + dirs: dirsMap{}, } } @@ -49,12 +57,6 @@ func resolutionDirExists(s, og string) bool { } func resolutionDir(og string) string { - ng, _ := filepath.Abs(og) - - if resolutionDirExists(ng, og) { - return ng - } - // packr.New _, filename, _, _ := runtime.Caller(3) ng, ok := resolutionDirTestFilename(filename, og) @@ -69,5 +71,5 @@ func resolutionDir(og string) string { return ng } - return og + return "" } diff --git a/v2/walk.go b/v2/walk.go index 514631c..1be8414 100644 --- a/v2/walk.go +++ b/v2/walk.go @@ -18,15 +18,12 @@ func (b *Box) Walk(wf WalkFunc) error { m := map[string]file.File{} dr := b.DefaultResolver - if dr == nil { - cd := resolver.OsPath(b.ResolutionDir) - dr = &resolver.Disk{Root: cd} - } if fm, ok := dr.(file.FileMappable); ok { for n, f := range fm.FileMap() { m[n] = f } } + var err error b.resolvers.Range(func(n string, r resolver.Resolver) bool { var f file.File