Revision 69bf84e1
b/src/Ganeti/Utils.hs | ||
---|---|---|
79 | 79 |
import Control.Concurrent |
80 | 80 |
import Control.Exception (try) |
81 | 81 |
import Control.Monad (foldM, liftM, when, unless) |
82 |
import Control.Monad.IO.Class (liftIO) |
|
82 | 83 |
import Data.Char (toUpper, isAlphaNum, isDigit, isSpace) |
83 | 84 |
import qualified Data.Either as E |
84 | 85 |
import Data.Function (on) |
... | ... | |
553 | 554 |
-- | Attempt, in a non-blocking way, to obtain a lock on a given file; report |
554 | 555 |
-- back success. |
555 | 556 |
lockFile :: FilePath -> IO (Result ()) |
556 |
lockFile path = do |
|
557 |
lockFile path = runResultT . liftIO $ do
|
|
557 | 558 |
handle <- openFile path WriteMode |
558 | 559 |
fd <- handleToFd handle |
559 |
Control.Monad.liftM (either (Bad . show) Ok) |
|
560 |
(try (setLock fd (WriteLock, AbsoluteSeek, 0, 0)) :: IO (Either IOError ())) |
|
560 |
setLock fd (WriteLock, AbsoluteSeek, 0, 0) |
|
561 | 561 |
|
562 | 562 |
-- | File stat identifier. |
563 | 563 |
type FStat = (EpochTime, FileID, FileOffset) |
Also available in: Unified diff