module Ouroboros.Consensus.Util.FileLock (
FileLock (..)
, ioFileLock
) where
import qualified System.FileLock as IO
data FileLock m = FileLock {
FileLock m -> FilePath -> m (m ())
lockFile :: FilePath -> m (m ())
}
ioFileLock :: FileLock IO
ioFileLock :: FileLock IO
ioFileLock = FileLock :: forall (m :: * -> *). (FilePath -> m (m ())) -> FileLock m
FileLock {
lockFile :: FilePath -> IO (IO ())
lockFile = \FilePath
fp ->
FileLock -> IO ()
IO.unlockFile (FileLock -> IO ()) -> IO FileLock -> IO (IO ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> SharedExclusive -> IO FileLock
IO.lockFile FilePath
fp SharedExclusive
IO.Exclusive
}