Documentation
¶
Overview ¶
Package state loads and saves lore's per-machine local state file.
Index ¶
- Constants
- func Path() (string, error)
- func Save(s State) error
- func SyncErrorPath() (string, error)
- type CheckoutEntry
- type ProjectEntry
- type State
- func (s *State) AddAgentDir(name, dirName string) error
- func (s *State) CheckoutForPath(name, projectPath string) (CheckoutEntry, bool)
- func (s *State) CheckoutOwner(projectPath string) (string, bool)
- func (s *State) Clone() State
- func (s *State) PathFor(name string) (string, bool)
- func (s *State) ProjectEntryFor(name string) (ProjectEntry, bool)
- func (s *State) RecordCheckout(name, projectPath, syncBase string) error
- func (s *State) RemoveAgentDir(name, dirName string)
- func (s *State) RemoveCheckout(name, projectPath string)
- func (s *State) RemoveProject(name string)
- func (s *State) RenameProject(oldName, newName string) error
Constants ¶
const CurrentSchemaVersion = 3
CurrentSchemaVersion is the schema_version value written by this build.
Variables ¶
This section is empty.
Functions ¶
func Path ¶
Path returns the on-disk location of the state file. Honors XDG_STATE_HOME; falls back to ~/.local/state/lore/state.toml.
func Save ¶
Save writes the state file atomically, creating its parent directory if needed. Writes to a sibling tempfile then renames into place so a crash or encode failure can never leave a truncated state.toml on disk. lore add's rollback path leans on this: if Save errors out the previous state file is still intact.
func SyncErrorPath ¶
SyncErrorPath returns the deferred automatic-sync error record path.
Types ¶
type CheckoutEntry ¶
CheckoutEntry records one project copy on this machine.
type ProjectEntry ¶
type ProjectEntry struct {
AgentDirs []string `toml:"agent_dirs"`
Checkouts []CheckoutEntry `toml:"checkouts"`
}
ProjectEntry records shared project identity and per-checkout state.
type State ¶
type State struct {
SchemaVersion int `toml:"schema_version"`
Projects map[string]ProjectEntry `toml:"projects"`
}
State is the typed representation of state.toml.
func Defaults ¶
func Defaults() State
Defaults returns an empty State at the current schema version.
func Load ¶
Load reads the state file. If absent, returns Defaults() with exists=false (nil err). Files at schema versions other than the current one are rejected with CodeInconsistency; the user is expected to remove the stale file and rebuild current state with pull.
func (*State) AddAgentDir ¶
AddAgentDir records an agent directory in the project identity.
func (*State) CheckoutForPath ¶
func (s *State) CheckoutForPath(name, projectPath string) (CheckoutEntry, bool)
CheckoutForPath returns the checkout recorded at projectPath.
func (*State) CheckoutOwner ¶
CheckoutOwner returns the project that owns an exact checkout path.
func (*State) Clone ¶
Clone returns a copy of s safe to mutate independently. Projects is a map (reference type), so a plain struct copy would alias it; orchestrators that snapshot pre-mutation state for a rollback (lore rm / mv) need this.
func (*State) ProjectEntryFor ¶
func (s *State) ProjectEntryFor(name string) (ProjectEntry, bool)
ProjectEntryFor returns the entry recorded for name. Second return is false when the project isn't tracked.
func (*State) RecordCheckout ¶
RecordCheckout records or updates one checkout and its sync-base.
func (*State) RemoveAgentDir ¶
RemoveAgentDir drops dirName from name's tracked set. If the removal empties the project's agent dir list, the project entry itself is removed (a project with zero tracked dirs is not a tracked project). No-op when the project or the dir isn't tracked.
Does NOT persist; see AddAgentDir for the rationale.
func (*State) RemoveCheckout ¶
RemoveCheckout drops one checkout from a project.
func (*State) RemoveProject ¶
RemoveProject drops every checkout record for a project.
func (*State) RenameProject ¶
RenameProject moves a project entry without changing its checkout data.