Expand description
Exclusive file lock held during install / uninstall.
Two terminals running plugin add at once would corrupt .plugins.json, or let
two cargo build runs write into the same wrapper directory. A cross-process
lock keeps them out of each other’s way.
§Implementation
The lock file is created with create_new(true) — atomic on mainstream file
systems, so whoever creates it first holds the lock. The pid and a timestamp are
written into it to make diagnosis easier.
No OS-level file lock (flock / LockFileEx): that would need extra
per-platform code, and this crate already has a simpler criterion — does the lock
file exist, and is it stale? The price is that a kill -9 leaves a stale lock
file behind, hence the stale takeover.
Structs§
- File
Lock - Holds an exclusive lock. Released on
Drop.
Constants§
- STALE_
AFTER - How old a lock file has to be before it counts as stale. A lock older than this is taken over by a later arrival.