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/...
This commit is contained in:
parent
040617c5ef
commit
b5d9eff767
|
@ -127,6 +127,11 @@ type Config struct {
|
|||
// repository.
|
||||
Dev 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.
|
||||
|
|
|
@ -47,6 +47,8 @@ func parseArgs() *bindata.Config {
|
|||
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.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.")
|
||||
|
||||
|
|
15
release.go
15
release.go
|
@ -81,7 +81,7 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return asset_release_common(w, asset)
|
||||
return asset_release_common(w, c, asset)
|
||||
}
|
||||
|
||||
// sanitize prepares a valid UTF-8 string as a raw string constant.
|
||||
|
@ -359,12 +359,21 @@ func %s_bytes() ([]byte, error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func asset_release_common(w io.Writer, asset *Asset) error {
|
||||
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()
|
||||
|
||||
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 := %s_bytes()
|
||||
if err != nil {
|
||||
|
@ -376,6 +385,6 @@ func asset_release_common(w io.Writer, asset *Asset) error {
|
|||
return a, nil
|
||||
}
|
||||
|
||||
`, asset.Func, asset.Func, asset.Name, fi.Size(), uint32(fi.Mode()), fi.ModTime().Unix())
|
||||
`, asset.Func, asset.Func, asset.Name, fi.Size(), mode, modTime)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user