forked from rosa/hakurei
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user