Adjust release mode for AssetInfo()

This commit is contained in:
Ryosuke IWANAGA 2014-12-08 07:35:15 +09:00
parent f9f833bc6e
commit 5dec5f37be

View File

@ -34,19 +34,24 @@ func writeRelease(w io.Writer, c *Config, toc []Asset) error {
// writeReleaseHeader writes output file headers. // writeReleaseHeader writes output file headers.
// This targets release builds. // This targets release builds.
func writeReleaseHeader(w io.Writer, c *Config) error { func writeReleaseHeader(w io.Writer, c *Config) error {
var err error
if c.NoCompress { if c.NoCompress {
if c.NoMemCopy { if c.NoMemCopy {
return header_uncompressed_nomemcopy(w) err = header_uncompressed_nomemcopy(w)
} else { } else {
return header_uncompressed_memcopy(w) err = header_uncompressed_memcopy(w)
} }
} else { } else {
if c.NoMemCopy { if c.NoMemCopy {
return header_compressed_nomemcopy(w) err = header_compressed_nomemcopy(w)
} else { } 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. // writeReleaseAsset write a release entry for the given asset.
@ -62,17 +67,21 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
if c.NoCompress { if c.NoCompress {
if c.NoMemCopy { if c.NoMemCopy {
return uncompressed_nomemcopy(w, asset, fd) err = uncompressed_nomemcopy(w, asset, fd)
} else { } else {
return uncompressed_memcopy(w, asset, fd) err = uncompressed_memcopy(w, asset, fd)
} }
} else { } else {
if c.NoMemCopy { if c.NoMemCopy {
return compressed_nomemcopy(w, asset, fd) err = compressed_nomemcopy(w, asset, fd)
} else { } else {
return compressed_memcopy(w, asset, fd) err = compressed_memcopy(w, asset, fd)
} }
} }
if err != nil {
return err
}
return asset_release_common(w, asset)
} }
// sanitize prepares a valid UTF-8 string as a raw string constant. // sanitize prepares a valid UTF-8 string as a raw string constant.
@ -97,6 +106,8 @@ func header_compressed_nomemcopy(w io.Writer) error {
"reflect" "reflect"
"strings" "strings"
"unsafe" "unsafe"
"os"
"time"
) )
func bindata_read(data, name string) ([]byte, error) { func bindata_read(data, name string) ([]byte, error) {
@ -135,6 +146,8 @@ func header_compressed_memcopy(w io.Writer) error {
"fmt" "fmt"
"io" "io"
"strings" "strings"
"os"
"time"
) )
func bindata_read(data []byte, name string) ([]byte, error) { func bindata_read(data []byte, name string) ([]byte, error) {
@ -164,6 +177,8 @@ func header_uncompressed_nomemcopy(w io.Writer) error {
"reflect" "reflect"
"strings" "strings"
"unsafe" "unsafe"
"os"
"time"
) )
func bindata_read(data, name string) ([]byte, error) { func bindata_read(data, name string) ([]byte, error) {
@ -185,11 +200,49 @@ func header_uncompressed_memcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import ( _, err := fmt.Fprintf(w, `import (
"fmt" "fmt"
"strings" "strings"
"os"
"time"
) )
`) `)
return err return err
} }
func header_release_common(w io.Writer) error {
_, err := fmt.Fprintf(w, `type asset struct {
bytes []byte
info os.FileInfo
}
type bindata_file_info struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func (fi bindata_file_info) Name() string {
return fi.name
}
func (fi bindata_file_info) Size() int64 {
return fi.size
}
func (fi bindata_file_info) Mode() os.FileMode {
return fi.mode
}
func (fi bindata_file_info) ModTime() time.Time {
return fi.modTime
}
func (fi bindata_file_info) IsDir() bool {
return false
}
func (fi bindata_file_info) Sys() interface{} {
return nil
}
`)
return err
}
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error { func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func) _, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
if err != nil { if err != nil {
@ -206,7 +259,7 @@ func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `" _, err = fmt.Fprintf(w, `"
func %s() ([]byte, error) { func %s_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_%s, _%s,
%q, %q,
@ -233,7 +286,7 @@ func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `") _, err = fmt.Fprintf(w, `")
func %s() ([]byte, error) { func %s_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_%s, _%s,
%q, %q,
@ -257,7 +310,7 @@ func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `" _, err = fmt.Fprintf(w, `"
func %s() ([]byte, error) { func %s_bytes() ([]byte, error) {
return bindata_read( return bindata_read(
_%s, _%s,
%q, %q,
@ -286,10 +339,31 @@ func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `) _, err = fmt.Fprintf(w, `)
func %s() ([]byte, error) { func %s_bytes() ([]byte, error) {
return _%s, nil return _%s, nil
} }
`, asset.Func, asset.Func) `, asset.Func, asset.Func)
return err return err
} }
func asset_release_common(w io.Writer, asset *Asset) error {
fi, err := os.Stat(asset.Path)
if err != nil {
return err
}
_, err = fmt.Fprintf(w, `func %s() (*asset, error) {
bytes, err := %s_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{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, fi.Size(), uint32(fi.Mode()), fi.ModTime().Unix())
return err
}