Compare commits

...

114 Commits

Author SHA1 Message Date
Noah 7816a8a362 Update package paths and README 2018-10-05 08:30:57 -07:00
Franklin Yu 6025e8de66
Add notice for discussion area 2018-03-04 22:04:58 -05:00
Jim Teeuwen a0ff2567cf Merge pull request #115 from grobie/fix-go-fmt
Fix go format of generated code
2015-10-23 11:11:02 +02:00
Tobias Schmidt 8ed2cd0f6d Fix go format of generated code
The following changes make the generated code go fmt compatible.
2015-10-23 03:48:06 -04:00
Jim Teeuwen bfe36d3254 Merge pull request #108 from liggitt/nometadata
Allow excluding metadata from built assets
2015-08-14 02:31:15 +02:00
Jordan Liggitt 7f4fb1184f Allow excluding metadata from built assets 2015-08-13 15:37:16 -04:00
Jim Teeuwen dce55d09e2 Merge pull request #107 from tamird/vet-shadow
Replace `go-nyet` with `go tool vet --shadow`
2015-08-08 02:19:13 +02:00
Tamir Duberstein 57e5327e97 Replace `go-nyet` with `go tool vet --shadow`
`go-nyet` is deprecated.
2015-08-07 16:36:36 -04:00
Jim Teeuwen 19c9a00bca Merge pull request #104 from jangler/master
Don't write NUL bytes in uncompressed_memcopy()
2015-07-28 18:58:31 +02:00
Brandon Mulcahy 96e3c9c230 Don't write NUL bytes in uncompressed_memcopy() 2015-07-28 07:21:58 -04:00
Jim Teeuwen 14ba83ac84 Merge pull request #103 from tsu-ku-ne/master
fix a bug that invalid convert to asset name if recursive
2015-07-21 11:10:03 +02:00
oda 94e9e44a67 fix a bug that invalid convert to asset name if recursive 2015-07-21 15:18:43 +09:00
Jim Teeuwen 281d36d28b Merge pull request #102 from tsu-ku-ne/master
Modify test to relate to function name
2015-07-16 08:30:07 +02:00
oda 0e7bf08e91 Modify test to relate to function name 2015-07-16 10:37:29 +09:00
Jim Teeuwen 564900b991 Merge pull request #101 from tsu-ku-ne/master
Fix bug that invalid converted asset name
2015-07-16 02:30:11 +02:00
oda c2c7562055 Fix bug that invalid converted asset name 2015-07-15 19:02:56 +09:00
Jim Teeuwen 2026467100 Merge pull request #100 from mattn/to_slash
call ToSlash() to be slash separated paths also on Windows.
2015-07-03 11:09:08 +02:00
Yasuhiro Matsumoto bd8da9c54b call ToSlash() to be slash separated paths also on Windows. 2015-07-03 11:51:55 +09:00
Jim Teeuwen 38ae5514e6 Merge pull request #99 from tamird/filepath-not-path
Use `filepath` everywhere instead of `path`
2015-07-02 18:58:11 +02:00
Tamir Duberstein ff362dd1f1 Use `filepath` everywhere instead of `path`
For non-slashed paths (e.g. Windows) `path` does the wrong thing.
Sadly this is not documented, but a cursory glance at the go sources
reveals that `filepath` uses `os.PathSeparator` everywhere while
`path` uses a literal `"/"`.
2015-07-02 11:44:17 -04:00
Jim Teeuwen 91db54b040 Merge pull request #97 from ikawaha/feature/remove_unsafe_refect_from_compress_nomemcopy
Remove reflect and unsafe from header_compressed_nomemcopy
2015-06-14 21:50:11 +02:00
ikawaha 49f71bc21c Remove reflect and unsafe from header_compressed_nomemcopy 2015-06-13 23:32:09 +09:00
Jim Teeuwen eb723d5626 Merge pull request #96 from tsu-ku-ne/master
Fix runtime error: index out of range
2015-06-10 11:06:00 +02:00
oda 6a532a6d90 Fix runtime error: index out of range 2015-06-10 12:32:55 +09:00
Jim Teeuwen 83a44d533b Merge pull request #93 from gelraen/files
Fix handling of individual files in subdirectories
2015-06-01 15:14:37 +02:00
Maxim Ignatenko a4f78e909c Fix handling of individual files in subdirectories 2015-06-01 13:27:45 +01:00
Jim Teeuwen 3ad80867de Merge pull request #92 from tsu-ku-ne/master
Fix bug that invalid generate Go code.
2015-05-29 13:51:24 +02:00
oda 1788809334 Ignore prefix if start with `.` 2015-05-29 18:00:38 +09:00
Jim Teeuwen b0c5bef59f Merge pull request #91 from tamird/diff-take-2
Insert a newline
2015-05-28 20:39:38 +02:00
Tamir Duberstein ca29b0b7f5 Insert a newline 2015-05-28 10:30:35 -04:00
Jim Teeuwen 69db088dee Merge pull request #90 from tamird/generated-by
Insert "generated by" comments
2015-05-28 13:39:15 +02:00
Tamir Duberstein 36d53ead3a Insert "generated by" comments
This allows Github to suppress diffs in generated files.
2015-05-27 19:52:04 -04:00
Tamir Duberstein e01811006d Style 2015-05-27 19:51:30 -04:00
Jim Teeuwen eb01a153be Merge pull request #86 from tamird/golint
Golint
2015-05-26 22:39:33 +02:00
Tamir Duberstein dfcf23b04e camelCase instead of snake_case 2015-05-11 21:44:51 -04:00
Tamir Duberstein 4fc85e2b3c Better Makefiles 2015-05-11 21:39:32 -04:00
Tamir Duberstein dada32c78b Early return 2015-05-11 15:47:48 -04:00
Tamir Duberstein 6b468a429a bintree 2015-05-11 15:46:01 -04:00
Tamir Duberstein ba26659a34 bindataFileInfo 2015-05-11 15:45:16 -04:00
Tamir Duberstein 4f258b3140 Comment style 2015-05-11 15:44:41 -04:00
Tamir Duberstein ffff253524 bindataRead 2015-05-11 15:42:14 -04:00
Tamir Duberstein 4d36d97d1d golint 2015-05-11 15:33:37 -04:00
Jim Teeuwen d0a5f1749d Merge pull request #85 from tamird/go-nyet
Incorporate go-nyet
2015-05-11 20:45:43 +02:00
Tamir Duberstein fff92e7dec Incorporate go-nyet 2015-05-11 09:48:50 -04:00
Jim Teeuwen a15f234cb1 Merge pull request #84 from tamird/errcheck
Emit `errcheck`-passing code
2015-05-09 14:00:24 +02:00
Tamir Duberstein c3e4c77465 Emit `errcheck`-passing code 2015-05-08 16:15:37 -04:00
Tamir Duberstein 476077970b Regenerate testdata 2015-05-08 16:15:24 -04:00
Jim Teeuwen 76a6418a0a Merge pull request #82 from abates/feature/FollowSymlinks
Implementation for following symlinks
2015-04-16 17:24:44 +02:00
Andrew Bates 465fc29db9 Implementation for following symlinks
This is an implementation where findFiles will follow symlinks and keep
track of paths already followed.  No paths will be evaluated more than
once, therefore preventing recursive link evaluation.

