internal/pkg: append user-facing name in messages
All checks were successful
Test / Create distribution (push) Successful in 46s
Test / Sandbox (push) Successful in 2m58s
Test / ShareFS (push) Successful in 4m49s
Test / Sandbox (race detector) (push) Successful in 5m25s
Test / Hpkg (push) Successful in 5m31s
Test / Hakurei (push) Successful in 5m46s
Test / Hakurei (race detector) (push) Successful in 7m46s
Test / Flake checks (push) Successful in 1m47s
All checks were successful
Test / Create distribution (push) Successful in 46s
Test / Sandbox (push) Successful in 2m58s
Test / ShareFS (push) Successful in 4m49s
Test / Sandbox (race detector) (push) Successful in 5m25s
Test / Hpkg (push) Successful in 5m31s
Test / Hakurei (push) Successful in 5m46s
Test / Hakurei (race detector) (push) Successful in 7m46s
Test / Flake checks (push) Successful in 1m47s
This makes verbose messages much more useful. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -3,8 +3,10 @@ package pkg
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ type httpArtifact struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ KnownChecksum = new(httpArtifact)
|
var _ KnownChecksum = new(httpArtifact)
|
||||||
|
var _ fmt.Stringer = new(httpArtifact)
|
||||||
|
|
||||||
// NewHTTPGet returns a new [File] backed by the supplied client. A GET request
|
// 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.
|
// 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.
|
// Checksum returns the caller-supplied checksum.
|
||||||
func (a *httpArtifact) Checksum() Checksum { return a.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]
|
// ResponseStatusError is returned for a response returned by an [http.Client]
|
||||||
// with a status code other than [http.StatusOK].
|
// with a status code other than [http.StatusOK].
|
||||||
type ResponseStatusError int
|
type ResponseStatusError int
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
@@ -278,6 +279,20 @@ func Ident(a Artifact) ID {
|
|||||||
return a.Kind().Ident(a.Params(), a.Dependencies()...)
|
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
|
// Kind corresponds to the concrete type of [Artifact] and is used to create
|
||||||
// identifier for an [Artifact] with dependencies.
|
// identifier for an [Artifact] with dependencies.
|
||||||
type Kind uint64
|
type Kind uint64
|
||||||
@@ -725,6 +740,9 @@ func (c *Cache) openFile(f File) (r io.ReadCloser, err error) {
|
|||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if c.msg.IsVerbose() {
|
||||||
|
c.msg.Verbosef("curing %s to memory...", reportName(f))
|
||||||
|
}
|
||||||
var data []byte
|
var data []byte
|
||||||
if data, err = f.Cure(c.ctx); err != nil {
|
if data, err = f.Cure(c.ctx); err != nil {
|
||||||
return
|
return
|
||||||
@@ -917,7 +935,7 @@ func (c *Cache) Cure(a Artifact) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.msg.IsVerbose() {
|
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
|
// cure File outside type switch to skip TContext initialisation
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -32,11 +33,29 @@ type tarArtifact struct {
|
|||||||
compression uint64
|
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
|
// NewTar returns a new [Artifact] backed by the supplied [Artifact] and
|
||||||
// compression method. The source [Artifact] must be compatible with
|
// compression method. The source [Artifact] must be compatible with
|
||||||
// [TContext.Open].
|
// [TContext.Open].
|
||||||
func NewTar(a Artifact, compression uint64) Artifact {
|
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.
|
// NewHTTPGetTar is abbreviation for NewHTTPGet passed to NewTar.
|
||||||
|
|||||||
Reference in New Issue
Block a user