aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-07-23 17:10:22 +0900
committerOphestra <cat@gensokyo.uk>2026-07-23 17:10:22 +0900
commite0eec632d0a7cca2fb09e026997fa9a39dcd7504 (patch)
tree705ecc285e4fe05c3bba126a276c2e9e28ae9ec8 /internal/pkg/pkg.go
parent67dbb68818026f3d7a64e9519cf1aac36468b7c9 (diff)
internal/pkg: optional executable files
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>
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index ae3a8185..f837fade 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -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
}