Merge pull request #63 from riywo/fix/testdata

Update testdata/out
This commit is contained in:
Jim Teeuwen 2014-12-09 12:36:31 +01:00
commit 7159dbfa31
5 changed files with 1214 additions and 186 deletions

View File

@ -3,14 +3,20 @@ package main
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"log" "strings"
"os"
"time"
"io/ioutil"
"path"
"path/filepath"
) )
func bindata_read(data []byte, name string) []byte { func bindata_read(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data)) gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil { if err != nil {
log.Fatalf("Read %q: %v", name, err) return nil, fmt.Errorf("Read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
@ -18,69 +24,271 @@ func bindata_read(data []byte, name string) []byte {
gz.Close() gz.Close()
if err != nil { if err != nil {
log.Fatalf("Read %q: %v", name, err) return nil, fmt.Errorf("Read %q: %v", name, err)
} }
return buf.Bytes() return buf.Bytes(), nil
} }
func in_b_test_asset() []byte { type asset struct {
return bindata_read([]byte{ bytes []byte
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7, info os.FileInfo
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
0x00, 0x00, 0x00,
},
"in/b/test.asset",
)
} }
func in_test_asset() []byte { type bindata_file_info struct {
return bindata_read([]byte{ name string
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7, size int64
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49, mode os.FileMode
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f, modTime time.Time
0x00, 0x00, 0x00,
},
"in/test.asset",
)
} }
func in_a_test_asset() []byte { func (fi bindata_file_info) Name() string {
return bindata_read([]byte{ return fi.name
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7, }
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49, func (fi bindata_file_info) Size() int64 {
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f, return fi.size
0x00, 0x00, 0x00, }
}, func (fi bindata_file_info) Mode() os.FileMode {
return fi.mode
}
func (fi bindata_file_info) ModTime() time.Time {
return fi.modTime
}
func (fi bindata_file_info) IsDir() bool {
return false
}
func (fi bindata_file_info) Sys() interface{} {
return nil
}
var _in_a_test_asset = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00")
func in_a_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_a_test_asset,
"in/a/test.asset", "in/a/test.asset",
) )
} }
func in_c_test_asset() []byte { func in_a_test_asset() (*asset, error) {
return bindata_read([]byte{ bytes, err := in_a_test_asset_bytes()
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7, if err != nil {
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49, return nil, err
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f, }
0x00, 0x00, 0x00,
}, info := bindata_file_info{name: "in/a/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_b_test_asset = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00")
func in_b_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
}
func in_b_test_asset() (*asset, error) {
bytes, err := in_b_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/b/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_c_test_asset = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00")
func in_c_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_c_test_asset,
"in/c/test.asset", "in/c/test.asset",
) )
} }
// Asset loads and returns the asset for the given name. func in_c_test_asset() (*asset, error) {
// This returns nil of the asset could not be found. bytes, err := in_c_test_asset_bytes()
func Asset(name string) []byte { if err != nil {
if f, ok := _bindata[name]; ok { return nil, err
return f()
} }
return nil
info := bindata_file_info{name: "in/c/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_test_asset = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00")
func in_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_test_asset,
"in/test.asset",
)
}
func in_test_asset() (*asset, error) {
bytes, err := in_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{ var _bindata = map[string]func() (*asset, error){
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset, "in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset, "in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -3,13 +3,19 @@ package main
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"log"
"reflect" "reflect"
"strings"
"unsafe" "unsafe"
"os"
"time"
"io/ioutil"
"path"
"path/filepath"
) )
func bindata_read(data, name string) []byte { func bindata_read(data, name string) ([]byte, error) {
var empty [0]byte var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data)) sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:] b := empty[:]
@ -20,7 +26,7 @@ func bindata_read(data, name string) []byte {
gz, err := gzip.NewReader(bytes.NewBuffer(b)) gz, err := gzip.NewReader(bytes.NewBuffer(b))
if err != nil { if err != nil {
log.Fatalf("Read %q: %v", name, err) return nil, fmt.Errorf("Read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
@ -28,61 +34,271 @@ func bindata_read(data, name string) []byte {
gz.Close() gz.Close()
if err != nil { if err != nil {
log.Fatalf("Read %q: %v", name, err) return nil, fmt.Errorf("Read %q: %v", name, err)
} }
return buf.Bytes() return buf.Bytes(), nil
} }
var _in_b_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" type asset struct {
bytes []byte
func in_b_test_asset() []byte { info os.FileInfo
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
} }
var _in_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" type bindata_file_info struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func in_test_asset() []byte { func (fi bindata_file_info) Name() string {
return bindata_read( return fi.name
_in_test_asset, }
"in/test.asset", func (fi bindata_file_info) Size() int64 {
) return fi.size
}
func (fi bindata_file_info) Mode() os.FileMode {
return fi.mode
}
func (fi bindata_file_info) ModTime() time.Time {
return fi.modTime
}
func (fi bindata_file_info) IsDir() bool {
return false
}
func (fi bindata_file_info) Sys() interface{} {
return nil
} }
var _in_a_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" var _in_a_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
func in_a_test_asset() []byte { func in_a_test_asset_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_in_a_test_asset, _in_a_test_asset,
"in/a/test.asset", "in/a/test.asset",
) )
} }
func in_a_test_asset() (*asset, error) {
bytes, err := in_a_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/a/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_b_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
func in_b_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
}
func in_b_test_asset() (*asset, error) {
bytes, err := in_b_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/b/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_c_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00" var _in_c_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
func in_c_test_asset() []byte { func in_c_test_asset_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_in_c_test_asset, _in_c_test_asset,
"in/c/test.asset", "in/c/test.asset",
) )
} }
// Asset loads and returns the asset for the given name. func in_c_test_asset() (*asset, error) {
// This returns nil of the asset could not be found. bytes, err := in_c_test_asset_bytes()
func Asset(name string) []byte { if err != nil {
if f, ok := _bindata[name]; ok { return nil, err
return f()
} }
return nil
info := bindata_file_info{name: "in/c/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
func in_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_test_asset,
"in/test.asset",
)
}
func in_test_asset() (*asset, error) {
bytes, err := in_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{ var _bindata = map[string]func() (*asset, error){
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset, "in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset, "in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

270
testdata/out/debug.go vendored
View File

@ -1,80 +1,248 @@
package main package main
import ( import (
"bytes" "fmt"
"io" "io/ioutil"
"log" "strings"
"os" "os"
"path"
"path/filepath"
) )
// bindata_read reads the given file from disk. // bindata_read reads the given file from disk. It returns an error on failure.
// It panics if anything went wrong. func bindata_read(path, name string) ([]byte, error) {
func bindata_read(path, name string) []byte { buf, err := ioutil.ReadFile(path)
fd, err := os.Open(path)
if err != nil { if err != nil {
log.Fatalf("Read %s: %v", name, err) err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err)
}
return buf, err
}
type asset struct {
bytes []byte
info os.FileInfo
}
// in_a_test_asset reads file data from disk. It returns an error on failure.
func in_a_test_asset() (*asset, error) {
path := "/Users/iwanaga.ryosuke/golang/src/github.com/riywo/go-bindata/testdata/in/a/test.asset"
name := "in/a/test.asset"
bytes, err := bindata_read(path, name)
if err != nil {
return nil, err
} }
defer fd.Close() fi, err := os.Stat(path)
var buf bytes.Buffer
_, err = io.Copy(&buf, fd)
if err != nil { if err != nil {
log.Fatalf("Read %s: %v", name, err) err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
} }
return buf.Bytes() a := &asset{bytes: bytes, info: fi}
return a, err
} }
// in_b_test_asset reads file data from disk. // in_b_test_asset reads file data from disk. It returns an error on failure.
// It panics if something went wrong in the process. func in_b_test_asset() (*asset, error) {
func in_b_test_asset() []byte { path := "/Users/iwanaga.ryosuke/golang/src/github.com/riywo/go-bindata/testdata/in/b/test.asset"
return bindata_read( name := "in/b/test.asset"
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset", bytes, err := bindata_read(path, name)
"in/b/test.asset", if err != nil {
) return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
} }
// in_test_asset reads file data from disk. // in_c_test_asset reads file data from disk. It returns an error on failure.
// It panics if something went wrong in the process. func in_c_test_asset() (*asset, error) {
func in_test_asset() []byte { path := "/Users/iwanaga.ryosuke/golang/src/github.com/riywo/go-bindata/testdata/in/c/test.asset"
return bindata_read( name := "in/c/test.asset"
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset", bytes, err := bindata_read(path, name)
"in/test.asset", if err != nil {
) return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
} }
// in_a_test_asset reads file data from disk. // in_test_asset reads file data from disk. It returns an error on failure.
// It panics if something went wrong in the process. func in_test_asset() (*asset, error) {
func in_a_test_asset() []byte { path := "/Users/iwanaga.ryosuke/golang/src/github.com/riywo/go-bindata/testdata/in/test.asset"
return bindata_read( name := "in/test.asset"
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset", bytes, err := bindata_read(path, name)
"in/a/test.asset", if err != nil {
) return nil, err
} }
// in_c_test_asset reads file data from disk. fi, err := os.Stat(path)
// It panics if something went wrong in the process. if err != nil {
func in_c_test_asset() []byte { err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
return bindata_read( }
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
"in/c/test.asset", a := &asset{bytes: bytes, info: fi}
) return a, err
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found. // It returns an error if the asset could not be found or
func Asset(name string) []byte { // could not be loaded.
if f, ok := _bindata[name]; ok { func Asset(name string) ([]byte, error) {
return f() cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
} }
return nil return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{ var _bindata = map[string]func() (*asset, error){
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset, "in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset, "in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,46 +1,265 @@
package main package main
func in_b_test_asset() []byte { import (
return []byte{ "fmt"
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69, "strings"
0x6c, 0x65, 0x0a, "os"
} "time"
"io/ioutil"
"path"
"path/filepath"
)
type asset struct {
bytes []byte
info os.FileInfo
} }
func in_test_asset() []byte { type bindata_file_info struct {
return []byte{ name string
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69, size int64
0x6c, 0x65, 0x0a, mode os.FileMode
} modTime time.Time
} }
func in_a_test_asset() []byte { func (fi bindata_file_info) Name() string {
return []byte{ return fi.name
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
}
} }
func (fi bindata_file_info) Size() int64 {
func in_c_test_asset() []byte { return fi.size
return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
}
} }
func (fi bindata_file_info) Mode() os.FileMode {
// Asset loads and returns the asset for the given name. return fi.mode
// This returns nil of the asset could not be found. }
func Asset(name string) []byte { func (fi bindata_file_info) ModTime() time.Time {
if f, ok := _bindata[name]; ok { return fi.modTime
return f() }
} func (fi bindata_file_info) IsDir() bool {
return false
}
func (fi bindata_file_info) Sys() interface{} {
return nil return nil
} }
// _bindata is a table, holding each asset generator, mapped to its name. var _in_a_test_asset = []byte(`// sample file
var _bindata = map[string]func() []byte{ `)
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset, func in_a_test_asset_bytes() ([]byte, error) {
"in/a/test.asset": in_a_test_asset, return _in_a_test_asset, nil
"in/c/test.asset": in_c_test_asset,
} }
func in_a_test_asset() (*asset, error) {
bytes, err := in_a_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/a/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_b_test_asset = []byte(`// sample file
`)
func in_b_test_asset_bytes() ([]byte, error) {
return _in_b_test_asset, nil
}
func in_b_test_asset() (*asset, error) {
bytes, err := in_b_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/b/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_c_test_asset = []byte(`// sample file
`)
func in_c_test_asset_bytes() ([]byte, error) {
return _in_c_test_asset, nil
}
func in_c_test_asset() (*asset, error) {
bytes, err := in_c_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/c/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_test_asset = []byte(`// sample file
`)
func in_test_asset_bytes() ([]byte, error) {
return _in_test_asset, nil
}
func in_test_asset() (*asset, error) {
bytes, err := in_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
"in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
}
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,11 +1,18 @@
package main package main
import ( import (
"fmt"
"reflect" "reflect"
"strings"
"unsafe" "unsafe"
"os"
"time"
"io/ioutil"
"path"
"path/filepath"
) )
func bindata_read(data, name string) []byte { func bindata_read(data, name string) ([]byte, error) {
var empty [0]byte var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data)) sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:] b := empty[:]
@ -13,58 +20,268 @@ func bindata_read(data, name string) []byte {
bx.Data = sx.Data bx.Data = sx.Data
bx.Len = len(data) bx.Len = len(data)
bx.Cap = bx.Len bx.Cap = bx.Len
return b return b, nil
} }
var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a" type asset struct {
bytes []byte
func in_b_test_asset() []byte { info os.FileInfo
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
} }
var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a" type bindata_file_info struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func in_test_asset() []byte { func (fi bindata_file_info) Name() string {
return bindata_read( return fi.name
_in_test_asset, }
"in/test.asset", func (fi bindata_file_info) Size() int64 {
) return fi.size
}
func (fi bindata_file_info) Mode() os.FileMode {
return fi.mode
}
func (fi bindata_file_info) ModTime() time.Time {
return fi.modTime
}
func (fi bindata_file_info) IsDir() bool {
return false
}
func (fi bindata_file_info) Sys() interface{} {
return nil
} }
var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a" var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func in_a_test_asset() []byte { func in_a_test_asset_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_in_a_test_asset, _in_a_test_asset,
"in/a/test.asset", "in/a/test.asset",
) )
} }
func in_a_test_asset() (*asset, error) {
bytes, err := in_a_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/a/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func in_b_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
}
func in_b_test_asset() (*asset, error) {
bytes, err := in_b_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/b/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a" var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func in_c_test_asset() []byte { func in_c_test_asset_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_in_c_test_asset, _in_c_test_asset,
"in/c/test.asset", "in/c/test.asset",
) )
} }
// Asset loads and returns the asset for the given name. func in_c_test_asset() (*asset, error) {
// This returns nil of the asset could not be found. bytes, err := in_c_test_asset_bytes()
func Asset(name string) []byte { if err != nil {
if f, ok := _bindata[name]; ok { return nil, err
return f()
} }
return nil
info := bindata_file_info{name: "in/c/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func in_test_asset_bytes() ([]byte, error) {
return bindata_read(
_in_test_asset,
"in/test.asset",
)
}
func in_test_asset() (*asset, error) {
bytes, err := in_test_asset_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "in/test.asset", size: 15, mode: os.FileMode(420), modTime: time.Unix(1418006091, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{ var _bindata = map[string]func() (*asset, error){
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset, "in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset, "in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}