diff options
author | Joey Hess <joey@kitenet.net> | 2014-08-20 16:45:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-08-20 16:45:58 -0400 |
commit | 679d9c0027ac996eea9f41a6f0f39af436801e89 (patch) | |
tree | d98ae7ba049e2daa4a99e6bcf55054bde5e5ab4d /Command | |
parent | 86f9d7734d0c638d4c966fd87a5d7e97759e125b (diff) |
reorganize and refactor lock code
Added a convenience Utility.LockFile that is not a windows/posix
portability shim, but still manages to cut down on the boilerplate around
locking.
This commit was sponsored by Johan Herland.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/PreCommit.hs | 24 |
1 files changed, 2 insertions, 22 deletions
diff --git a/Command/PreCommit.hs b/Command/PreCommit.hs index 61508ba9b..355e2766e 100644 --- a/Command/PreCommit.hs +++ b/Command/PreCommit.hs @@ -18,16 +18,12 @@ import Annex.Direct import Annex.Hook import Annex.View import Annex.View.ViewedFile -import Annex.Perms +import Annex.LockFile import Logs.View import Logs.MetaData import Types.View import Types.MetaData -#ifdef mingw32_HOST_OS -import Utility.WinLock -#endif - import qualified Data.Set as S def :: [Command] @@ -92,20 +88,4 @@ showMetaDataChange = showLongNote . unlines . concatMap showmeta . fromMetaData {- Takes exclusive lock; blocks until available. -} lockPreCommitHook :: Annex a -> Annex a -lockPreCommitHook a = do - lockfile <- fromRepo gitAnnexPreCommitLock - createAnnexDirectory $ takeDirectory lockfile - mode <- annexFileMode - bracketIO (lock lockfile mode) unlock (const a) - where -#ifndef mingw32_HOST_OS - lock lockfile mode = do - l <- liftIO $ noUmask mode $ createFile lockfile mode - setFdOption l CloseOnExec True - liftIO $ waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0) - return l - unlock = closeFd -#else - lock lockfile _mode = liftIO $ waitToLock $ lockExclusive lockfile - unlock = dropLock -#endif +lockPreCommitHook = withExclusiveLock gitAnnexPreCommitLock |