aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-02-15 00:39:24 +0900
committerOphestra <cat@gensokyo.uk>2026-02-15 00:39:24 +0900
commit5828631e79dc9ee788c8dc148de18d14994591ee (patch)
treee7a0326536e1a6087af307c83871a4933773f374 /internal/pkg/pkg.go
parent4f9f4875d715833ff2556199404575bc022830ca (diff)
internal/pkg: split off context common
For making these methods available to RContext. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index fdde9bec..54ac571d 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -65,18 +65,23 @@ func MustDecode(s string) (checksum Checksum) {
return
}
+// common holds elements and receives methods shared between different contexts.
+type common struct {
+ // Address of underlying [Cache], should be zeroed or made unusable after
+ // Cure returns and must not be exposed directly.
+ cache *Cache
+}
+
// TContext is passed to [TrivialArtifact.Cure] and provides information and
// methods required for curing the [TrivialArtifact].
//
// Methods of TContext are safe for concurrent use. TContext is valid
// until [TrivialArtifact.Cure] returns.
type TContext struct {
- // Address of underlying [Cache], should be zeroed or made unusable after
- // [TrivialArtifact.Cure] returns and must not be exposed directly.
- cache *Cache
-
// Populated during [Cache.Cure].
work, temp *check.Absolute
+
+ common
}
// destroy destroys the temporary directory and joins its errors with the error
@@ -104,10 +109,10 @@ func (t *TContext) destroy(errP *error) {
}
// Unwrap returns the underlying [context.Context].
-func (t *TContext) Unwrap() context.Context { return t.cache.ctx }
+func (c *common) Unwrap() context.Context { return c.cache.ctx }
// GetMessage returns [message.Msg] held by the underlying [Cache].
-func (t *TContext) GetMessage() message.Msg { return t.cache.msg }
+func (c *common) GetMessage() message.Msg { return c.cache.msg }
// GetWorkDir returns a pathname to a directory which [Artifact] is expected to
// write its output to. This is not the final resting place of the [Artifact]
@@ -126,13 +131,13 @@ func (t *TContext) GetTempDir() *check.Absolute { return t.temp }
// If err is nil, the caller must close the resulting [io.ReadCloser] and return
// its error, if any. Failure to read r to EOF may result in a spurious
// [ChecksumMismatchError], or the underlying implementation may block on Close.
-func (t *TContext) Open(a Artifact) (r io.ReadCloser, err error) {
+func (c *common) Open(a Artifact) (r io.ReadCloser, err error) {
if f, ok := a.(FileArtifact); ok {
- return t.cache.openFile(f)
+ return c.cache.openFile(f)
}
var pathname *check.Absolute
- if pathname, _, err = t.cache.Cure(a); err != nil {
+ if pathname, _, err = c.cache.Cure(a); err != nil {
return
}
@@ -1526,7 +1531,11 @@ func (c *Cache) cure(a Artifact, curesExempt bool) (
return
}
- t := TContext{c, c.base.Append(dirWork, ids), c.base.Append(dirTemp, ids)}
+ t := TContext{
+ c.base.Append(dirWork, ids),
+ c.base.Append(dirTemp, ids),
+ common{c},
+ }
switch ca := a.(type) {
case TrivialArtifact:
defer t.destroy(&err)