Skip to content
This repository was archived by the owner on Jun 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/")

Expand Down
26 changes: 14 additions & 12 deletions v2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -69,5 +71,5 @@ func resolutionDir(og string) string {
return ng
}

return og
return ""
}
5 changes: 1 addition & 4 deletions v2/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down