All checks were successful
		
		
	
	Test / Create distribution (push) Successful in 34s
				
			Test / Sandbox (push) Successful in 2m9s
				
			Test / Hpkg (push) Successful in 3m58s
				
			Test / Sandbox (race detector) (push) Successful in 4m31s
				
			Test / Hakurei (race detector) (push) Successful in 5m19s
				
			Test / Hakurei (push) Successful in 2m12s
				
			Test / Flake checks (push) Successful in 1m31s
				
			This corrects minor mistakes in doc comments and adds them for undocumented constants. Signed-off-by: Ophestra <cat@gensokyo.uk>
		
			
				
	
	
		
			84 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package hst
 | |
| 
 | |
| import (
 | |
| 	"encoding/gob"
 | |
| 	"os"
 | |
| 	"strings"
 | |
| 
 | |
| 	"hakurei.app/container/check"
 | |
| )
 | |
| 
 | |
| func init() { gob.Register(new(FSEphemeral)) }
 | |
| 
 | |
| // FilesystemEphemeral is the type string of a mount point with ephemeral state.
 | |
| const FilesystemEphemeral = "ephemeral"
 | |
| 
 | |
| // FSEphemeral represents an ephemeral container mount point.
 | |
| type FSEphemeral struct {
 | |
| 	// Pathname in the container mount namespace.
 | |
| 	Target *check.Absolute `json:"dst"`
 | |
| 	// Do not mount filesystem read-only.
 | |
| 	Write bool `json:"write,omitempty"`
 | |
| 	// Upper limit on the size of the filesystem.
 | |
| 	Size int `json:"size,omitempty"`
 | |
| 	// Initial permission bits of the new filesystem.
 | |
| 	Perm os.FileMode `json:"perm,omitempty"`
 | |
| }
 | |
| 
 | |
| func (e *FSEphemeral) Valid() bool { return e != nil && e.Target != nil }
 | |
| 
 | |
| func (e *FSEphemeral) Path() *check.Absolute {
 | |
| 	if !e.Valid() {
 | |
| 		return nil
 | |
| 	}
 | |
| 	return e.Target
 | |
| }
 | |
| 
 | |
| func (e *FSEphemeral) Host() []*check.Absolute { return nil }
 | |
| 
 | |
| const fsEphemeralDefaultPerm = os.FileMode(0755)
 | |
| 
 | |
| func (e *FSEphemeral) Apply(z *ApplyState) {
 | |
| 	if !e.Valid() {
 | |
| 		return
 | |
| 	}
 | |
| 
 | |
| 	size := e.Size
 | |
| 	if size < 0 {
 | |
| 		size = 0
 | |
| 	}
 | |
| 
 | |
| 	perm := e.Perm
 | |
| 	if perm == 0 {
 | |
| 		perm = fsEphemeralDefaultPerm
 | |
| 	}
 | |
| 
 | |
| 	if e.Write {
 | |
| 		z.Tmpfs(e.Target, size, perm)
 | |
| 	} else {
 | |
| 		z.Readonly(e.Target, perm)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (e *FSEphemeral) String() string {
 | |
| 	if !e.Valid() {
 | |
| 		return "<invalid>"
 | |
| 	}
 | |
| 
 | |
| 	expr := new(strings.Builder)
 | |
| 	expr.Grow(15 + len(FilesystemEphemeral) + len(e.Target.String()))
 | |
| 
 | |
| 	if e.Write {
 | |
| 		expr.WriteString("w")
 | |
| 	}
 | |
| 	expr.WriteString("+" + FilesystemEphemeral + "(")
 | |
| 	if e.Perm != 0 {
 | |
| 		expr.WriteString(e.Perm.String())
 | |
| 	} else {
 | |
| 		expr.WriteString(fsEphemeralDefaultPerm.String())
 | |
| 	}
 | |
| 	expr.WriteString("):" + e.Target.String())
 | |
| 
 | |
| 	return expr.String()
 | |
| }
 |