diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-12 03:53:19 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-12 03:53:19 +0900 |
| commit | 91c3594dee2f1689501997d395af7019df8bebe2 (patch) | |
| tree | c8f88efdb9d791179f9682e6ea8d2da987548d42 /internal/pkg/tar.go | |
| parent | 7ccc2fc5ece9c6236c02585ef4048fdc2b4a5b51 (diff) | |
internal/pkg: append user-facing name in messages
This makes verbose messages much more useful.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/tar.go')
| -rw-r--r-- | internal/pkg/tar.go | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/internal/pkg/tar.go b/internal/pkg/tar.go index 624eafe2..0aa8e3bf 100644 --- a/internal/pkg/tar.go +++ b/internal/pkg/tar.go @@ -6,6 +6,7 @@ import ( "compress/gzip" "encoding/binary" "errors" + "fmt" "io" "io/fs" "net/http" @@ -32,11 +33,29 @@ type tarArtifact struct { compression uint64 } +// tarArtifactNamed embeds tarArtifact for a [fmt.Stringer] tarball. +type tarArtifactNamed struct { + tarArtifact + // Copied from tarArtifact.f. + name string +} + +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 compatible with // [TContext.Open]. func NewTar(a Artifact, compression uint64) Artifact { - return &tarArtifact{a, compression} + ta := tarArtifact{a, compression} + if s, ok := a.(fmt.Stringer); ok { + if name := s.String(); name != "" { + return &tarArtifactNamed{ta, name} + } + } + return &ta } // NewHTTPGetTar is abbreviation for NewHTTPGet passed to NewTar. |
