[Started implementing lockReadWrite, then realised that it's unnecessary. nad**20040824164844] { hunk ./NAD/LockFile.hs 3 + -- , lockReadWrite hunk ./NAD/LockFile.hs 15 --- Note that other processes are free to do whatever they want with --- the file, except that they cannot obtain a lock of their own. +-- Note that, unless mandatory locking is set on the file, other +-- processes are free to do whatever they want with it, except that +-- they cannot obtain a lock of their own. hunk ./NAD/LockFile.hs 31 + +-- | @'lockReadWrite' append file comp@ opens @file@, locks it, reads +-- its contents, runs @comp@ on the contents, writes the string +-- returned from @comp@ to the file, and finally unlocks the file. If +-- @append@ is 'True', then the output is appended to the original +-- contents of the file, and otherwise the original contents are +-- discarded. + +-- lockReadWrite :: Bool -> FilePath -> (String -> IO String) -> IO () +-- lockReadWrite append file comp = do +-- h <- openFile file ReadWriteMode +-- fd <- handleToFd h +-- lockFile fd $ do +-- s <- readEntireFile fd +-- s' <- comp s +-- when (not append) $ do +-- fdSeek fd AbsoluteSeek 0 +-- -- Erase file. +-- ... +-- fdWrite fd s' +-- -- Handle possible errors. +-- closeFd fd }