Commit includes test cases and test data
2015-04-16 09:38:06 -04:00
Jim Teeuwen f449dcd26c Merge pull request #81 from liggitt/ascii
Always encode binary data to ascii-escaped strings
2015-04-02 02:05:19 +02:00
Jordan Liggitt 1d06945605 Always encode binary data to ascii-escaped strings 2015-04-01 15:44:58 -04:00
Jim Teeuwen 21f0a65fc5 Merge pull request #80 from srhnsn/master
Always split by forward slashes when writing the TOC tree.
2015-03-21 19:11:58 +01:00
Serhan Şen 9178943e13 Always split by forward slashes when writing the TOC tree.
At that point, all slashes are normalized as forward slashes.
2015-03-21 16:36:03 +01:00
Jim Teeuwen 7362d4b6b2 Merge pull request #74 from tschottdorf/master
add `mode` and `modTime` flags
2015-03-10 19:22:57 +01:00
Tobias Schottdorf b5d9eff767 add `mode` and `modTime` flags
In some situations, it is desired to have reproducible runs of `go-bindata`
from a fixed git repository commit. Since mtimes and file modes are not
generally versioned, the newly introduced flags aid in that quest by allowing
to completely replace those two pieces of data by something fixed.

Example:
//go:generate go-bindata -pkg resource -mode 0644 -modtime 1388530800 \
                         -o ./embedded.go ./ui/...
2015-03-10 19:17:17 +01:00
Jim Teeuwen 040617c5ef Merge pull request #73 from jbreitbart/master
Added MustAsset function.
2015-03-08 22:15:58 +01:00
Jens Breitbart 81e20ed1b7 Added MustAsset function. 2015-03-08 12:42:30 +01:00
Jim Teeuwen 8ee21af0fa Merge pull request #72 from shurcooL/remove-unused-Config-field
Remove unused field in Config.
2015-02-26 02:52:18 +01:00
Dmitri Shuralyov af127dc2da Remove unused field in Config.
Commit 2c7ab48825 added new struct
InputConfig which contains Path string and Recursive bool. The rest of
go-bindata has been changed to use that.
The Recursive flag inside Config is now completely unused, and should
be removed since it makes code harder to read.
2015-02-25 17:34:33 -08:00
Jim Teeuwen 8ec170e704 Merge pull request #69 from beyang/master
add -dev flag, similar to -debug but does not emit absolute file paths
2015-01-27 01:35:24 +01:00
Beyang Liu 0efad67aa4 add -dev flag, similar to -debug but does not emit absolute file paths 2015-01-26 15:56:13 -08:00
Jim Teeuwen 4a8e91e5cd Merge pull request #66 from shurcooL/patch-1
Update README to mention go get -u.
2015-01-09 11:22:27 +01:00
Dmitri Shuralyov e3850a4b3c Update README to mention go get -u.
This will help prevent/reduce issues such as #65.
2015-01-09 01:13:54 -08:00
Jim Teeuwen 452770b024 Merge pull request #64 from riywo/fix/recursive_knownFuncs
Fix bug of knownFuncs usage when findFiles is called recursively
2014-12-09 16:43:41 +01:00
Ryosuke IWANAGA f80b50711d Fix bug of knownFuncs usage when findFiles is called recursively 2014-12-09 22:07:31 +09:00
Jim Teeuwen 7159dbfa31 Merge pull request #63 from riywo/fix/testdata
Update testdata/out
2014-12-09 12:36:31 +01:00
Ryosuke IWANAGA fc595e391e Update testdata/out 2014-12-09 14:41:25 +09:00
Jim Teeuwen f7b87a0a9a Merge pull request #62 from riywo/restore
Add RestoreAsset/RestoreAssets methods
2014-12-08 17:11:19 +01:00
Ryosuke IWANAGA 0267f6e673 Add RestoreAsset/RestoreAssets methods 2014-12-08 23:02:06 +09:00
Jim Teeuwen 9091c617ee Merge pull request #61 from riywo/add-file-info
Add AssetInfo() to use FileInfo
2014-12-08 00:26:27 +01:00
Ryosuke IWANAGA 5dec5f37be Adjust release mode for AssetInfo() 2014-12-08 07:35:15 +09:00
Ryosuke IWANAGA f9f833bc6e Add AssetInfo() into debug mode using type asset 2014-12-08 07:31:35 +09:00
Jim Teeuwen f94581bd91 Merge pull request #59 from jwforres/sort_sooner
Sort before generating unique function names to get stable output
2014-11-25 11:17:39 +01:00
Jessica Forrester fcbedc59d6 Sort before generating unique function names to get stable output 2014-11-24 16:10:21 -05:00
Jim Teeuwen bbd0c6e271 Merge pull request #56 from jwforres/fix_compilation_mem_bloat
Fix extreme memory bloat during compile time. Also, when strings are valid UTF-8 inline them directly as raw strings when in uncompressed mode.
2014-11-20 18:47:17 +01:00
Jessica Forrester 2c5bf09f1b Fix extreme memory bloat during compile time. When using uncompressed mode show raw UTF-8 strings for better diffs. 2014-11-20 10:29:22 -05:00
Jim Teeuwen da92400a92 Merge pull request #55 from shurcooL/patch-1
Fix Asset signature in README.
2014-11-16 11:22:31 +01:00
Dmitri Shuralyov 0e05e3a19d Fix Asset signature in README.
See https://github.com/jteeuwen/go-bindata/pull/54#discussion_r20400279.
2014-11-15 19:45:57 -08:00
Jim Teeuwen 1796683e4d Merge pull request #54 from arschles/fix-readme
fixing the readme to indicate err return
2014-11-15 01:21:54 +01:00
Aaron Schlesinger 8f6e0a3425 fixing the readme to indicate err return
from a test that I wrote in https://github.com/arschles/go-bindata-test, it looks like go-bindata generates an Asset(...) function that returns an error when the file isn't found
2014-11-14 14:38:19 -08:00
Jim Teeuwen 1743f47c01 Merge pull request #50 from liggitt/sorted_order
Output TOC and tree in sorted order
2014-09-29 23:50:12 +02:00
Jordan Liggitt 853793af8f Output TOC and tree in sorted order to make output stable between invocations. Addresses issue #49 2014-09-29 16:32:04 -04:00
jimt 93b909d149 Merge pull request #47 from stephens2424/master
Appending a count for filenames that end up being duplicated by
2014-08-18 04:00:46 +02:00
Stephen Searles cfd1b4bd08 Appending a count for filenames that end up being duplicated by
sanitization. Addresses issue #46.
2014-08-17 17:15:30 -07:00
jimt 64e31e0c92 Merge pull request #43 from Byron/master
AssetDir is now able to list the data root.
2014-08-07 16:44:26 +02:00
Sebastian Thiel 6ca6b73691 AssetDir is now able to list the data root.
Previously, it was impossible to get a listing of entries right underneath
the data root.

