aboutsummaryrefslogtreecommitdiff
path: root/Annex/LockPool.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-28 14:17:14 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-28 14:42:03 -0400
commite48f551505b3923d7c17e3b42330060e84129673 (patch)
tree5de335f5cc25b39a5d4ca12fdb6a076e03cf34db /Annex/LockPool.hs
parent4a923c3ee0e238ccc17881179bec77c6531e3ad4 (diff)
use locking on Windows
This is all the easy cases, where there was already a separate lock file.
Diffstat (limited to 'Annex/LockPool.hs')
-rw-r--r--Annex/LockPool.hs32
1 files changed, 18 insertions, 14 deletions
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 }