Safe Haskell | Safe-Infered |
---|
Ganeti.Utils.Atomic
Description
Utility functions for atomic file access.
- atomicWriteFile :: FilePath -> String -> IO ()
- fsyncFileChecked :: FilePath -> IO ()
- atomicUpdateFile :: MonadBaseControl IO m => FilePath -> (FilePath -> Handle -> m a) -> m a
- withLockedFile :: (MonadError e m, FromString e, MonadBaseControl IO m) => FilePath -> (Fd -> m a) -> m a
- atomicUpdateLockedFile :: FilePath -> FStat -> (FilePath -> Handle -> IO a) -> ResultG (FStat, a)
- atomicUpdateLockedFile_ :: FilePath -> FStat -> (FilePath -> Handle -> IO a) -> ResultG FStat
Documentation
atomicWriteFile :: FilePath -> String -> IO ()Source
Atomically write a file, by first writing the contents into a temporary file and then renaming it to the old position.
fsyncFileChecked :: FilePath -> IO ()Source
atomicUpdateFile :: MonadBaseControl IO m => FilePath -> (FilePath -> Handle -> m a) -> m aSource
Atomically update a file, by first creating a temporary file, running the given action on it, and then renaming it to the old position. Usually the action will write to the file and update its permissions. The action is allowed to close the file descriptor, but isn't required to do so.
withLockedFile :: (MonadError e m, FromString e, MonadBaseControl IO m) => FilePath -> (Fd -> m a) -> m aSource
Opens a file in a R/W mode, locks it (blocking if needed) and runs a given action while the file is locked. Releases the lock and closes the file afterwards.
atomicUpdateLockedFile :: FilePath -> FStat -> (FilePath -> Handle -> IO a) -> ResultG (FStat, a)Source
Just as atomicUpdateFile
, but in addition locks the file during the
operation using withLockedFile
and checks if the file has been modified.
The action is only run if it hasn't, otherwise an error is thrown.
The file must exist.
Returns the new file status after the operation is finished.
atomicUpdateLockedFile_ :: FilePath -> FStat -> (FilePath -> Handle -> IO a) -> ResultG FStatSource
Just as atomicUpdateLockedFile
, but discards the action result.