aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/gobuffalo/packr/box.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gobuffalo/packr/box.go')
-rw-r--r--vendor/github.com/gobuffalo/packr/box.go49
1 files changed, 6 insertions, 43 deletions
diff --git a/vendor/github.com/gobuffalo/packr/box.go b/vendor/github.com/gobuffalo/packr/box.go
index 30eb6e2..d221101 100644
--- a/vendor/github.com/gobuffalo/packr/box.go
+++ b/vendor/github.com/gobuffalo/packr/box.go
@@ -15,6 +15,7 @@ import (
)
var (
+ // ErrResOutsideBox gets returned in case of the requested resources being outside the box
ErrResOutsideBox = errors.New("Can't find a resource outside the box")
)
@@ -51,10 +52,12 @@ type Box struct {
directories map[string]bool
}
+// AddString converts t to a byteslice and delegates to AddBytes to add to b.data
func (b Box) AddString(path string, t string) {
b.AddBytes(path, []byte(t))
}
+// AddBytes sets t in b.data by the given path
func (b Box) AddBytes(path string, t []byte) {
b.data[path] = t
}
@@ -132,14 +135,14 @@ func (b Box) find(name string) (File, error) {
bb = b.decompress(bb)
return newVirtualFile(cleanName, bb), nil
}
+ if _, ok := b.directories[cleanName]; ok {
+ return newVirtualDir(cleanName), nil
+ }
if filepath.Ext(cleanName) != "" {
// The Handler created by http.FileSystem checks for those errors and
// returns http.StatusNotFound instead of http.StatusInternalServerError.
return nil, os.ErrNotExist
}
- if _, ok := b.directories[cleanName]; ok {
- return newVirtualDir(cleanName), nil
- }
return nil, os.ErrNotExist
}
@@ -149,46 +152,6 @@ func (b Box) find(name string) (File, error) {
return fileFor(p, cleanName)
}
-type WalkFunc func(string, File) error
-
-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
-}
-
// Open returns a File using the http.File interface
func (b Box) Open(name string) (http.File, error) {
return b.find(name)