pub struct ConfigLock { /* private fields */ }Expand description
An exclusive advisory lock over one config file, held for as long as
the value lives and released when it drops (including on an early ?,
and by the kernel if the process dies holding it).
Keyed on the path it is given rather than on shep.toml specifically:
shep-cli’s ShepToml::edit takes one over shep.toml, and
commands::dog_migration takes one over dogs.toml, which has two
writers of its own. Whenever both are held at once, shep.toml’s is
taken first, which is the whole of what keeps the two orderings from
deadlocking; migrate_dog_sections is the one caller that holds both,
and it says so at the point it nests them.
The lock is on a sibling <name>.lock, never on the config itself,
and that is the whole design decision, the same one barks::RingLock
records: ShepToml::save finishes by renameing a new file over the
config, which replaces the inode. A lock taken on the config would be a
lock on an inode the very next successful save unlinks; the next writer
would open the new inode, find it unlocked, and the two would be
excluding nothing. The lock file is never renamed, never rewritten and
never read; it exists only to be an inode with a stable identity, and
it is left on disk between edits on purpose so both writers keep
agreeing on which one it is.
Derives Debug rather than opting out: the fields are a held OS lock
handle (a flock(2) wrapper on unix, a bare File on Windows), never a
secret, so there is nothing here for a redacted impl to protect.