lukko-0.1.1.3: File locking

Safe Haskell | Trustworthy
Language | Haskell2010

Lukko.OFD

Contents

- Types
- File descriptors
- Handles

Description

Linux open file descriptor locking.

https://www.gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html

We prefer this over BSD locking (e.g. flock) since the latter appears to break in some NFS configurations. Note that we intentionally do not try to use ordinary POSIX file locking due to its peculiar semantics under multi-threaded environments.

Synopsis

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

# Types

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 #
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

data FD Source #

Opaque file descriptor

This is a wrapper over `CInt`

fdOpen :: FilePath -> IO FD Source #

Open file to be used for locking.

    open(path, O_RDWR | O_CREAT);

fdClose :: FD -> IO () Source #

Close lock file.

    close(fd);

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

Lock using OFD locks.

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

Try to lock using OFD locks.

fdUnlock :: FD -> IO () Source #

Unlock using OFD locks.

# Handles

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

Lock using OFD locks.

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

Try to lock using OFD locks.

hUnlock :: Handle -> IO () Source #

Unlock using OFD locks.