aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/file.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/file.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/file.go')
-rw-r--r--internal/pkg/file.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/pkg/file.go b/internal/pkg/file.go
index 1b6b02f7..14467153 100644
--- a/internal/pkg/file.go
+++ b/internal/pkg/file.go
@@ -12,6 +12,7 @@ type fileArtifact []byte
var _ KnownChecksum = new(fileArtifact)
var _ CuresExempt = new(fileArtifact)
+var _ RevisionArtifact = new(fileArtifact)
// fileArtifactNamed embeds fileArtifact alongside a caller-supplied name.
type fileArtifactNamed struct {
@@ -76,6 +77,20 @@ func (a *fileArtifact) Checksum() Checksum {
return Checksum(h.Sum(nil))
}
+// Revision satisfies [RevisionArtifact] for incompatible IsExecutable behaviour.
+func (*fileArtifact) Revision() uint64 { return 0 }
+
+// IsExecutable returns whether the contents begin with shebang or the ELF
+// magic number.
+func (a *fileArtifact) IsExecutable() bool {
+ return a != nil &&
+ (bytes.HasPrefix(
+ *a, []byte{'#', '!'},
+ ) || bytes.HasPrefix(
+ *a, []byte{0x7f, 'E', 'L', 'F'},
+ ))
+}
+
// Cure returns the caller-supplied data.
func (a *fileArtifact) Cure(*RContext) (io.ReadCloser, error) {
return io.NopCloser(bytes.NewReader(*a)), nil