summaryrefslogtreecommitdiff
path: root/Utility/LockFile
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-05-18 14:16:49 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-05-18 15:57:17 -0400
commit94a3e606fb31150c969d63790ec1ef870f413cc1 (patch)
tree566860a856e7d064e18de4c3a8a2e561377caf3c /Utility/LockFile
parent6a318cf0c050f9fa7959874bf0eb8f1105ef0a4b (diff)
lock pools to work around non-concurrency/composition safety of POSIX fcntl
Diffstat (limited to 'Utility/LockFile')
-rw-r--r--Utility/LockFile/Posix.hs14
-rw-r--r--Utility/LockFile/Windows.hs2
2 files changed, 5 insertions, 11 deletions
diff --git a/Utility/LockFile/Posix.hs b/Utility/LockFile/Posix.hs
index 9013bd32c..12275c48a 100644
--- a/Utility/LockFile/Posix.hs
+++ b/Utility/LockFile/Posix.hs
@@ -12,7 +12,6 @@ module Utility.LockFile.Posix (
tryLockExclusive,
createLockFile,
openExistingLockFile,
- isLocked,
checkLocked,
getLockStatus,
dropLock,
@@ -73,28 +72,23 @@ openLockFile filemode lockfile = do
setFdOption l CloseOnExec True
return l
--- Check if a file is locked, either exclusively, or with shared lock.
--- When the file doesn't exist, it's considered not locked.
-isLocked :: LockFile -> IO Bool
-isLocked = fromMaybe False <$$> checkLocked
-
-- Returns Nothing when the file doesn't exist, for cases where
-- that is different from it not being locked.
checkLocked :: LockFile -> IO (Maybe Bool)
checkLocked = maybe Nothing (Just . isJust) <$$> getLockStatus'
-getLockStatus :: LockFile -> IO (Maybe (ProcessID, FileLock))
+getLockStatus :: LockFile -> IO (Maybe ProcessID)
getLockStatus = fromMaybe Nothing <$$> getLockStatus'
-getLockStatus' :: LockFile -> IO (Maybe (Maybe (ProcessID, FileLock)))
+getLockStatus' :: LockFile -> IO (Maybe (Maybe ProcessID))
getLockStatus' lockfile = go =<< catchMaybeIO open
where
open = openFd lockfile ReadOnly Nothing defaultFileFlags
go Nothing = return Nothing
go (Just h) = do
- ret <- getLock h (ReadLock, AbsoluteSeek, 0, 0)
+ v <- getLock h (ReadLock, AbsoluteSeek, 0, 0)
closeFd h
- return (Just ret)
+ return (Just (fmap fst v))
dropLock :: LockHandle -> IO ()
dropLock (LockHandle fd) = closeFd fd
diff --git a/Utility/LockFile/Windows.hs b/Utility/LockFile/Windows.hs
index 3c680d91c..fe57ff9eb 100644
--- a/Utility/LockFile/Windows.hs
+++ b/Utility/LockFile/Windows.hs
@@ -22,7 +22,7 @@ type LockFile = FilePath
type LockHandle = HANDLE
{- Tries to lock a file with a shared lock, which allows other processes to
- - also lock it shared. Fails is the file is exclusively locked. -}
+ - also lock it shared. Fails if the file is exclusively locked. -}
lockShared :: LockFile -> IO (Maybe LockHandle)
lockShared = openLock fILE_SHARE_READ