Compare commits
No commits in common. "d7e3dfdb0f8c5a23f3f5e39393c7bf8ca5950686" and "9049abc682c745f4028a5c074a084488cf2b0edd" have entirely different histories.
d7e3dfdb0f
...
9049abc682
17
ricefs/fs.go
17
ricefs/fs.go
@ -11,27 +11,10 @@ import (
|
|||||||
|
|
||||||
var _ afero.Fs = &RiceFs{}
|
var _ afero.Fs = &RiceFs{}
|
||||||
|
|
||||||
// FindFs tries to find a rice.Box by its name and wraps in into a RiceFs.
|
|
||||||
func FindFs(name string) (*RiceFs, error) {
|
|
||||||
box, err := rice.FindBox(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return NewFs(box), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFs creates a new RiceFs based on the supplied rice.Box.
|
|
||||||
func NewFs(b *rice.Box) *RiceFs {
|
func NewFs(b *rice.Box) *RiceFs {
|
||||||
return &RiceFs{b}
|
return &RiceFs{b}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustFindFs tries to find a rice.Box by its name and wraps in into a RiceFs. If the box is not found the method panics.
|
|
||||||
func MustFindFs(name string) *RiceFs {
|
|
||||||
box := rice.MustFindBox(name)
|
|
||||||
return NewFs(box)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RiceFs represents an afero.Fs based on an underlying rice.Box.
|
|
||||||
type RiceFs struct {
|
type RiceFs struct {
|
||||||
Box *rice.Box
|
Box *rice.Box
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@ import (
|
|||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyDir represents a directory that is mimicked on hard drive.
|
|
||||||
type CopyDir interface {
|
type CopyDir interface {
|
||||||
Fs() afero.Fs
|
|
||||||
Retrieve(name string) (string, error)
|
Retrieve(name string) (string, error)
|
||||||
Path(name string) string
|
Path(name string) string
|
||||||
Open(name string) (*os.File, error)
|
Open(name string) (*os.File, error)
|
||||||
@ -33,8 +31,6 @@ func NewCopyDir(fs afero.Fs) (CopyDir, error) {
|
|||||||
return ©Dir{fs, dir}, nil
|
return ©Dir{fs, dir}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *copyDir) Fs() afero.Fs { return d.fs }
|
|
||||||
|
|
||||||
func (d *copyDir) Retrieve(name string) (string, error) {
|
func (d *copyDir) Retrieve(name string) (string, error) {
|
||||||
var path = d.Path(name)
|
var path = d.Path(name)
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
|
@ -20,12 +20,6 @@ func NewFallbackFs(source, backup afero.Fs) *FallbackFs {
|
|||||||
return &FallbackFs{source, backup}
|
return &FallbackFs{source, backup}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOsFsFallback creates a new Fs based on the os package, restricts access on the supplied path and uses backup as fallback.
|
|
||||||
func NewOsFsFallback(path string, backup afero.Fs) *FallbackFs {
|
|
||||||
osFs := afero.NewOsFs()
|
|
||||||
return NewFallbackFs(afero.NewBasePathFs(osFs, path), backup)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FallbackFs) do(action func(afero.Fs) error) error {
|
func (f *FallbackFs) do(action func(afero.Fs) error) error {
|
||||||
err := action(f.source)
|
err := action(f.source)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user