internal/pkg: append user-facing name in messages

This makes verbose messages much more useful.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-12 03:53:19 +09:00
parent 7ccc2fc5ec
commit 91c3594dee
3 changed files with 45 additions and 2 deletions

View File

@@ -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.