state

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package state persists resume-only state for dotdrift apply.

Index

Constants

View Source
const (
	StatusFresh      = "fresh"
	StatusInProgress = "in-progress"
	StatusComplete   = "complete"
	StatusFailed     = "failed"
)

Status values for the apply pipeline.

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) 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 {
	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 New

func New() *State

New returns a fresh state with initialized maps.

func (*State) IsCompleted

func (s *State) IsCompleted(step string) bool

IsCompleted reports whether a step has been completed.

func (*State) MarkComplete

func (s *State) MarkComplete(step string)

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

func (s *State) MarkFailed(step string, err error)

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.

type Store

type Store interface {
	Load() (*State, error)
	Save(s *State) error
}

Store persists state.

Jump to

Keyboard shortcuts

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