internal/pkg: caller-supplied reporting name for exec
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m54s
Test / ShareFS (push) Successful in 4m55s
Test / Sandbox (race detector) (push) Successful in 5m19s
Test / Hpkg (push) Successful in 5m20s
Test / Hakurei (push) Successful in 5m44s
Test / Hakurei (race detector) (push) Successful in 7m49s
Test / Flake checks (push) Successful in 1m45s
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m54s
Test / ShareFS (push) Successful in 4m55s
Test / Sandbox (race detector) (push) Successful in 5m19s
Test / Hpkg (push) Successful in 5m20s
Test / Hakurei (push) Successful in 5m44s
Test / Hakurei (race detector) (push) Successful in 7m49s
Test / Flake checks (push) Successful in 1m45s
This does not have a reasonable way of inferring the underlying name. For zero value it falls back to base of executable pathname. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -55,6 +57,8 @@ const (
|
|||||||
// Methods of execArtifact does not modify any struct field or underlying arrays
|
// Methods of execArtifact does not modify any struct field or underlying arrays
|
||||||
// referred to by slices.
|
// referred to by slices.
|
||||||
type execArtifact struct {
|
type execArtifact struct {
|
||||||
|
// Caller-supplied user-facing reporting name.
|
||||||
|
name string
|
||||||
// Caller-supplied inner mount points.
|
// Caller-supplied inner mount points.
|
||||||
paths []ExecPath
|
paths []ExecPath
|
||||||
|
|
||||||
@@ -73,6 +77,8 @@ type execArtifact struct {
|
|||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ fmt.Stringer = new(execArtifact)
|
||||||
|
|
||||||
// execNetArtifact is like execArtifact but implements [KnownChecksum] and has
|
// execNetArtifact is like execArtifact but implements [KnownChecksum] and has
|
||||||
// its resulting container keep the host net namespace.
|
// its resulting container keep the host net namespace.
|
||||||
type execNetArtifact struct {
|
type execNetArtifact struct {
|
||||||
@@ -119,24 +125,32 @@ func (a *execNetArtifact) Cure(f *FContext) error {
|
|||||||
// process and all processes originating from it is terminated. A zero or
|
// process and all processes originating from it is terminated. A zero or
|
||||||
// negative timeout value is equivalent tp [ExecTimeoutDefault], a timeout value
|
// negative timeout value is equivalent tp [ExecTimeoutDefault], a timeout value
|
||||||
// greater than [ExecTimeoutMax] is equivalent to [ExecTimeoutMax].
|
// greater than [ExecTimeoutMax] is equivalent to [ExecTimeoutMax].
|
||||||
|
//
|
||||||
|
// The user-facing name is not accessible from the container and does not
|
||||||
|
// affect curing outcome. Because of this, it is omitted from parameter data
|
||||||
|
// for computing identifier.
|
||||||
func NewExec(
|
func NewExec(
|
||||||
|
name string,
|
||||||
checksum *Checksum,
|
checksum *Checksum,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
|
|
||||||
dir *check.Absolute,
|
dir *check.Absolute,
|
||||||
env []string,
|
env []string,
|
||||||
path *check.Absolute,
|
pathname *check.Absolute,
|
||||||
args []string,
|
args []string,
|
||||||
|
|
||||||
paths ...ExecPath,
|
paths ...ExecPath,
|
||||||
) Artifact {
|
) Artifact {
|
||||||
|
if name == "" {
|
||||||
|
name = "exec-" + path.Base(pathname.String())
|
||||||
|
}
|
||||||
if timeout <= 0 {
|
if timeout <= 0 {
|
||||||
timeout = ExecTimeoutDefault
|
timeout = ExecTimeoutDefault
|
||||||
}
|
}
|
||||||
if timeout > ExecTimeoutMax {
|
if timeout > ExecTimeoutMax {
|
||||||
timeout = ExecTimeoutMax
|
timeout = ExecTimeoutMax
|
||||||
}
|
}
|
||||||
a := execArtifact{paths, dir, env, path, args, timeout}
|
a := execArtifact{name, paths, dir, env, pathname, args, timeout}
|
||||||
if checksum == nil {
|
if checksum == nil {
|
||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
@@ -192,6 +206,9 @@ func (a *execArtifact) Dependencies() []Artifact {
|
|||||||
return slices.Concat(artifacts...)
|
return slices.Concat(artifacts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the caller-supplied reporting name.
|
||||||
|
func (a *execArtifact) String() string { return a.name }
|
||||||
|
|
||||||
// Cure cures the [Artifact] in the container described by the caller.
|
// Cure cures the [Artifact] in the container described by the caller.
|
||||||
func (a *execArtifact) Cure(f *FContext) (err error) {
|
func (a *execArtifact) Cure(f *FContext) (err error) {
|
||||||
return a.cure(f, false)
|
return a.cure(f, false)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func TestExec(t *testing.T) {
|
|||||||
|
|
||||||
cureMany(t, c, []cureStep{
|
cureMany(t, c, []cureStep{
|
||||||
{"container", pkg.NewExec(
|
{"container", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1"},
|
[]string{"HAKUREI_TEST=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -61,7 +61,7 @@ func TestExec(t *testing.T) {
|
|||||||
), ignorePathname, wantChecksumOffline, nil},
|
), ignorePathname, wantChecksumOffline, nil},
|
||||||
|
|
||||||
{"error passthrough", pkg.NewExec(
|
{"error passthrough", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1"},
|
[]string{"HAKUREI_TEST=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -77,7 +77,7 @@ func TestExec(t *testing.T) {
|
|||||||
), nil, pkg.Checksum{}, errors.Join(stub.UniqueError(0xcafe))},
|
), nil, pkg.Checksum{}, errors.Join(stub.UniqueError(0xcafe))},
|
||||||
|
|
||||||
{"invalid paths", pkg.NewExec(
|
{"invalid paths", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1"},
|
[]string{"HAKUREI_TEST=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -90,7 +90,7 @@ func TestExec(t *testing.T) {
|
|||||||
// check init failure passthrough
|
// check init failure passthrough
|
||||||
var exitError *exec.ExitError
|
var exitError *exec.ExitError
|
||||||
if _, _, err := c.Cure(pkg.NewExec(
|
if _, _, err := c.Cure(pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
nil,
|
nil,
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -112,7 +112,7 @@ func TestExec(t *testing.T) {
|
|||||||
)
|
)
|
||||||
cureMany(t, c, []cureStep{
|
cureMany(t, c, []cureStep{
|
||||||
{"container", pkg.NewExec(
|
{"container", pkg.NewExec(
|
||||||
&wantChecksum, 0,
|
"", &wantChecksum, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1"},
|
[]string{"HAKUREI_TEST=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -144,7 +144,7 @@ func TestExec(t *testing.T) {
|
|||||||
|
|
||||||
cureMany(t, c, []cureStep{
|
cureMany(t, c, []cureStep{
|
||||||
{"container", pkg.NewExec(
|
{"container", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
@@ -170,7 +170,7 @@ func TestExec(t *testing.T) {
|
|||||||
|
|
||||||
cureMany(t, c, []cureStep{
|
cureMany(t, c, []cureStep{
|
||||||
{"container", pkg.NewExec(
|
{"container", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
||||||
check.MustAbs("/work/bin/testtool"),
|
check.MustAbs("/work/bin/testtool"),
|
||||||
@@ -201,7 +201,7 @@ func TestExec(t *testing.T) {
|
|||||||
|
|
||||||
cureMany(t, c, []cureStep{
|
cureMany(t, c, []cureStep{
|
||||||
{"container", pkg.NewExec(
|
{"container", pkg.NewExec(
|
||||||
nil, 0,
|
"", nil, 0,
|
||||||
pkg.AbsWork,
|
pkg.AbsWork,
|
||||||
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
[]string{"HAKUREI_TEST=1", "HAKUREI_ROOT=1"},
|
||||||
check.MustAbs("/opt/bin/testtool"),
|
check.MustAbs("/opt/bin/testtool"),
|
||||||
|
|||||||
Reference in New Issue
Block a user