diff options
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/Journal.hs | 13 | ||||
-rw-r--r-- | Annex/LockPool.hs | 32 |
2 files changed, 24 insertions, 21 deletions
diff --git a/Annex/Journal.hs b/Annex/Journal.hs index 8b88ab2fb..3f31cb941 100644 --- a/Annex/Journal.hs +++ b/Annex/Journal.hs @@ -20,6 +20,10 @@ import Annex.Exception import qualified Git import Annex.Perms +#ifdef mingw32_HOST_OS +import Utility.WinLock +#endif + {- Records content for a file in the branch to the journal. - - Using the journal, rather than immediatly staging content to the index @@ -116,13 +120,8 @@ lockJournal a = do l <- noUmask mode $ createFile lockfile mode waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0) return l -#else - lock lockfile _mode = do - writeFile lockfile "" - return lockfile -#endif -#ifndef mingw32_HOST_OS unlock = closeFd #else - unlock = removeFile + lock lockfile _mode = waitToLock $ lockExclusive lockfile + unlock = dropLock #endif diff --git a/Annex/LockPool.hs b/Annex/LockPool.hs index a9a0f3101..5fc167d28 100644 --- a/Annex/LockPool.hs +++ b/Annex/LockPool.hs @@ -1,6 +1,6 @@ {- git-annex lock pool - - - Copyright 2012 Joey Hess <joey@kitenet.net> + - Copyright 2012, 2014 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -9,13 +9,16 @@ module Annex.LockPool where -import qualified Data.Map as M -import System.Posix.Types (Fd) - import Common.Annex import Annex +import Types.LockPool + +import qualified Data.Map as M + #ifndef mingw32_HOST_OS import Annex.Perms +#else +import Utility.WinLock #endif {- Create a specified lock file, and takes a shared lock. -} @@ -26,31 +29,32 @@ lockFile file = go =<< fromPool file go Nothing = do #ifndef mingw32_HOST_OS mode <- annexFileMode - fd <- liftIO $ noUmask mode $ + lockhandle <- liftIO $ noUmask mode $ openFd file ReadOnly (Just mode) defaultFileFlags - liftIO $ waitToSetLock fd (ReadLock, AbsoluteSeek, 0, 0) + liftIO $ waitToSetLock lockhandle (ReadLock, AbsoluteSeek, 0, 0) #else - liftIO $ writeFile file "" - let fd = 0 + lockhandle <- liftIO $ waitToLock $ lockShared file #endif - changePool $ M.insert file fd + changePool $ M.insert file lockhandle unlockFile :: FilePath -> Annex () unlockFile file = maybe noop go =<< fromPool file where - go fd = do + go lockhandle = do #ifndef mingw32_HOST_OS - liftIO $ closeFd fd + liftIO $ closeFd lockhandle +#else + liftIO $ dropLock lockhandle #endif changePool $ M.delete file -getPool :: Annex (M.Map FilePath Fd) +getPool :: Annex LockPool getPool = getState lockpool -fromPool :: FilePath -> Annex (Maybe Fd) +fromPool :: FilePath -> Annex (Maybe LockHandle) fromPool file = M.lookup file <$> getPool -changePool :: (M.Map FilePath Fd -> M.Map FilePath Fd) -> Annex () +changePool :: (LockPool -> LockPool) -> Annex () changePool a = do m <- getPool changeState $ \s -> s { lockpool = a m } |