diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-06-04 18:37:07 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-06-04 18:54:43 +0900 |
| commit | db69dcf0be0c1be4e3187027fa4199538013e76d (patch) | |
| tree | 78513e0ec30c375af15270852d551f326c7f663f /internal/pkg/tar.go | |
| parent | 76c1fb84c87ba12a22b64f7c471a92603365837f (diff) | |
internal/pkg: remove tar built-in decompressor
This is replaced by decompressArtifact and is no longer necessary.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/tar.go')
| -rw-r--r-- | internal/pkg/tar.go | 79 |
1 files changed, 15 insertions, 64 deletions
diff --git a/internal/pkg/tar.go b/internal/pkg/tar.go index 1c558d52..0b40e103 100644 --- a/internal/pkg/tar.go +++ b/internal/pkg/tar.go @@ -2,32 +2,18 @@ package pkg import ( "archive/tar" - "compress/bzip2" - "compress/gzip" "errors" "fmt" "io" "io/fs" - "net/http" "os" "path/filepath" ) -const ( - // TarUncompressed denotes an uncompressed tarball. - TarUncompressed = iota - // TarGzip denotes a tarball compressed via [gzip]. - TarGzip - // TarBzip2 denotes a tarball compressed via [bzip2]. - TarBzip2 -) - // A tarArtifact is an [Artifact] unpacking a tarball backed by a [FileArtifact]. type tarArtifact struct { // Caller-supplied backing tarball. f Artifact - // Compression on top of the tarball. - compression uint32 } // tarArtifactNamed embeds tarArtifact for a [fmt.Stringer] tarball. @@ -42,10 +28,10 @@ var _ fmt.Stringer = new(tarArtifactNamed) // String returns the name of the underlying [Artifact] suffixed with unpack. func (a *tarArtifactNamed) String() string { return a.name + "-unpack" } -// NewTar returns a new [Artifact] backed by the supplied [Artifact] and -// compression method. The source [Artifact] must be a [FileArtifact]. -func NewTar(a Artifact, compression uint32) Artifact { - ta := tarArtifact{a, compression} +// NewTar returns a new [Artifact] unpacking the tar stream produced by the +// backing [Artifact]. The source [Artifact] must be a [FileArtifact]. +func NewTar(a Artifact) Artifact { + ta := tarArtifact{a} if s, ok := a.(fmt.Stringer); ok { if name := s.String(); name != "" { return &tarArtifactNamed{ta, name} @@ -54,25 +40,15 @@ func NewTar(a Artifact, compression uint32) Artifact { return &ta } -// NewHTTPGetTar is abbreviation for NewHTTPGet passed to NewTar. -func NewHTTPGetTar( - hc *http.Client, - url string, - checksum Checksum, - compression uint32, -) Artifact { - return NewTar(NewHTTPGet(hc, url, checksum), compression) -} - // Kind returns the hardcoded [Kind] constant. func (a *tarArtifact) Kind() Kind { return KindTar } -// Params writes compression encoded in little endian. -func (a *tarArtifact) Params(ctx *IContext) { ctx.WriteUint32(a.compression) } +// Params is a noop. +func (a *tarArtifact) Params(*IContext) {} func init() { register(KindTar, func(r *IRReader) Artifact { - a := NewTar(r.Next(), r.ReadUint32()) + a := NewTar(r.Next()) if _, ok := r.Finalise(); ok { panic(ErrUnexpectedChecksum) } @@ -98,42 +74,17 @@ func (e DisallowedTypeflagError) Error() string { // Cure cures the [Artifact], producing a directory located at work. func (a *tarArtifact) Cure(t *TContext) (err error) { - var tr io.ReadCloser - if tr, err = t.Open(a.f); err != nil { + var r io.ReadCloser + if r, err = t.Open(a.f); err != nil { return } - defer func(f io.ReadCloser) { - if err == nil { - err = tr.Close() - } - - closeErr := f.Close() + defer func() { + closeErr := r.Close() if err == nil { err = closeErr } - }(tr) - br := t.cache.getReader(tr) - defer t.cache.putReader(br) - tr = io.NopCloser(br) - - switch a.compression { - case TarUncompressed: - break - - case TarGzip: - if tr, err = gzip.NewReader(tr); err != nil { - return - } - break - - case TarBzip2: - tr = io.NopCloser(bzip2.NewReader(tr)) - break - - default: - return os.ErrInvalid - } + }() type dirTargetPerm struct { path string @@ -156,8 +107,8 @@ func (a *tarArtifact) Cure(t *TContext) (err error) { }() var header *tar.Header - r := tar.NewReader(tr) - for header, err = r.Next(); err == nil; header, err = r.Next() { + tr := tar.NewReader(r) + for header, err = tr.Next(); err == nil; header, err = tr.Next() { typeflag := header.Typeflag if typeflag == 0 { if len(header.Name) > 0 && header.Name[len(header.Name)-1] == '/' { @@ -183,7 +134,7 @@ func (a *tarArtifact) Cure(t *TContext) (err error) { ); err != nil { return } - if _, err = io.Copy(f, r); err != nil { + if _, err = io.Copy(f, tr); err != nil { _ = f.Close() return } else if err = f.Close(); err != nil { |