Such a query is now possible by passing an empty string as data root.
2014-08-07 16:24:25 +02:00
jimt 388b47b5ff Merge pull request #42 from opennota/files_as_params
Accept individual files as parameters
2014-08-05 15:59:05 +02:00
opennota 6347e7a31c Accept individual files as parameters 2014-08-05 19:23:20 +07:00
jimt b040f60a8c Merge pull request #41 from ctl80/patch-1
Fixing small grammar error.
2014-08-01 14:18:09 +02:00
ctl80 68a53ac0c2 Fixing small grammar error. 2014-08-01 06:49:15 -05:00
jimt c3d7350481 Merge pull request #40 from elazarl/patch-1
Refer to go-bindata-assetfs in README
2014-07-14 11:06:04 +02:00
Elazar Leibovich d47bbf733e refer to go-bindata-assetfs in README 2014-07-14 06:50:09 +03:00
jimt 54e5992f47 Merge pull request #39 from elazarl/pullreq
Support directory listing with AssetDir(dirname string)
2014-07-13 15:34:24 +02:00
Elazar Leibovich c15090e68a Support directory listing with AssetDir(dirname string)
Signed-off-by: Elazar Leibovich <elazarl@gmail.com>
2014-07-13 12:50:11 +03:00
Jim Teeuwen d3feb9534c Removes unnecessary return in `writeReleaseAsset`. This satisfies
the rules for `go vet`. Addresses issue #35

Signed-off-by: Jim Teeuwen <jimteeuwen@gmail.com>
2014-06-09 12:31:18 +02:00
Jim Teeuwen 17800c65a0 Fixes formatting of various generated outputs to be
more compatible with `go fmt`. This partially addresses
issue #34

Signed-off-by: Jim Teeuwen <jimteeuwen@gmail.com>
2014-05-28 14:43:02 +02:00
jimt 394d5b27c0 Merge pull request #32 from XenoPhex/master
Asset retrieval is independent of OS Path
2014-05-16 20:22:52 +02:00
Anand Gaitonde and Michael Maximilien f93f031745 Asset retrieval is independent of OS Path
That is for Windows \\ are replaced with / since the
asset map uses paths with /
2014-05-16 10:34:04 -07:00
jimt 4b70a41eb8 Merge pull request #31 from yosssi/fix-toc-footer
Remove the unnecessary line break of the TOC footer
2014-05-12 17:52:26 +02:00
yosssi ff2ab748eb Remove the unnecessary line break of the TOC footer 2014-05-13 00:39:28 +09:00
jimt 8abc1cae37 Merge pull request #30 from yosssi/add-assetnames
Add `AssetNames` function which returns the names of the assets.
2014-05-12 12:34:24 +02:00
yosssi e764a84fdf Fix the following things:
* Change `for name, _ := range _bindata` to `for name := range _bindata {`
* Format the souce codes
2014-05-12 18:15:42 +09:00
yosssi 57a8ec74ce Add `AssetNames` function which returns the names of the assets. 2014-05-12 13:59:00 +09:00
jimt 6c168add63 Merge pull request #29 from yosssi/fix-contributing
Fix a typo of CONTRIBUTING.md (Update from "chose" to "choose")
2014-05-10 20:00:37 +02:00
jimt ab3c8e2995 Merge pull request #28 from yosssi/fix-config-validate
Fix `*Config.validate` method not to make a directory when the `-o` flag's path does not have a directory.
2014-05-10 19:59:02 +02:00
yosssi cda5f335ae Fix a typo of CONTRIBUTING.md (Update from "chose" to "choose") 2014-05-11 02:55:35 +09:00
yosssi ca7033b19a Fix `*Config.validate` method not to make a directory when the `-o` flag's path does not have a directory. 2014-05-11 02:42:25 +09:00
jimt 2ebf002fb5 Merge pull request #26 from ian-kent/master
Add support for -ignore
2014-04-30 01:41:00 +02:00
Ian Kent 7f6fddddd0 Add support for -ignore 2014-04-29 23:42:13 +01:00
Jim Teeuwen 212d2a5cdc Fixes typo in flag description. 2014-04-10 18:10:22 +02:00
Jim Teeuwen 3834e2fe48 Fixes some code comments. 2014-03-07 22:13:34 +01:00
jimt 362b0784bb Merge pull request #20 from taichi/use_to_slash
Use / in the name of the asset.
2014-02-28 19:34:45 +01:00
SATO taichi eb1b26017a Use / in the name of the asset.
Windows path separator is not / in \.
2014-02-28 20:33:10 +09:00
Jim Teeuwen 1c1928d3b6 Amends README with a note on how to access generated asset data. 2014-01-29 12:43:10 +01:00
29 changed files with 2392 additions and 335 deletions

View File

@ -70,7 +70,7 @@ good to keep in mind:
> the rest of the API. This addresses issue #32
Do not pile a lot of unrelated changes into a single commit.
Pick and chose only those changes for a single commit, which are
Pick and choose only those changes for a single commit, which are
directly related. We would much rather see a hundred commits
saying nothing but `"Runs go fmt"` in between any real fixes
than have these style changes embedded in those real fixes.

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
make -C testdata

View File

