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>
This commit is contained in:
cat
2026-07-23 17:10:22 +09:00
parent 67dbb68818
commit e0eec632d0
10 changed files with 93 additions and 36 deletions
+15
View File
@@ -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