internal/pkg: optional executable files
Test / Create distribution (push) Successful in 56s
Test / Sandbox (push) Successful in 2m54s
Test / ShareFS (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 5m33s
Test / Hakurei (race detector) (push) Successful in 6m48s
Test / Hakurei (push) Successful in 2m29s
Test / Flake checks (push) Successful in 1m10s

This enables a FileArtifact implementation to specify whether its resulting file should be executable. This change also implements shebang and ELF magic checks in the file artifact.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-07-23 17:10:22 +09:00
parent 67dbb68818
commit e0eec632d0
10 changed files with 93 additions and 36 deletions
+18 -2
View File
@@ -478,6 +478,8 @@ type KnownIdent interface {
// [Artifact]. This value must be known ahead of time and guaranteed to be
// unique without having obtained the full contents of the [Artifact].
ID() ID
Artifact
}
// KnownChecksum is optionally implemented by [Artifact] for an artifact with
@@ -489,6 +491,8 @@ type KnownChecksum interface {
//
// Result must remain identical across multiple invocations.
Checksum() Checksum
Artifact
}
// CuresExempt is optionally implemented for an artifact exempt to the
@@ -506,6 +510,12 @@ type CuresExempt interface {
// FileArtifact does not support fine-grained cancellation. Its context is
// inherited from the first [TrivialArtifact] or [FloodArtifact] that opens it.
type FileArtifact interface {
// IsExecutable returns whether the resulting filesystem entry should be made
// executable, if the [FileArtifact] is cured to the on-disk cache.
//
// Result must remain identical across multiple invocations.
IsExecutable() bool
// Cure returns [io.ReadCloser] of the full contents of [FileArtifact]. If
// [FileArtifact] implements [KnownChecksum], Cure is responsible for
// validating any data it produces and must return [ChecksumMismatchError]
@@ -515,7 +525,8 @@ type FileArtifact interface {
//
// Callers are responsible for closing the resulting [io.ReadCloser].
//
// Result must remain identical across multiple invocations.
// The resulting [io.ReadCloser] across multiple invocations must have
// identical behaviour.
Cure(r *RContext) (io.ReadCloser, error)
Artifact
@@ -2208,12 +2219,17 @@ func (c *Cache) cure(a Artifact, curesExempt, rebuild bool) (
return
}
perm := os.FileMode(0400)
if f.IsExecutable() {
perm = 0500
}
work := c.base.Append(dirWork, ids)
var w *os.File
if w, err = os.OpenFile(
work.String(),
os.O_CREATE|os.O_EXCL|os.O_WRONLY,
0400,
perm,
); err != nil {
return
}