@ -1,3 +1,13 @@
> **NOTICE:**
>
> This repository is a fork of <https://github.com/jteeuwen/go-bindata> which
> itself was a fork of an original project that disappeared.
>
> I've cloned a copy for personal use at <https://git.kirsle.net/go/bindata> so
> that I always have a version that won't disappear.
>
> [@kirsle](https://www.kirsle.net/)
## bindata
This package converts any file into managable Go source code. Useful for
@ -13,7 +23,7 @@ output being generated.
To install the library and command line program, use the following:
go get github.com/jteeuwen/go-bindata/...
go get -u git.kirsle.net/go/bindata/...
### Usage
@ -42,11 +52,27 @@ Multiple input directories can be specified if necessary.
$ go-bindata dir1/... /path/to/dir2/... dir3
The following paragraphs detail some of the command line options which can
The following paragraphs detail some of the command line options which can be
supplied to `go-bindata`. Refer to the `testdata/out` directory for various
output examples from the assets in `testdata/in`. Each example uses different
command line options.
To ignore files, pass in regexes using -ignore, for example:
$ go-bindata -ignore=\\.gitignore data/...
### Accessing an asset
To access asset data, we use the `Asset(string) ([]byte, error)` function which
is included in the generated output.
data, err := Asset("pub/style/foo.css")
if err != nil {
// Asset was not found.
}
// use asset data
### Debug vs Release builds
@ -166,4 +192,7 @@ format is specified at build time with the appropriate tags.
The tags are appended to a `// +build` line in the beginning of the output file
and must follow the build tags syntax specified by the go tool.
### Related projects
[go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs#readme) -
implements `http.FileSystem` interface. Allows you to serve assets with `net/http`.

View File

@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"regexp"
)
// InputConfig defines options on a asset directory to be convert.
@ -116,10 +117,29 @@ type Config struct {
// in the code. The default behaviour is Release mode.
Debug bool
// Recursively process all assets in the input directory and its
// sub directories. This defaults to false, so only files in the
// input directory itself are read.
Recursive bool
// Perform a dev build, which is nearly identical to the debug option. The
// only difference is that instead of absolute file paths in generated code,
// it expects a variable, `rootDir`, to be set in the generated code's
// package (the author needs to do this manually), which it then prepends to
// an asset's name to construct the file path on disk.
//
// This is mainly so you can push the generated code file to a shared
// repository.
Dev bool
// When true, size, mode and modtime are not preserved from files
NoMetadata bool
// When nonzero, use this as mode for all files.
Mode uint
// When nonzero, use this as unix timestamp for all files.
ModTime int64
// Ignores any filenames matching the regex pattern specified, e.g.
// path/to/file.ext will ignore only that file, or \\.gitignore
// will match any .gitignore file.
//
// This parameter can be provided multiple times.
Ignore []*regexp.Regexp
}
// NewConfig returns a default configuration struct.
@ -129,8 +149,8 @@ func NewConfig() *Config {
c.NoMemCopy = false
c.NoCompress = false
c.Debug = false
c.Recursive = false
c.Output = "./bindata.go"
c.Ignore = make([]*regexp.Regexp, 0)
return c
}
@ -142,14 +162,10 @@ func (c *Config) validate() error {
}
for _, input := range c.Input {
stat, err := os.Lstat(input.Path)
_, err := os.Lstat(input.Path)
if err != nil {
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
}
if !stat.IsDir() {
return fmt.Errorf("Input path '%s' is not a directory.", input.Path)
}
}
if len(c.Output) == 0 {
@ -170,10 +186,12 @@ func (c *Config) validate() error {
// File does not exist. This is fine, just make
// sure the directory it is to be in exists.
dir, _ := filepath.Split(c.Output)
err = os.MkdirAll(dir, 0744)
if dir != "" {
err = os.MkdirAll(dir, 0744)
if err != nil {
return fmt.Errorf("Create output directory: %v", err)
if err != nil {
return fmt.Errorf("Create output directory: %v", err)
}
}
}

View File

@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"unicode"
)
@ -26,9 +27,11 @@ func Translate(c *Config) error {
return err
}
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
// Locate all the assets.
for _, input := range c.Input {
err = findFiles(input.Path, c.Prefix, input.Recursive, &toc)
err = findFiles(input.Path, c.Prefix, input.Recursive, &toc, c.Ignore, knownFuncs, visitedPaths)
if err != nil {
return err
}
@ -46,10 +49,32 @@ func Translate(c *Config) error {
bfd := bufio.NewWriter(fd)
defer bfd.Flush()
// Write the header. This makes e.g. Github ignore diffs in generated files.
if _, err = fmt.Fprint(bfd, "// Code generated by go-bindata.\n"); err != nil {
return err
}
if _, err = fmt.Fprint(bfd, "// sources:\n"); err != nil {
return err
}
wd, err := os.Getwd()
if err != nil {
return err
}
for _, asset := range toc {
relative, _ := filepath.Rel(wd, asset.Path)
if _, err = fmt.Fprintf(bfd, "// %s\n", filepath.ToSlash(relative)); err != nil {
return err
}
}
if _, err = fmt.Fprint(bfd, "// DO NOT EDIT!\n\n"); err != nil {
return err
}
// Write build tags, if applicable.
if len(c.Tags) > 0 {
_, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags)
if err != nil {
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil {
return err
}
}
@ -61,8 +86,8 @@ func Translate(c *Config) error {
}
// Write assets.
if c.Debug {
err = writeDebug(bfd, toc)
if c.Debug || c.Dev {
err = writeDebug(bfd, c, toc)
} else {
err = writeRelease(bfd, c, toc)
}
@ -72,44 +97,108 @@ func Translate(c *Config) error {
}
// Write table of contents
return writeTOC(bfd, toc)
if err := writeTOC(bfd, toc); err != nil {
return err
}
// Write hierarchical tree of assets
if err := writeTOCTree(bfd, toc); err != nil {
return err
}
// Write restore procedure
return writeRestore(bfd)
}
// Implement sort.Interface for []os.FileInfo based on Name()
type ByName []os.FileInfo
func (v ByName) Len() int { return len(v) }
func (v ByName) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func (v ByName) Less(i, j int) bool { return v[i].Name() < v[j].Name() }
// findFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code.
func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regexp.Regexp, knownFuncs map[string]int, visitedPaths map[string]bool) error {
dirpath := dir
if len(prefix) > 0 {
dir, _ = filepath.Abs(dir)
dirpath, _ = filepath.Abs(dirpath)
prefix, _ = filepath.Abs(prefix)
prefix = filepath.ToSlash(prefix)
}
fd, err := os.Open(dir)
fi, err := os.Stat(dirpath)
if err != nil {
return err
}
defer fd.Close()
var list []os.FileInfo
list, err := fd.Readdir(0)
if err != nil {
return err
if !fi.IsDir() {
dirpath = filepath.Dir(dirpath)
list = []os.FileInfo{fi}
} else {
visitedPaths[dirpath] = true
fd, err := os.Open(dirpath)
if err != nil {
return err
}
defer fd.Close()
list, err = fd.Readdir(0)
if err != nil {
return err
}
// Sort to make output stable between invocations
sort.Sort(ByName(list))
}
for _, file := range list {
var asset Asset
asset.Path = filepath.Join(dir, file.Name())
asset.Name = asset.Path
asset.Path = filepath.Join(dirpath, file.Name())
asset.Name = filepath.ToSlash(asset.Path)
ignoring := false
for _, re := range ignore {
if re.MatchString(asset.Path) {
ignoring = true
break
}
}
if ignoring {
continue
}
if file.IsDir() {
if recursive {
findFiles(asset.Path, prefix, recursive, toc)
recursivePath := filepath.Join(dir, file.Name())
visitedPaths[asset.Path] = true
findFiles(recursivePath, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
}
continue
} else if file.Mode()&os.ModeSymlink == os.ModeSymlink {
var linkPath string
if linkPath, err = os.Readlink(asset.Path); err != nil {
return err
}
if !filepath.IsAbs(linkPath) {
if linkPath, err = filepath.Abs(dirpath + "/" + linkPath); err != nil {
return err
}
}
if _, ok := visitedPaths[linkPath]; !ok {
visitedPaths[linkPath] = true
findFiles(asset.Path, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
}
continue
}
if strings.HasPrefix(asset.Name, prefix) {
asset.Name = asset.Name[len(prefix):]
} else {
asset.Name = filepath.Join(dir, file.Name())
}
// If we have a leading slash, get rid of it.
@ -122,7 +211,7 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
return fmt.Errorf("Invalid file: %v", asset.Path)
}
asset.Func = safeFunctionName(asset.Name)
asset.Func = safeFunctionName(asset.Name, knownFuncs)
asset.Path, _ = filepath.Abs(asset.Path)
*toc = append(*toc, asset)
}
@ -133,25 +222,40 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
// safeFunctionName converts the given name into a name
// which qualifies as a valid function identifier.
func safeFunctionName(name string) string {
// which qualifies as a valid function identifier. It
// also compares against a known list of functions to
// prevent conflict based on name translation.
func safeFunctionName(name string, knownFuncs map[string]int) string {
var inBytes, outBytes []byte
var toUpper bool
name = strings.ToLower(name)
name = regFuncName.ReplaceAllString(name, "_")
inBytes = []byte(name)
// Get rid of "__" instances for niceness.
for strings.Index(name, "__") > -1 {
name = strings.Replace(name, "__", "_", -1)
for i := 0; i < len(inBytes); i++ {
if regFuncName.Match([]byte{inBytes[i]}) {
toUpper = true
} else if toUpper {
outBytes = append(outBytes, []byte(strings.ToUpper(string(inBytes[i])))...)
toUpper = false
} else {
outBytes = append(outBytes, inBytes[i])
}
}
// Leading underscores are silly (unless they prefix a digit (see below)).
for len(name) > 1 && name[0] == '_' {
name = name[1:]
}
name = string(outBytes)
// Identifier can't start with a digit.
if unicode.IsDigit(rune(name[0])) {
name = "_" + name
}
if num, ok := knownFuncs[name]; ok {
knownFuncs[name] = num + 1
name = fmt.Sprintf("%s%d", name, num)
} else {
knownFuncs[name] = 2
}
return name
}

90
convert_test.go Normal file
View File

@ -0,0 +1,90 @@
package bindata
import (
"regexp"
"strings"
"testing"
)
func TestSafeFunctionName(t *testing.T) {
var knownFuncs = make(map[string]int)
name1 := safeFunctionName("foo/bar", knownFuncs)
name2 := safeFunctionName("foo_bar", knownFuncs)
if name1 == name2 {
t.Errorf("name collision")
}
}
func TestFindFiles(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/dupname", "testdata/dupname", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if toc[0].Func == toc[1].Func {
t.Errorf("name collision")
}
}
func TestFindFilesWithSymlinks(t *testing.T) {
var tocSrc []Asset
var tocTarget []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkSrc", "testdata/symlinkSrc", true, &tocSrc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
knownFuncs = make(map[string]int)
visitedPaths = make(map[string]bool)
err = findFiles("testdata/symlinkParent", "testdata/symlinkParent", true, &tocTarget, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(tocSrc) != len(tocTarget) {
t.Errorf("Symlink source and target should have the same number of assets. Expected %d got %d", len(tocTarget), len(tocSrc))
} else {
for i, _ := range tocSrc {
targetFunc := strings.TrimPrefix(tocTarget[i].Func, "symlinktarget")
targetFunc = strings.ToLower(targetFunc[:1]) + targetFunc[1:]
if tocSrc[i].Func != targetFunc {
t.Errorf("Symlink source and target produced different function lists. Expected %s to be %s", targetFunc, tocSrc[i].Func)
}
}
}
}
func TestFindFilesWithRecursiveSymlinks(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkRecursiveParent", "testdata/symlinkRecursiveParent", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(toc) != 1 {
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
}
}
func TestFindFilesWithSymlinkedFile(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkFile", "testdata/symlinkFile", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(toc) != 1 {
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
}
}

View File

@ -10,14 +10,14 @@ import (
)
// writeDebug writes the debug code file.
func writeDebug(w io.Writer, toc []Asset) error {
func writeDebug(w io.Writer, c *Config, toc []Asset) error {
err := writeDebugHeader(w)
if err != nil {
return err
}
for i := range toc {
err = writeDebugAsset(w, &toc[i])
err = writeDebugAsset(w, c, &toc[i])
if err != nil {
return err
}
@ -32,11 +32,13 @@ func writeDebugHeader(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// bindata_read reads the given file from disk. It returns
// an error on failure.
func bindata_read(path, name string) ([]byte, error) {
// bindataRead reads the given file from disk. It returns an error on failure.
func bindataRead(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err)
@ -44,6 +46,11 @@ func bindata_read(path, name string) ([]byte, error) {
return buf, err
}
type asset struct {
bytes []byte
info os.FileInfo
}
`)
return err
}
@ -51,16 +58,30 @@ func bindata_read(path, name string) ([]byte, error) {
// writeDebugAsset write a debug entry for the given asset.
// A debug entry is simply a function which reads the asset from
// the original file (e.g.: from disk).
func writeDebugAsset(w io.Writer, asset *Asset) error {
_, err := fmt.Fprintf(w, `
// %s reads file data from disk.
// It panics if something went wrong in the process.
func %s() ([]byte, error) {
return bindata_read(
%q,
%q,
)
func writeDebugAsset(w io.Writer, c *Config, asset *Asset) error {
pathExpr := fmt.Sprintf("%q", asset.Path)
if c.Dev {
pathExpr = fmt.Sprintf("filepath.Join(rootDir, %q)", asset.Name)
}
_, err := fmt.Fprintf(w, `// %s reads file data from disk. It returns an error on failure.
func %s() (*asset, error) {
path := %s
name := %q
bytes, err := bindataRead(path, name)
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
}
`, asset.Func, asset.Func, asset.Path, asset.Name)
`, asset.Func, asset.Func, pathExpr, asset.Name)
return err
}

View File

@ -0,0 +1,22 @@
package main
import "strings"
// borrowed from https://github.com/hashicorp/serf/blob/master/command/agent/flag_slice_value.go
// AppendSliceValue implements the flag.Value interface and allows multiple
// calls to the same variable to append a list.
type AppendSliceValue []string
func (s *AppendSliceValue) String() string {
return strings.Join(*s, ",")
}
func (s *AppendSliceValue) Set(value string) error {
if *s == nil {
*s = make([]string, 0, 1)
}
*s = append(*s, value)
return nil
}

View File

@ -7,10 +7,12 @@ package main
import (
"flag"
"fmt"
"github.com/jteeuwen/go-bindata"
"os"
"path/filepath"
"regexp"
"strings"
"git.kirsle.net/go/bindata"
)
func main() {
@ -39,15 +41,29 @@ func parseArgs() *bindata.Config {
}
flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of uild tags to include.")
flag.BoolVar(&c.Dev, "dev", c.Dev, "Similar to debug, but does not emit absolute paths. Expects a rootDir variable to already exist in the generated code's package.")
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of build tags to include.")
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
flag.BoolVar(&c.NoMetadata, "nometadata", c.NoMetadata, "Assets will not preserve size, mode, and modtime info.")
flag.UintVar(&c.Mode, "mode", c.Mode, "Optional file mode override for all files.")
flag.Int64Var(&c.ModTime, "modtime", c.ModTime, "Optional modification unix timestamp override for all files.")
flag.StringVar(&c.Output, "o", c.Output, "Optional name of the output file to be generated.")
flag.BoolVar(&version, "version", false, "Displays version information.")
ignore := make([]string, 0)
flag.Var((*AppendSliceValue)(&ignore), "ignore", "Regex pattern to ignore")
flag.Parse()
patterns := make([]*regexp.Regexp, 0)
for _, pattern := range ignore {
patterns = append(patterns, regexp.MustCompile(pattern))
}
c.Ignore = patterns
if version {
fmt.Printf("%s\n", Version())
os.Exit(0)

View File

@ -5,10 +5,13 @@
package bindata
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"unicode/utf8"
)
// writeRelease writes the release code file.
@ -31,19 +34,24 @@ func writeRelease(w io.Writer, c *Config, toc []Asset) error {
// writeReleaseHeader writes output file headers.
// This targets release builds.
func writeReleaseHeader(w io.Writer, c *Config) error {
var err error
if c.NoCompress {
if c.NoMemCopy {
return header_uncompressed_nomemcopy(w)
err = header_uncompressed_nomemcopy(w)
} else {
return header_uncompressed_memcopy(w)
err = header_uncompressed_memcopy(w)
}
} else {
if c.NoMemCopy {
return header_compressed_nomemcopy(w)
err = header_compressed_nomemcopy(w)
} else {
return header_compressed_memcopy(w)
err = header_compressed_memcopy(w)
}
}
if err != nil {
return err
}
return header_release_common(w)
}
// writeReleaseAsset write a release entry for the given asset.
@ -59,52 +67,65 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
if c.NoCompress {
if c.NoMemCopy {
return uncompressed_nomemcopy(w, asset, fd)
err = uncompressed_nomemcopy(w, asset, fd)
} else {
return uncompressed_memcopy(w, asset, fd)
err = uncompressed_memcopy(w, asset, fd)
}
} else {
if c.NoMemCopy {
return compressed_nomemcopy(w, asset, fd)
err = compressed_nomemcopy(w, asset, fd)
} else {
return compressed_memcopy(w, asset, fd)
err = compressed_memcopy(w, asset, fd)
}
}
if err != nil {
return err
}
return asset_release_common(w, c, asset)
}
return nil
// sanitize prepares a valid UTF-8 string as a raw string constant.
// Based on https://code.google.com/p/go/source/browse/godoc/static/makestatic.go?repo=tools
func sanitize(b []byte) []byte {
// Replace ` with `+"`"+`
b = bytes.Replace(b, []byte("`"), []byte("`+\"`\"+`"), -1)
// Replace BOM with `+"\xEF\xBB\xBF"+`
// (A BOM is valid UTF-8 but not permitted in Go source files.
// I wouldn't bother handling this, but for some insane reason
// jquery.js has a BOM somewhere in the middle.)
return bytes.Replace(b, []byte("\xEF\xBB\xBF"), []byte("`+\"\\xEF\\xBB\\xBF\"+`"), -1)
}
func header_compressed_nomemcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"bytes"
"compress/gzip"
"fmt"
"io"
"reflect"
"unsafe"
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
func bindata_read(data, name string) ([]byte, error) {
var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:]
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bx.Data = sx.Data
bx.Len = len(data)
bx.Cap = bx.Len
gz, err := gzip.NewReader(bytes.NewBuffer(b))
func bindataRead(data, name string) ([]byte, error) {
gz, err := gzip.NewReader(strings.NewReader(data))
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
}
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
gz.Close()
clErr := gz.Close()
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
}
if clErr != nil {
return nil, err
}
return buf.Bytes(), nil
}
@ -115,13 +136,18 @@ func bindata_read(data, name string) ([]byte, error) {
func header_compressed_memcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"bytes"
"compress/gzip"
"fmt"
"io"
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
func bindata_read(data []byte, name string) ([]byte, error) {
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
@ -129,11 +155,14 @@ func bindata_read(data []byte, name string) ([]byte, error) {
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
gz.Close()
clErr := gz.Close()
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
}
if clErr != nil {
return nil, err
}
return buf.Bytes(), nil
}
@ -144,12 +173,17 @@ func bindata_read(data []byte, name string) ([]byte, error) {
func header_uncompressed_nomemcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"fmt"
"reflect"
"unsafe"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"time"
"unsafe"
)
func bindata_read(data, name string) ([]byte, error) {
func bindataRead(data, name string) ([]byte, error) {
var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:]
@ -166,12 +200,53 @@ func bindata_read(data, name string) ([]byte, error) {
func header_uncompressed_memcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import (
"fmt"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
`)
return err
}
func header_release_common(w io.Writer) error {
_, err := fmt.Fprintf(w, `type asset struct {
bytes []byte
info os.FileInfo
}
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
`)
return err
}
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
if err != nil {
@ -188,8 +263,8 @@ func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `"
func %s() ([]byte, error) {
return bindata_read(
func %sBytes() ([]byte, error) {
return bindataRead(
_%s,
%q,
)
@ -200,14 +275,12 @@ func %s() ([]byte, error) {
}
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
return bindata_read([]byte{`, asset.Func)
_, err := fmt.Fprintf(w, `var _%s = []byte("`, asset.Func)
if err != nil {
return nil
return err
}
gz := gzip.NewWriter(&ByteWriter{Writer: w})
gz := gzip.NewWriter(&StringWriter{Writer: w})
_, err = io.Copy(gz, r)
gz.Close()
@ -215,13 +288,16 @@ func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
return err
}
_, err = fmt.Fprintf(w, `
},
_, err = fmt.Fprintf(w, `")
func %sBytes() ([]byte, error) {
return bindataRead(
_%s,
%q,
)
}
`, asset.Name)
`, asset.Func, asset.Func, asset.Name)
return err
}
@ -238,8 +314,8 @@ func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `"
func %s() ([]byte, error) {
return bindata_read(
func %sBytes() ([]byte, error) {
return bindataRead(
_%s,
%q,
)
@ -250,21 +326,62 @@ func %s() ([]byte, error) {
}
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
return []byte{`, asset.Func)
_, err := fmt.Fprintf(w, `var _%s = []byte(`, asset.Func)
if err != nil {
return err
}
_, err = io.Copy(&ByteWriter{Writer: w}, r)
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
if utf8.Valid(b) && !bytes.Contains(b, []byte{0}) {
fmt.Fprintf(w, "`%s`", sanitize(b))
} else {
fmt.Fprintf(w, "%+q", b)
}
_, err = fmt.Fprintf(w, `
}, nil
_, err = fmt.Fprintf(w, `)
func %sBytes() ([]byte, error) {
return _%s, nil
}
`)
`, asset.Func, asset.Func)
return err
}
func asset_release_common(w io.Writer, c *Config, asset *Asset) error {
fi, err := os.Stat(asset.Path)
if err != nil {
return err
}
mode := uint(fi.Mode())
modTime := fi.ModTime().Unix()
size := fi.Size()
if c.NoMetadata {
mode = 0
modTime = 0
size = 0
}
if c.Mode > 0 {
mode = uint(os.ModePerm) & c.Mode
}
if c.ModTime > 0 {
modTime = c.ModTime
}
_, err = fmt.Fprintf(w, `func %s() (*asset, error) {
bytes, err := %sBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: %q, size: %d, mode: os.FileMode(%d), modTime: time.Unix(%d, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
`, asset.Func, asset.Func, asset.Name, size, mode, modTime)
return err
}

63
restore.go Normal file
View File

@ -0,0 +1,63 @@
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package bindata
import (
"fmt"
"io"
)
func writeRestore(w io.Writer) error {
_, err := fmt.Fprintf(w, `
// RestoreAsset restores 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, filepath.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
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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, "/")...)...)
}
`)
return err
}

37
testdata/Makefile vendored Normal file
View File

@ -0,0 +1,37 @@
FILES:=$(wildcard out/*.go)
.PHONY: check
check: errcheck vet golint $(FILES:.go=.checked)
out/%.checked: out/%.go
errcheck $<
go tool vet --all $<
go tool vet --shadow $<
golint $<
$(GOPATH)/bin/go-bindata: $(wildcard ../*.go) $(wildcard ../**/*.go)
go install ../...
out/compress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -o $@ in/...
out/compress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nomemcopy -o $@ in/...
out/debug.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -debug -o $@ in/...
out/nocompress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nocompress -o $@ in/...
out/nocompress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nocompress -nomemcopy -o $@ in/...
errcheck:
go get github.com/kisielk/errcheck
vet:
go get golang.org/x/tools/cmd/vet
golint:
go get github.com/golang/lint/golint

1
testdata/dupname/foo/bar vendored Normal file
View File

@ -0,0 +1 @@
// sample file

1
testdata/dupname/foo_bar vendored Normal file
View File

@ -0,0 +1 @@
// sample file

View File

@ -1,86 +1,312 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"log"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
func bindata_read(data []byte, name string) []byte {
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
log.Fatalf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
gz.Close()
clErr := gz.Close()
if err != nil {
log.Fatalf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
if clErr != nil {
return nil, err
}
return buf.Bytes()
return buf.Bytes(), nil
}
func in_b_test_asset() []byte {
return bindata_read([]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
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",
)
type asset struct {
bytes []byte
info os.FileInfo
}
func in_test_asset() []byte {
return bindata_read([]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
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/test.asset",
)
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func in_a_test_asset() []byte {
return bindata_read([]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
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,
},
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
var _inATestAsset = []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 inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
func in_c_test_asset() []byte {
return bindata_read([]byte{
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
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,
},
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = []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 inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset",
)
}
func inBTestAsset() (*asset, error) {
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = []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 inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = []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 inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset",
)
}
func inTestAsset() (*asset, error) {
bytes, err := inTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found.
func Asset(name string) []byte {
if f, ok := _bindata[name]; ok {
return f()
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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": inATestAsset,
"in/b/test.asset": inBTestAsset,
"in/c/test.asset": inCTestAsset,
"in/test.asset": inTestAsset,
}
// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores 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, filepath.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
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset,
"in/c/test.asset": in_c_test_asset,
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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,88 +1,312 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"log"
"reflect"
"unsafe"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
func bindata_read(data, name string) []byte {
var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:]
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bx.Data = sx.Data
bx.Len = len(data)
bx.Cap = bx.Len
gz, err := gzip.NewReader(bytes.NewBuffer(b))
func bindataRead(data, name string) ([]byte, error) {
gz, err := gzip.NewReader(strings.NewReader(data))
if err != nil {
log.Fatalf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
var buf bytes.Buffer
_, err = io.Copy(&buf, gz)
gz.Close()
clErr := gz.Close()
if err != nil {
log.Fatalf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %v", name, err)
}
if clErr != nil {
return nil, 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"
func in_b_test_asset() []byte {
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
type asset struct {
bytes []byte
info os.FileInfo
}
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() []byte {
return bindata_read(
_in_test_asset,
"in/test.asset",
)
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
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 (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
func in_a_test_asset() []byte {
return bindata_read(
_in_a_test_asset,
var _inATestAsset = "\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 inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
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 inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
func in_c_test_asset() []byte {
return bindata_read(
_in_c_test_asset,
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = "\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 inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset",
)
}
func inBTestAsset() (*asset, error) {
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = "\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 inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = "\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 inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset",
)
}
func inTestAsset() (*asset, error) {
bytes, err := inTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found.
func Asset(name string) []byte {
if f, ok := _bindata[name]; ok {
return f()
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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": inATestAsset,
"in/b/test.asset": inBTestAsset,
"in/c/test.asset": inCTestAsset,
"in/test.asset": inTestAsset,
}
// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores 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, filepath.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
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset,
"in/c/test.asset": in_c_test_asset,
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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, "/")...)...)
}

289
testdata/out/debug.go vendored
View File

@ -1,80 +1,263 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main
import (
"bytes"
"io"
"log"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
// bindata_read reads the given file from disk.
// It panics if anything went wrong.
func bindata_read(path, name string) []byte {
fd, err := os.Open(path)
// bindataRead reads the given file from disk. It returns an error on failure.
func bindataRead(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path)
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
}
// inATestAsset reads file data from disk. It returns an error on failure.
func inATestAsset() (*asset, error) {
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
name := "in/a/test.asset"
bytes, err := bindataRead(path, name)
if err != nil {
return nil, err
}
defer fd.Close()
var buf bytes.Buffer
_, err = io.Copy(&buf, fd)
fi, err := os.Stat(path)
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.
// It panics if something went wrong in the process.
func in_b_test_asset() []byte {
return bindata_read(
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
"in/b/test.asset",
)
// inBTestAsset reads file data from disk. It returns an error on failure.
func inBTestAsset() (*asset, error) {
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset"
name := "in/b/test.asset"
bytes, err := bindataRead(path, name)
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.
// It panics if something went wrong in the process.
func in_test_asset() []byte {
return bindata_read(
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
"in/test.asset",
)
// inCTestAsset reads file data from disk. It returns an error on failure.
func inCTestAsset() (*asset, error) {
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset"
name := "in/c/test.asset"
bytes, err := bindataRead(path, name)
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.
// It panics if something went wrong in the process.
func in_a_test_asset() []byte {
return bindata_read(
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
"in/a/test.asset",
)
}
// inTestAsset reads file data from disk. It returns an error on failure.
func inTestAsset() (*asset, error) {
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
name := "in/test.asset"
bytes, err := bindataRead(path, name)
if err != nil {
return nil, err
}
// in_c_test_asset reads file data from disk.
// It panics if something went wrong in the process.
func in_c_test_asset() []byte {
return bindata_read(
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
"in/c/test.asset",
)
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
}
// Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found.
func Asset(name string) []byte {
if f, ok := _bindata[name]; ok {
return f()
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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": inATestAsset,
"in/b/test.asset": inBTestAsset,
"in/c/test.asset": inCTestAsset,
"in/test.asset": inTestAsset,
}
// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores 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, filepath.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
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset,
"in/c/test.asset": in_c_test_asset,
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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, "/")...)...)
}

259
testdata/out/debug.go-bindata vendored Normal file
View File

@ -0,0 +1,259 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
"os"
"path"
"path/filepath"
)
// bindata_read reads the given file from disk. It returns an error on failure.
func bindata_read(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
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/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
name := "in/a/test.asset"
bytes, err := bindata_read(path, name)
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_b_test_asset reads file data from disk. It returns an error on failure.
func in_b_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset"
name := "in/b/test.asset"
bytes, err := bindata_read(path, name)
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_c_test_asset reads file data from disk. It returns an error on failure.
func in_c_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset"
name := "in/c/test.asset"
bytes, err := bindata_read(path, name)
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. It returns an error on failure.
func in_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
name := "in/test.asset"
bytes, err := bindata_read(path, name)
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
}
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if (err != nil) {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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,46 +1,280 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main
func in_b_test_asset() []byte {
return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
}
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
)
type asset struct {
bytes []byte
info os.FileInfo
}
func in_test_asset() []byte {
return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
}
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func in_a_test_asset() []byte {
return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
func in_c_test_asset() []byte {
return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
var _inATestAsset = []byte(`// sample file
`)
func inATestAssetBytes() ([]byte, error) {
return _inATestAsset, nil
}
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = []byte(`// sample file
`)
func inBTestAssetBytes() ([]byte, error) {
return _inBTestAsset, nil
}
func inBTestAsset() (*asset, error) {
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = []byte(`// sample file
`)
func inCTestAssetBytes() ([]byte, error) {
return _inCTestAsset, nil
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = []byte(`// sample file
`)
func inTestAssetBytes() ([]byte, error) {
return _inTestAsset, nil
}
func inTestAsset() (*asset, error) {
bytes, err := inTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found.
func Asset(name string) []byte {
if f, ok := _bindata[name]; ok {
return f()
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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": inATestAsset,
"in/b/test.asset": inBTestAsset,
"in/c/test.asset": inCTestAsset,
"in/test.asset": inTestAsset,
}
// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores 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, filepath.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
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset,
"in/c/test.asset": in_c_test_asset,
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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,25 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"time"
"unsafe"
)
func bindata_read(data, name string) []byte {
func bindataRead(data, name string) ([]byte, error) {
var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:]
@ -13,58 +27,276 @@ func bindata_read(data, name string) []byte {
bx.Data = sx.Data
bx.Len = len(data)
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"
func in_b_test_asset() []byte {
return bindata_read(
_in_b_test_asset,
"in/b/test.asset",
)
type asset struct {
bytes []byte
info os.FileInfo
}
var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func in_test_asset() []byte {
return bindata_read(
_in_test_asset,
"in/test.asset",
)
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
func in_a_test_asset() []byte {
return bindata_read(
_in_a_test_asset,
var _inATestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
func in_c_test_asset() []byte {
return bindata_read(
_in_c_test_asset,
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset",
)
}
func inBTestAsset() (*asset, error) {
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset",
)
}
func inTestAsset() (*asset, error) {
bytes, err := inTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// This returns nil of the asset could not be found.
func Asset(name string) []byte {
if f, ok := _bindata[name]; ok {
return f()
// 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)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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": inATestAsset,
"in/b/test.asset": inBTestAsset,
"in/c/test.asset": inCTestAsset,
"in/test.asset": inTestAsset,
}
// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores 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, filepath.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
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() []byte{
"in/b/test.asset": in_b_test_asset,
"in/test.asset": in_test_asset,
"in/a/test.asset": in_a_test_asset,
"in/c/test.asset": in_c_test_asset,
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.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, "/")...)...)
}

1
testdata/symlinkFile/file1 vendored Symbolic link
View File

@ -0,0 +1 @@
../symlinkSrc/file1

1
testdata/symlinkParent/symlinkTarget vendored Symbolic link
View File

@ -0,0 +1 @@
../symlinkSrc/

1
testdata/symlinkRecursiveParent/file1 vendored Normal file
View File

@ -0,0 +1 @@
// test file 1

View File

@ -0,0 +1 @@
../symlinkRecursiveParent/

1
testdata/symlinkSrc/file1 vendored Normal file
View File

@ -0,0 +1 @@
// symlink file 1

1
testdata/symlinkSrc/file2 vendored Normal file
View File

@ -0,0 +1 @@
// symlink file 2

1
testdata/symlinkSrc/file3 vendored Normal file
View File

@ -0,0 +1 @@
// symlink file 3

1
testdata/symlinkSrc/file4 vendored Normal file
View File

@ -0,0 +1 @@
// symlink file 4

184
toc.go
View File

@ -7,8 +7,139 @@ package bindata
import (
"fmt"
"io"
"sort"
"strings"
)
type assetTree struct {
Asset Asset
Children map[string]*assetTree
}
func newAssetTree() *assetTree {
tree := &assetTree{}
tree.Children = make(map[string]*assetTree)
return tree
}
func (node *assetTree) child(name string) *assetTree {
rv, ok := node.Children[name]
if !ok {
rv = newAssetTree()
node.Children[name] = rv
}
return rv
}
func (root *assetTree) Add(route []string, asset Asset) {
for _, name := range route {
root = root.child(name)
}
root.Asset = asset
}
func ident(w io.Writer, n int) {
for i := 0; i < n; i++ {
w.Write([]byte{'\t'})
}
}
func (root *assetTree) funcOrNil() string {
if root.Asset.Func == "" {
return "nil"
} else {
return root.Asset.Func
}
}
func (root *assetTree) writeGoMap(w io.Writer, nident int) {
fmt.Fprintf(w, "&bintree{%s, map[string]*bintree{", root.funcOrNil())
if len(root.Children) > 0 {
io.WriteString(w, "\n")
// Sort to make output stable between invocations
filenames := make([]string, len(root.Children))
i := 0
for filename, _ := range root.Children {
filenames[i] = filename
i++
}
sort.Strings(filenames)
for _, p := range filenames {
ident(w, nident+1)
fmt.Fprintf(w, `"%s": `, p)
root.Children[p].writeGoMap(w, nident+1)
}
ident(w, nident)
}
io.WriteString(w, "}}")
if nident > 0 {
io.WriteString(w, ",")
}
io.WriteString(w, "\n")
}
func (root *assetTree) WriteAsGoMap(w io.Writer) error {
_, err := fmt.Fprint(w, `type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = `)
root.writeGoMap(w, 0)
return err
}
func writeTOCTree(w io.Writer, toc []Asset) error {
_, err := fmt.Fprintf(w, `// 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 childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
`)
if err != nil {
return err
}
tree := newAssetTree()
for i := range toc {
pathList := strings.Split(toc[i].Name, "/")
tree.Add(pathList, toc[i])
}
return tree.WriteAsGoMap(w)
}
// writeTOC writes the table of contents file.
func writeTOC(w io.Writer, toc []Asset) error {
err := writeTOCHeader(w)
@ -28,19 +159,58 @@ func writeTOC(w io.Writer, toc []Asset) error {
// writeTOCHeader writes the table of contents file header.
func writeTOCHeader(w io.Writer) error {
_, err := fmt.Fprintf(w, `
// Asset loads and returns the asset for the given name.
_, err := fmt.Fprintf(w, `// 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) {
if f, ok := _bindata[name]; ok {
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, fmt.Errorf("Asset %%s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// 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() ([]byte, error) {
var _bindata = map[string]func() (*asset, error){
`)
return err
}
@ -53,8 +223,8 @@ func writeTOCAsset(w io.Writer, asset *Asset) error {
// writeTOCFooter writes the table of contents file footer.
func writeTOCFooter(w io.Writer) error {
_, err := fmt.Fprintf(w, `
}
_, err := fmt.Fprintf(w, `}
`)
return err
}