diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-05-19 23:35:24 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-05-19 23:35:24 -0400 |
commit | 3237ddb564f5d2c07d03184d4f43c9c33c612a6c (patch) | |
tree | 7fef6e09b3cbcb6ea48d04b56cac070dd46df3c6 /Utility/LockFile | |
parent | 8907359a875c2deb76d9386e398d97e4e4103fe2 (diff) |
fix crash in stale transfer lockfile cleanup code
Need to differentiate between the lockfile not being locked, and it not
existing.
Diffstat (limited to 'Utility/LockFile')
-rw-r--r-- | Utility/LockFile/Posix.hs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Utility/LockFile/Posix.hs b/Utility/LockFile/Posix.hs index 65ba328df..18d9e4fc1 100644 --- a/Utility/LockFile/Posix.hs +++ b/Utility/LockFile/Posix.hs @@ -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 |