From 7f4fb1184ff6bab28016ed674b61864665ba3d97 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Thu, 13 Aug 2015 15:37:16 -0400 Subject: [PATCH] Allow excluding metadata from built assets --- config.go | 2 ++ go-bindata/main.go | 1 + release.go | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 8c58b51..2bd0d56 100644 --- a/config.go +++ b/config.go @@ -127,6 +127,8 @@ type Config struct { // 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. diff --git a/go-bindata/main.go b/go-bindata/main.go index 55d9dc5..503a059 100644 --- a/go-bindata/main.go +++ b/go-bindata/main.go @@ -47,6 +47,7 @@ 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.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.") diff --git a/release.go b/release.go index 0766def..6a57dd5 100644 --- a/release.go +++ b/release.go @@ -359,7 +359,12 @@ func asset_release_common(w io.Writer, c *Config, asset *Asset) error { 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 } @@ -377,6 +382,6 @@ func asset_release_common(w io.Writer, c *Config, asset *Asset) error { return a, nil } -`, asset.Func, asset.Func, asset.Name, fi.Size(), mode, modTime) +`, asset.Func, asset.Func, asset.Name, size, mode, modTime) return err }