lukko-0.1.2: File locking

Safe Haskell | Trustworthy
Language | Haskell2010

Lukko

Contents

- File descriptors
- Handles

Description

Open `Handle` based locking

Synopsis

- data FileLockingNotSupported = FileLockingNotSupported
- fileLockingSupported :: Bool
- type FileLockingSupported = 'True
- data FileLockingMethod
  - = MethodOFD
  - | MethodFLock
  - | MethodWindows
  - | MethodNoOp
- fileLockingMethod :: FileLockingMethod
- data LockMode
  - = SharedLock
  - | ExclusiveLock
- type FD = FD
- fdOpen :: FilePath -> IO FD
- fdClose :: FD -> IO ()
- fdLock :: FD -> LockMode -> IO ()
- fdTryLock :: FD -> LockMode -> IO Bool
- fdUnlock :: FD -> IO ()
- handleToFd :: Handle -> IO FD
- hLock :: Handle -> LockMode -> IO ()
- hTryLock :: Handle -> LockMode -> IO Bool
- hUnlock :: Handle -> IO ()

# Documentation

data FileLockingNotSupported Source #

Exception thrown by `hLock` on non-Windows platforms that don't support `flock`.

Constructors

FileLockingNotSupported |

#### Instances

Instances details

Exception FileLockingNotSupported Source # |
Instance details Defined in Lukko.Internal.Types Methods toException :: FileLockingNotSupported -> SomeException Source # fromException :: SomeException -> Maybe FileLockingNotSupported Source # displayException :: FileLockingNotSupported -> String Source # backtraceDesired :: FileLockingNotSupported -> Bool Source #
Show FileLockingNotSupported Source # |
Instance details Defined in Lukko.Internal.Types Methods showsPrec :: Int -> FileLockingNotSupported -> ShowS Source # show :: FileLockingNotSupported -> String Source # showList :: [FileLockingNotSupported] -> ShowS Source #

fileLockingSupported :: Bool Source #

A constants specifying whether file locking is supported.

type FileLockingSupported = 'True Source #

A type level `fileLockingSupported`.

data FileLockingMethod Source #

Potentially availble lock methods.

Constructors

MethodOFD | open file descriptor locking
MethodFLock | BSD `flock`
MethodWindows | Windows locking
MethodNoOp | No-Op (throws `FileLockingNotSupported`)

#### Instances

Instances details

Bounded FileLockingMethod Source # |
Instance details Defined in Lukko.Internal.Types Methods minBound :: FileLockingMethod Source # maxBound :: FileLockingMethod Source #
Enum FileLockingMethod Source # |

Instance details

Defined in Lukko.Internal.Types

Methods

succ :: FileLockingMethod -> FileLockingMethod Source #

pred :: FileLockingMethod -> FileLockingMethod Source #

toEnum :: Int -> FileLockingMethod Source #

fromEnum :: FileLockingMethod -> Int Source #

enumFrom :: FileLockingMethod -> [FileLockingMethod] Source #

enumFromThen :: FileLockingMethod -> FileLockingMethod -> [FileLockingMethod] Source #

enumFromTo :: FileLockingMethod -> FileLockingMethod -> [FileLockingMethod] Source #

enumFromThenTo :: FileLockingMethod -> FileLockingMethod -> FileLockingMethod -> [FileLockingMethod] Source #

Show FileLockingMethod Source # |
Instance details Defined in Lukko.Internal.Types Methods showsPrec :: Int -> FileLockingMethod -> ShowS Source # show :: FileLockingMethod -> String Source # showList :: [FileLockingMethod] -> ShowS Source #
Eq FileLockingMethod Source # |
Instance details Defined in Lukko.Internal.Types Methods (==) :: FileLockingMethod -> FileLockingMethod -> Bool Source # (/=) :: FileLockingMethod -> FileLockingMethod -> Bool Source #
Ord FileLockingMethod Source # |

Instance details

Defined in Lukko.Internal.Types

Methods

compare :: FileLockingMethod -> FileLockingMethod -> Ordering Source #

(<) :: FileLockingMethod -> FileLockingMethod -> Bool Source #

(<=) :: FileLockingMethod -> FileLockingMethod -> Bool Source #

(>) :: FileLockingMethod -> FileLockingMethod -> Bool Source #

(>=) :: FileLockingMethod -> FileLockingMethod -> Bool Source #

max :: FileLockingMethod -> FileLockingMethod -> FileLockingMethod Source #

min :: FileLockingMethod -> FileLockingMethod -> FileLockingMethod Source #

fileLockingMethod :: FileLockingMethod Source #

A constant specifying this method

data LockMode Source #

Indicates a mode in which a file should be locked.

Constructors

SharedLock |
ExclusiveLock |

# File descriptors

type FD = FD Source #

Opaque file descriptor

An `int` / `CInt` on unix systems, and `HANDLE` on windows.

fdOpen :: FilePath -> IO FD Source #

Open file to be used for locking.

fdClose :: FD -> IO () Source #

Close lock file.

fdLock :: FD -> LockMode -> IO () Source #

Like `hLock`, but work on "raw" file descriptor, as handled by `fdOpen` and `fdClose`.

fdTryLock :: FD -> LockMode -> IO Bool Source #

Non-blocking version of `fdLock`.

fdUnlock :: FD -> IO () Source #

Release a lock taken with `fdLock` or `fdTryLock`.

# Handles

handleToFd :: Handle -> IO FD Source #

Convert GHC `Handle` to lukko `FD`.

hLock :: Handle -> LockMode -> IO () Source #

If a `Handle` references a file descriptor, attempt to lock contents of the underlying file in appropriate mode. If the file is already locked in incompatible mode, this function blocks until the lock is established. The lock is automatically released upon closing a `Handle`.

Things to be aware of:

1) This function may block inside a C call. If it does, in order to be able to interrupt it with asynchronous exceptions and/or for other threads to continue working, you MUST use threaded version of the runtime system.

2) The implementation uses `LockFileEx` on Windows, open file descriptor locks on Linux, and `flock` otherwise, hence all of their caveats also apply here.

3) On non-Windows plaftorms that don't support `flock` (e.g. Solaris) this function throws `FileLockingNotImplemented`. We deliberately choose to not provide `fcntl` based locking instead because of its broken semantics.

hTryLock :: Handle -> LockMode -> IO Bool Source #

Non-blocking version of `hLock`.

hUnlock :: Handle -> IO () Source #

Release a lock taken with `hLock` or `hTryLock`.