state

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state owns bitc's on-disk layout (spec 9).

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the state-dir schema this binary writes and understands.

Variables

This section is empty.

Functions

func AccountDir

func AccountDir(e *config.Effective) (string, error)

AccountDir is <passwd home>/.local/state/bitc/account (spec 2, 9). No env, flag or key moves it, so a private BITC_DIR or BITC_CONFIG cannot multiply the cap; only [test] accounting_dir. Like the state dir it is refused (78) on a network filesystem: the launch lock, the ledger and the reservations that hold the spend cap need a reliable flock.

func AccountDirOnNetworkFS added in v0.1.3

func AccountDirOnNetworkFS(e *config.Effective) (dir, netfs string, err error)

AccountDirOnNetworkFS is AccountDir for sweep, which still has work to do on a network filesystem: it returns the dir and, instead of refusing, the name of the network filesystem ("" for a local one). The caller must then treat the dir as read-only and its locks as untrusted; a dir that does not exist yet is not created there.

func AppendHistory

func AppendHistory(path string, e Event, red *redact.Set) error

AppendHistory appends one redacted JSON line with a single O_APPEND write.

func Check added in v0.1.2

func Check(root string) error

Check runs Open's refusals on an existing state dir without creating or writing anything; a missing dir passes, since the first command creates it 0700.

func CheckAccountDir added in v0.1.3

func CheckAccountDir(e *config.Effective) error

CheckAccountDir is AccountDir's filesystem refusal without creating anything. Its callers are config check and status. A missing dir is judged by its nearest existing parent, so a fresh network-filesystem home is refused before the first remote command creates the dir there.

func Install16

func Install16(secret []byte) string

Install16 is 16 hex of sha256(secret).

func InstallSecret

func InstallSecret(dir string) ([]byte, error)

InstallSecret returns the 32-byte install secret, creating it once. The file appears atomically (a full temp file linked into place), so no reader sees a partial secret; a file of any other length is an error rather than a key.

func MkdirPrivate

func MkdirPrivate(path string) error

MkdirPrivate creates path and missing parents with 0700 and checks path itself: owned by the user, not group- or world-accessible.

func ReadInstallSecret added in v0.1.3

func ReadInstallSecret(dir string) ([]byte, error)

ReadInstallSecret is InstallSecret without creating anything: a missing secret is an error.

func Shorten added in v0.1.6

func Shorten(s string, n int) string

Shorten cuts s to at most n bytes at a UTF-8 boundary and ends it with the history cut marker, or returns s whole when it is not longer than n.

func StubNetworkFS added in v0.1.3

func StubNetworkFS(under string) (restore func())

StubNetworkFS makes statfs of a path under `under` (every path if "") report NFS until the returned function is called. For tests in other packages; the seam itself is unexported. It swaps a global without a lock, so a test using it must not run in parallel.

func WriteFileAtomic

func WriteFileAtomic(path string, b []byte) error

WriteFileAtomic writes b to path (0600) through a temp file and rename.

Types

type Event

type Event struct {
	TS            string         `json:"ts"`
	Event         string         `json:"event"` // start | end | starved | fallback | reaped
	Pool          string         `json:"pool"`
	Slot          int            `json:"slot,omitempty"`
	Units         map[string]int `json:"units,omitempty"` // units held per group (start and end)
	Job           string         `json:"job"`
	Pid           int            `json:"pid"`
	Nested        bool           `json:"nested,omitempty"`
	Argv          []string       `json:"argv"`
	ArgvTruncated bool           `json:"argv_truncated,omitempty"`
	Cwd           string         `json:"cwd"`
	Provider      string         `json:"provider"`
	Resource      string         `json:"resource,omitempty"`
	Sha           string         `json:"sha,omitempty"`
	Head          string         `json:"head,omitempty"`       // git HEAD of the run's work tree at hold start
	TreeClean     *bool          `json:"tree_clean,omitempty"` // git status --porcelain was empty at hold start
	WaitMS        *int64         `json:"wait_ms,omitempty"`
	RunMS         *int64         `json:"run_ms,omitempty"`
	Exit          *int           `json:"exit,omitempty"`
	Outcome       string         `json:"outcome,omitempty"`
	Reason        string         `json:"reason,omitempty"`
}

Event is one history.jsonl line (spec 9). Refusals write nothing.

type Layout

type Layout struct{ Root string }

Layout names every path in a state dir. Root is absolute.

func Open

func Open(root string) (Layout, error)

Open creates the state dir (0700) or checks an existing one, then checks SCHEMA. Every refusal is 78 (spec 9).

func (Layout) AdmitLock

func (l Layout) AdmitLock() string

func (Layout) ContainersDir added in v0.1.6

func (l Layout) ContainersDir() string

ContainersDir holds a containerized run's --cidfile (<ticket>.cid): docker writes the id there once the container exists, which tells a docker failure from the command's own exit 125.

func (Layout) GroupUnitLock

func (l Layout) GroupUnitLock(g string, j int) string

func (Layout) History

func (l Layout) History() string

func (Layout) JobDir

func (l Layout) JobDir(wt8, name string) string

func (Layout) JobsDir

func (l Layout) JobsDir() string

func (Layout) NestLock

func (l Layout) NestLock(p string, i, depth int) string

func (Layout) PoolDir

func (l Layout) PoolDir(p string) string

func (Layout) Reservations

func (l Layout) Reservations() string

func (Layout) Schema

func (l Layout) Schema() string

func (Layout) SlotLock

func (l Layout) SlotLock(p string, i int) string

func (Layout) Tickets

func (l Layout) Tickets(p string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL