aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/exec.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-12 04:17:47 +0900
committerOphestra <cat@gensokyo.uk>2026-01-12 04:17:47 +0900
commit29951c51749f1c3f5ca96488bff6eee247c03dc7 (patch)
tree12a482e08fa4449addcb50da302a5c824e9dbf60 /internal/pkg/exec.go
parent91c3594dee2f1689501997d395af7019df8bebe2 (diff)
internal/pkg: caller-supplied reporting name for exec
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>
Diffstat (limited to 'internal/pkg/exec.go')
-rw-r--r--internal/pkg/exec.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/pkg/exec.go b/internal/pkg/exec.go
index 2ded00e9..8fd6898f 100644
--- a/internal/pkg/exec.go
+++ b/internal/pkg/exec.go
@@ -4,7 +4,9 @@ import (
"bytes"
"context"
"errors"
+ "fmt"
"os"
+ "path"
"slices"
"strconv"
"syscall"
@@ -55,6 +57,8 @@ const (
// Methods of execArtifact does not modify any struct field or underlying arrays
// referred to by slices.
type execArtifact struct {
+ // Caller-supplied user-facing reporting name.
+ name string
// Caller-supplied inner mount points.
paths []ExecPath
@@ -73,6 +77,8 @@ type execArtifact struct {
timeout time.Duration
}
+var _ fmt.Stringer = new(execArtifact)
+
// execNetArtifact is like execArtifact but implements [KnownChecksum] and has
// its resulting container keep the host net namespace.
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
// negative timeout value is equivalent tp [ExecTimeoutDefault], a timeout value
// 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(
+ name string,
checksum *Checksum,
timeout time.Duration,
dir *check.Absolute,
env []string,
- path *check.Absolute,
+ pathname *check.Absolute,
args []string,
paths ...ExecPath,
) Artifact {
+ if name == "" {
+ name = "exec-" + path.Base(pathname.String())
+ }
if timeout <= 0 {
timeout = ExecTimeoutDefault
}
if timeout > ExecTimeoutMax {
timeout = ExecTimeoutMax
}
- a := execArtifact{paths, dir, env, path, args, timeout}
+ a := execArtifact{name, paths, dir, env, pathname, args, timeout}
if checksum == nil {
return &a
}
@@ -192,6 +206,9 @@ func (a *execArtifact) Dependencies() []Artifact {
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.
func (a *execArtifact) Cure(f *FContext) (err error) {
return a.cure(f, false)