mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
0eb3e7975c
This reverts back to using `git archive` for the source archives... but will keep supporting extra files. ##### How it works: Basically, we run `git archive` as before. Then, we make a backup of the generated archive, and create a new one copying by reading from the backup and writing into the new one. Finally, we write the extra files to the new one as well. This only happens if the configuration does have extra files, otherwise, just the simple `git archive` will be run. PS: we can't just append to the archive because weird tar format paddings et al. --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
// Package targz implements the Archive interface providing tar.gz archiving
|
|
// and compression.
|
|
package targz
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"io"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/archive/tar"
|
|
"github.com/goreleaser/goreleaser/pkg/config"
|
|
)
|
|
|
|
// Archive as tar.gz.
|
|
type Archive struct {
|
|
gw *gzip.Writer
|
|
tw *tar.Archive
|
|
}
|
|
|
|
// New tar.gz archive.
|
|
func New(target io.Writer) Archive {
|
|
// the error will be nil since the compression level is valid
|
|
gw, _ := gzip.NewWriterLevel(target, gzip.BestCompression)
|
|
tw := tar.New(gw)
|
|
return Archive{
|
|
gw: gw,
|
|
tw: &tw,
|
|
}
|
|
}
|
|
|
|
func Copying(source io.Reader, target io.Writer) (Archive, error) {
|
|
// the error will be nil since the compression level is valid
|
|
gw, _ := gzip.NewWriterLevel(target, gzip.BestCompression)
|
|
srcgz, err := gzip.NewReader(source)
|
|
if err != nil {
|
|
return Archive{}, err
|
|
}
|
|
tw, err := tar.Copying(srcgz, gw)
|
|
return Archive{
|
|
gw: gw,
|
|
tw: &tw,
|
|
}, err
|
|
}
|
|
|
|
// Close all closeables.
|
|
func (a Archive) Close() error {
|
|
if err := a.tw.Close(); err != nil {
|
|
return err
|
|
}
|
|
return a.gw.Close()
|
|
}
|
|
|
|
// Add file to the archive.
|
|
func (a Archive) Add(f config.File) error {
|
|
return a.tw.Add(f)
|
|
}
|