ganeti

Safe HaskellNone

Ganeti.Utils.Atomic

Description

Utility functions for atomic file access.

Synopsis

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.

atomicUpdateFile :: MonadBaseControl IO m => FilePath -> (FilePath -> Handle -> m a) -> m a Source #

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, Error e, MonadBaseControl IO m) => FilePath -> (Fd -> m a) -> m a Source #

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

Just as atomicUpdateLockedFile, but discards the action result.