diff options
author | Felix Lange <fjl@twurst.com> | 2016-11-03 20:44:16 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-11-03 20:44:16 +0800 |
commit | ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c (patch) | |
tree | 607dacdb7baeda5e4138bca28b4b0fa1ff4843ac /internal/build | |
parent | d0c820acd697964c8480d91e1fa10615276b3ef6 (diff) | |
download | go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar.gz go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar.bz2 go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar.lz go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar.xz go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.tar.zst go-tangerine-ed2bc7fbe9a30c1861cffdd7d0fd570847a2ae0c.zip |
build, internal/build: misc improvements (#3229)
* travis.yml: don't create darwin/386 builds
* build: remove godep remains
* internal/build: improve archives
- enable compression for zip files
- don't write half-complete archives
* build: add -unstable to archive names
Diffstat (limited to 'internal/build')
-rw-r--r-- | internal/build/archive.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/internal/build/archive.go b/internal/build/archive.go index 2a7090c0d..ac680ba63 100644 --- a/internal/build/archive.go +++ b/internal/build/archive.go @@ -41,14 +41,14 @@ type Archive interface { Close() error } -func NewArchive(file *os.File) Archive { +func NewArchive(file *os.File) (Archive, string) { switch { case strings.HasSuffix(file.Name(), ".zip"): - return NewZipArchive(file) + return NewZipArchive(file), strings.TrimSuffix(file.Name(), ".zip") case strings.HasSuffix(file.Name(), ".tar.gz"): - return NewTarballArchive(file) + return NewTarballArchive(file), strings.TrimSuffix(file.Name(), ".tar.gz") default: - return nil + return nil, "" } } @@ -74,17 +74,24 @@ func AddFile(a Archive, file string) error { } // WriteArchive creates an archive containing the given files. -func WriteArchive(basename, ext string, files []string) error { - archfd, err := os.Create(basename + ext) +func WriteArchive(name string, files []string) (err error) { + archfd, err := os.Create(name) if err != nil { return err } - defer archfd.Close() - archive := NewArchive(archfd) + + defer func() { + archfd.Close() + // Remove the half-written archive on failure. + if err != nil { + os.Remove(name) + } + }() + archive, basename := NewArchive(archfd) if archive == nil { - return fmt.Errorf("unknown archive extension: %s", ext) + return fmt.Errorf("unknown archive extension") } - fmt.Println(basename + ext) + fmt.Println(name) if err := archive.Directory(basename); err != nil { return err } @@ -118,6 +125,7 @@ func (a *ZipArchive) Header(fi os.FileInfo) (io.Writer, error) { return nil, fmt.Errorf("can't make zip header: %v", err) } head.Name = a.dir + head.Name + head.Method = zip.Deflate w, err := a.zipw.CreateHeader(head) if err != nil { return nil, fmt.Errorf("can't add zip header: %v", err) |