56 lines
2.1 KiB
Markdown
56 lines
2.1 KiB
Markdown
Dot locking for files
|
|
|
|
This is an implementation of dot-locking from [scsh](https://scsh.net/).
|
|
|
|
## Documentation
|
|
|
|
From [https://scsh.net/docu/html/man-Z-H-11.html#node_sec_10.3](https://scsh.net/docu/html/man-Z-H-11.html#node_sec_10.3)
|
|
|
|
Copied here for convenience.
|
|
|
|
|
|
(__obtain-dot-lock__ file-name)
|
|
|
|
Tries to obtain the lock for file-name. If the file is already locked, the thread
|
|
sleeps for interval seconds (default is 1) before it retries. If the lock cannot
|
|
be obtained after retry-number attempts, the procedure returns #f, other-
|
|
wise #t. The default value of retry-number is #f which corresponds to an
|
|
infinite number of retires.
|
|
If stale-time is non-#f, it specifies the minimum age a lock may have
|
|
(in seconds) before it is considered stale. Obtain-dot-lock attempts to
|
|
delete stale locks. If it was succcessful obtaining a lock after breaking
|
|
it, obtain-dot-lock returns broken. If stale-time is #f, obtain-dot-lock
|
|
never considers a lock stale. The default for stale-time is 300.
|
|
Note that it is possible that obtain-dot-lock breaks a lock but never-
|
|
theless fails to obtain it otherwise. If it is necessary to handle this case
|
|
specially, use break-dot-lock directly (see below) rather than specifying
|
|
a non-#f stale-time
|
|
|
|
|
|
(__break-dot-lock__ file-name)
|
|
|
|
Breaks the lock for file-name if one exists. Note that breaking a lock
|
|
does not imply a subsequent obtain-dot-lock will succeed, as an-
|
|
other party may have acquired the lock between break-dot-lock and
|
|
obtain-dot-lock.
|
|
|
|
|
|
(__release-dot-lock__ file-name)
|
|
|
|
Releases the lock for file-name. On success, release-dot-lock returns #t,
|
|
otherwise #f. Note that this procedure can also be used to break the lock
|
|
for file-name.
|
|
|
|
|
|
(__with-dot-lock*__ file-name thunk)
|
|
(__with-dot-lock__ file-name body ...)
|
|
|
|
The procedure with-dot-lock* obtains the requested lock, and then calls
|
|
(thunk). When thunk returns, the lock is released. A non-local exit (e.g.,
|
|
throwing to a saved continuation or raising an exception) also causes the
|
|
lock to be released.
|
|
After a normal return from thunk, its return values are returned by
|
|
with-dot-lock*. The with-dot-lock special form is equivalent syntac-
|
|
tic sugar.
|
|
|