Skip to main content

Module lock

Module lock 

Source
Expand description

Cross-process safety for shared files: a lock compatible with proper-lockfile, which pi uses for auth.json, settings.json and trust.json, and an atomic replacement of a file’s contents. The lock is a <file>.lock directory, and one whose modification time is older than the stale period may be taken over. A lock taken with FileLock::acquire keeps its modification time fresh while held, as proper-lockfile does.

Structs§

FileLock
A held lock. Dropping it releases the lock.

Enums§

LockError
Why the lock could not be taken.

Functions§

write_atomic
Replaces path’s contents so that readers see the old or the new bytes, never a partial file: writes a temporary file beside it, flushes it to disk and renames it over path. An existing file keeps its permissions, and a new one gets create_mode (Unix, less the umask). A symbolic link keeps pointing at its target, which receives the contents. On error the file is unchanged.