fix crash in stale transfer lockfile cleanup code

Need to differentiate between the lockfile not being locked, and it not
existing.
This commit is contained in:
Joey Hess 2015-05-19 23:35:24 -04:00
parent 26bb2c40f8
commit 9de5cd2966
4 changed files with 23 additions and 9 deletions

View file

@ -12,6 +12,7 @@ module Utility.LockFile.Posix (
tryLockExclusive,
checkLocked,
getLockStatus,
LockStatus(..),
dropLock,
checkSaneLock,
) where
@ -66,8 +67,16 @@ openLockFile filemode lockfile = do
checkLocked :: LockFile -> IO (Maybe Bool)
checkLocked = maybe Nothing (Just . isJust) <$$> getLockStatus'
getLockStatus :: LockFile -> IO (Maybe ProcessID)
getLockStatus = fromMaybe Nothing <$$> getLockStatus'
data LockStatus = StatusUnLocked | StatusLockedBy ProcessID | StatusNoLockFile
deriving (Eq)
getLockStatus :: LockFile -> IO LockStatus
getLockStatus lockfile = do
v <- getLockStatus' lockfile
return $ case v of
Nothing -> StatusNoLockFile
Just Nothing -> StatusUnLocked
Just (Just pid) -> StatusLockedBy pid
getLockStatus' :: LockFile -> IO (Maybe (Maybe ProcessID))
getLockStatus' lockfile = go =<< catchMaybeIO open