more lock file refactoring
This commit is contained in:
parent
d279180266
commit
ec7dd0446a
3 changed files with 20 additions and 16 deletions
|
@ -6,13 +6,16 @@
|
|||
-}
|
||||
|
||||
module Utility.LockFile.Posix (
|
||||
LockHandle,
|
||||
lockShared,
|
||||
lockExclusive,
|
||||
dropLock,
|
||||
createLockFile,
|
||||
LockHandle
|
||||
openExistingLockFile,
|
||||
) where
|
||||
|
||||
import Utility.Exception
|
||||
|
||||
import System.IO
|
||||
import System.Posix
|
||||
|
||||
|
@ -35,11 +38,18 @@ lock lockreq mode lockfile = do
|
|||
waitToSetLock l (lockreq, AbsoluteSeek, 0, 0)
|
||||
return (LockHandle l)
|
||||
|
||||
-- Create and opens lock file, does not lock it.
|
||||
-- Close on exec flag is set so child processes do not inherit the lock.
|
||||
-- Create and opens lock file; does not lock it.
|
||||
createLockFile :: Maybe FileMode -> LockFile -> IO Fd
|
||||
createLockFile mode lockfile = do
|
||||
l <- openFd lockfile ReadWrite mode defaultFileFlags
|
||||
createLockFile = openLockFile ReadWrite
|
||||
|
||||
-- Opens an existing lock file; does not lock it or create it.
|
||||
openExistingLockFile :: LockFile -> IO (Maybe Fd)
|
||||
openExistingLockFile = catchMaybeIO . openLockFile ReadOnly Nothing
|
||||
|
||||
-- Close on exec flag is set so child processes do not inherit the lock.
|
||||
openLockFile :: OpenMode -> Maybe FileMode -> LockFile -> IO Fd
|
||||
openLockFile openmode filemode lockfile = do
|
||||
l <- openFd lockfile openmode filemode defaultFileFlags
|
||||
setFdOption l CloseOnExec True
|
||||
return l
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue