Merge pull request #74 from tschottdorf/master

add `mode` and `modTime` flags
This commit is contained in:
Jim Teeuwen 2015-03-10 19:22:57 +01:00
commit 7362d4b6b2
3 changed files with 19 additions and 3 deletions

View File

@ -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.

View 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.")

View File

@ -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
}