aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/file.go
diff options
context:
space:
mode:
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