state

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package state persists the apply resume cursor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default state file path when no profile is known. Prefer ProfileStatePath for normal CLI use; DefaultPath is a fallback for direct API callers that do not have a profile root. It returns an error when neither XDG_STATE_HOME nor a user home directory is available so the empty string never flows into MkdirAll.

func ProfileStatePath added in v0.2.0

func ProfileStatePath(profileRoot string) string

ProfileStatePath returns the default state file path for a profile root. The path is located under the XDG state directory so the profile directory is not polluted with runtime state.

Types

type FileStore

type FileStore struct {
	Path string
	// contains filtered or unexported fields
}

FileStore saves state to a JSON file.

Concurrency: mutual exclusion between processes is provided by an flock(LOCK_EX) on the sidecar file <Path>.lock (see Lock), never on the state file itself. Save replaces the state file via tmp+rename, so a lock taken on the state file's inode would stay behind on the unlinked inode while later openers lock the new inode — the sidecar path is stable across renames. Load and Save do NOT lock internally; callers that need a load→modify→save critical section must hold Lock across it (cmd/apply does). Lock-free readers are still safe: rename is atomic, so Load never observes a torn write.

func NewFileStore

func NewFileStore(path string) *FileStore

NewFileStore returns a FileStore using the given path. An empty path falls back to DefaultPath; if no default can be determined the store's Path stays empty and Load/Save/Lock return an explicit error.

func (*FileStore) Load

func (fs *FileStore) Load() (*State, error)

Load reads the state file, returning a fresh state if it does not exist.

func (*FileStore) Lock added in v0.2.0

func (fs *FileStore) Lock() error

Lock acquires the exclusive sidecar lock, blocking until it is available. Hold it across the entire load→pipeline→save window; it is idempotent on a FileStore that already holds it.

func (*FileStore) LockPath added in v0.2.0

func (fs *FileStore) LockPath() string

LockPath returns the sidecar lock file path. The sidecar is never renamed, so a lock held on it survives Save's atomic tmp+rename of the state file.

func (*FileStore) Remove added in v0.14.0

func (fs *FileStore) Remove() error

Remove deletes the state file; a missing file is not an error.

func (*FileStore) Save

func (fs *FileStore) Save(s *State) error

Save writes the state file atomically (tmp file, fsync, rename).

func (*FileStore) TryLock added in v0.2.0

func (fs *FileStore) TryLock() (bool, error)

TryLock attempts the exclusive sidecar lock without blocking and reports whether it was acquired.

func (*FileStore) Unlock added in v0.2.0

func (fs *FileStore) Unlock() error

Unlock releases the sidecar lock. It is a no-op when not held.

type State

type State struct {
	LastCompleted string `json:"lastCompleted,omitempty"`
}

State holds the apply resume cursor: the last successfully completed pipeline step. The file is deleted when the pipeline completes, so a missing file means "start from the beginning".

func New

func New() *State

New returns a fresh state (no step completed yet).

Jump to

Keyboard shortcuts

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