Move lockfile logic into it's own file.

This commit is contained in:
Benjamin Summers 2019-09-17 19:45:51 -07:00
parent 721945d1ba
commit 26f5964ef7
2 changed files with 25 additions and 15 deletions

View File

@ -105,6 +105,7 @@ import System.Environment (getProgName)
import System.Posix.Signals (Handler(Catch), installHandler, sigTERM)
import Text.Show.Pretty (pPrint)
import Urbit.Time (Wen)
import Vere.LockFile (lockFile)
import qualified CLI
import qualified Data.Set as Set
@ -196,21 +197,6 @@ tryPlayShip shipPath = do
rio $ logTrace "SHIP RESUMED"
Pier.pier shipPath Nothing sls
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 $ Lock.unlock fil handle
params = def { Lock.retryToAcquireLock = Lock.No }
start = do
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
io (Lock.lock params fil)
tryResume :: HasLogFunc e => FilePath -> RIO e ()
tryResume shipPath = do
rwith resumedPier $ \(serf, log, ss) -> do

View File

@ -0,0 +1,24 @@
module Vere.LockFile (lockFile) where
import UrbitPrelude
import Data.Default (def)
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
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
io (lock params fil)