Documentation
¶
Overview ¶
Package state persists resume-only state for dotdrift apply.
Index ¶
Constants ¶
const ( StatusFresh = "fresh" StatusInProgress = "in-progress" StatusComplete = "complete" StatusFailed = "failed" )
Status values for the apply pipeline.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
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
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 ¶
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) Lock ¶ added in v0.2.0
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
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.
type State ¶
type State struct {
Selection string `json:"selection"`
Completed map[string]bool `json:"completed"`
Current string `json:"current"`
Status string `json:"status"`
Error string `json:"error"`
}
State holds the resume cursor and last error.
func (*State) IsCompleted ¶
IsCompleted reports whether a step has been completed.
func (*State) MarkComplete ¶
MarkComplete records a step as completed and clears the current step/error.
func (*State) MarkCompletePipeline ¶
func (s *State) MarkCompletePipeline()
MarkCompletePipeline marks the pipeline as fully complete.
func (*State) MarkFailed ¶
MarkFailed records a step as the current failed step and stores the error.
func (*State) ResetForSelection ¶
func (s *State) ResetForSelection()
ResetForSelection clears runtime progress when the selection fingerprint changes.