mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
31 lines
896 B
Haskell
31 lines
896 B
Haskell
{-|
|
|
Acquire and release the vere lockfile.
|
|
-}
|
|
|
|
module Urbit.Vere.LockFile (lockFile) where
|
|
|
|
import Urbit.Prelude
|
|
|
|
import Data.Default (def)
|
|
import RIO.Directory (createDirectoryIfMissing)
|
|
import System.IO.LockFile.Internal (LockingParameters(..), RetryStrategy(..),
|
|
lock, unlock)
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
lockFile :: HasLogFunc e => FilePath -> RAcquire e ()
|
|
lockFile pax = void $ mkRAcquire start stop
|
|
where
|
|
fil = pax <> "/.vere.lock"
|
|
|
|
stop handle = do
|
|
logInfo $ display @Text $ ("Releasing lock file: " <> pack fil)
|
|
io $ unlock fil handle
|
|
|
|
params = def { retryToAcquireLock = No }
|
|
|
|
start = do
|
|
createDirectoryIfMissing True pax
|
|
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
|
|
io (lock params fil)
|