aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-12 03:53:19 +0900
committerOphestra <cat@gensokyo.uk>2026-01-12 03:53:19 +0900
commit91c3594dee2f1689501997d395af7019df8bebe2 (patch)
treec8f88efdb9d791179f9682e6ea8d2da987548d42 /internal
parent7ccc2fc5ece9c6236c02585ef4048fdc2b4a5b51 (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')
-rw-r--r--internal/pkg/net.go6
-rw-r--r--internal/pkg/pkg.go20
-rw-r--r--internal/pkg/tar.go21
3 files changed, 45 insertions, 2 deletions
diff --git a/internal/pkg/net.go b/internal/pkg/net.go
index 737dfd85..b8d85b91 100644
--- a/internal/pkg/net.go
+++ b/internal/pkg/net.go
@@ -3,8 +3,10 @@ package pkg
import (
"context"
"crypto/sha512"
+ "fmt"
"io"
"net/http"
+ "path"
"sync"
)
@@ -30,6 +32,7 @@ type httpArtifact struct {
}
var _ KnownChecksum = new(httpArtifact)
+var _ fmt.Stringer = new(httpArtifact)
// NewHTTPGet returns a new [File] backed by the supplied client. A GET request
// is set up for url. If c is nil, [http.DefaultClient] is used instead.
@@ -57,6 +60,9 @@ func (a *httpArtifact) Dependencies() []Artifact { return nil }
// Checksum returns the caller-supplied checksum.
func (a *httpArtifact) Checksum() Checksum { return a.checksum }
+// String returns [path.Base] over the backing url.
+func (a *httpArtifact) String() string { return path.Base(a.url) }
+
// ResponseStatusError is returned for a response returned by an [http.Client]
// with a status code other than [http.StatusOK].
type ResponseStatusError int
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index 60898b48..c1a3f97e 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -8,6 +8,7 @@ import (
"encoding/base64"
"encoding/binary"
"errors"
+ "fmt"
"io"
"io/fs"
"os"
@@ -278,6 +279,20 @@ func Ident(a Artifact) ID {
return a.Kind().Ident(a.Params(), a.Dependencies()...)
}
+// reportNameIdent is like reportName but does not recompute [ID].
+func reportNameIdent(a Artifact, id ID) string {
+ r := Encode(id)
+ if s, ok := a.(fmt.Stringer); ok {
+ if name := s.String(); name != "" {
+ r += "-" + name
+ }
+ }
+ return r
+}
+
+// reportName returns a string describing [Artifact] presented to the user.
+func reportName(a Artifact) string { return reportNameIdent(a, Ident(a)) }
+
// Kind corresponds to the concrete type of [Artifact] and is used to create
// identifier for an [Artifact] with dependencies.
type Kind uint64
@@ -725,6 +740,9 @@ func (c *Cache) openFile(f File) (r io.ReadCloser, err error) {
if !errors.Is(err, os.ErrNotExist) {
return
}
+ if c.msg.IsVerbose() {
+ c.msg.Verbosef("curing %s to memory...", reportName(f))
+ }
var data []byte
if data, err = f.Cure(c.ctx); err != nil {
return
@@ -917,7 +935,7 @@ func (c *Cache) Cure(a Artifact) (
}
if c.msg.IsVerbose() {
- c.msg.Verbosef("curing %s...", Encode(id))
+ c.msg.Verbosef("curing %s...", reportNameIdent(a, id))
}
// cure File outside type switch to skip TContext initialisation
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.