Documentation
¶
Overview ¶
Package stage owns everything that touches disk before a swap: the single-updater lock, the state directory, free-space checks, and the streamed, resumable, hash-verified download.
Index ¶
- Constants
- func CreateTemp(dir, suffix string) (*os.File, error)
- func Download(ctx context.Context, dir string, a ota.Artifact, fetch Fetcher, ...) (string, error)
- func EnsureDir(dir string) error
- func Free(dir string) (uint64, bool)
- func Held(stateDir, name string) bool
- func Partial(dir string) string
- func ReadJSON(path string, v any) error
- func Remove(path string) error
- func Sweep(dir string, keep ...string) error
- func SyncDir(dir string) error
- func WriteJSON(path string, v any) error
- type Fetcher
- type Lock
- type Progress
Constants ¶
const LauncherLock = "launcher.lock"
LauncherLock is held by a resident launcher for its whole life, so another process can tell a launcher is running without any socket or pid file.
const Margin = 64 << 20
Margin is kept free beyond the download itself, so finishing an update never fills the disk the program is about to run from.
const PartPrefix = ".ota-"
PartPrefix marks every temporary file this package creates, so a sweep can tell ours from anything else in the directory.
Variables ¶
This section is empty.
Functions ¶
func CreateTemp ¶
CreateTemp makes a new, empty temp file owner-only. O_EXCL means a file planted at a predictable name can never be opened and written through.
func Download ¶
func Download(ctx context.Context, dir string, a ota.Artifact, fetch Fetcher, progress Progress) (string, error)
Download streams an artifact into dir and returns the path of the complete, verified file (mode 0600). A partial left by an interrupted run for the same artifact is resumed, but only after its existing bytes are re-hashed, so a partial altered between runs can never be laundered by the final check.
On a transfer error the partial is kept for resume and ota.ErrDownload is returned. On a size overrun, hash mismatch or full disk the partial is deleted, since resuming it could only fail again.
func EnsureDir ¶
EnsureDir creates the state directory owner-only. It holds partial downloads of the program and the record of which version is trusted, so nobody else on the machine gets to read or plant files in it.
func Partial ¶
Partial returns the partial file named by an active download record, so the sweep keeps it.
func ReadJSON ¶
ReadJSON loads path into v. A missing file reports fs.ErrNotExist so callers can treat "no record" as a state, not a failure.
func Sweep ¶
Sweep removes temp files from crashed runs. keep names files still in use (the partial named by an active download record). Call only while holding the lock, or a live download in another process would be deleted under it.
Types ¶
type Fetcher ¶
Fetcher opens the artifact starting at offset. It returns the offset the body actually starts at: a source that ignores Range answers from 0, and the download then restarts rather than appending the wrong bytes.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held single-updater lock. The OS releases it if the process dies, so there is no stale-lock heuristic to get wrong.
func Acquire ¶
Acquire takes the lock for a state directory without blocking, returning ota.ErrLocked if another process holds it.
func AcquireNamed ¶
AcquireNamed takes a named lock in a state directory without blocking.