Merge branch 'king-haskell' of github.com:urbit/urbit into king-boot-pb

This commit is contained in:
Benjamin Summers 2019-09-17 19:54:08 -07:00
commit 0b667d8073
2 changed files with 27 additions and 16 deletions

View File

@ -103,6 +103,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 RIO.Directory
@ -196,22 +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
createDirectoryIfMissing True pax
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,26 @@
module Vere.LockFile (lockFile) where
import UrbitPrelude
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)