Skip to main content

Module state

Module state 

Source
Expand description

State persistence: state.json v2 read/write/migrate.

State lives at <repo>/.git/iso-code/state.json and is rewritten via a write-temp → fsync → rename sequence for crash safety. The file lock is scoped strictly around each read-modify-write. Unknown fields are preserved through a #[serde(flatten)] catch-all to keep newer writers forward compatible with older readers.

Structs§

ActiveWorktreeEntry
An active worktree entry in state.json.
ConfigSnapshot
Snapshot of config written into state.json for diagnostics.
GcHistoryEntry
A single GC history record.
StaleWorktreeEntry
A stale (evicted) worktree entry in state.json.
StateV2
Top-level state file (v2).

Functions§

compute_repo_id
Compute the repo_id: sha256 hex of the absolute canonicalized repo path.
ensure_state_dir
Ensure the state directory exists. Called from Manager::new().
migrate
Schema migration dispatcher. Upgrades older state files to the current schema version in-place before they are returned to callers.
read_state
Read and parse state.json, migrating from v1 if needed. If the file is missing, returns a fresh empty state.
state_dir
Return the state directory: <repo>/.git/iso-code/. Respects ISO_CODE_HOME env var override and Config.home_override.
state_json_path
Return the state.json path.
state_lock_path
Return the state.lock path.
with_state
Read-modify-write helper: acquires state.lock, reads state, applies the closure, then writes back. The lock is released as soon as this function returns — callers must not perform long-running work inside the closure.
with_state_timeout
Like with_state but takes an explicit lock acquisition timeout.
write_state
Atomically write state.json: write tmp -> fsync -> rename.