convert from Utility.LockPool to Annex.LockPool everywhere
This commit is contained in:
parent
cd22340c99
commit
aaf1ef268d
8 changed files with 59 additions and 46 deletions
|
@ -62,7 +62,7 @@ import Annex.Perms
|
||||||
import Annex.Link
|
import Annex.Link
|
||||||
import Annex.Content.Direct
|
import Annex.Content.Direct
|
||||||
import Annex.ReplaceFile
|
import Annex.ReplaceFile
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
import Messages.Progress
|
import Messages.Progress
|
||||||
import qualified Types.Remote
|
import qualified Types.Remote
|
||||||
import qualified Types.Backend
|
import qualified Types.Backend
|
||||||
|
@ -113,12 +113,12 @@ inAnnexSafe key = inAnnex' (fromMaybe True) (Just False) go key
|
||||||
=<< contentLockFile key
|
=<< contentLockFile key
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
checkindirect contentfile = liftIO $ checkOr is_missing contentfile
|
checkindirect contentfile = checkOr is_missing contentfile
|
||||||
{- In direct mode, the content file must exist, but
|
{- In direct mode, the content file must exist, but
|
||||||
- the lock file generally won't exist unless a removal is in
|
- the lock file generally won't exist unless a removal is in
|
||||||
- process. -}
|
- process. -}
|
||||||
checkdirect contentfile lockfile = liftIO $
|
checkdirect contentfile lockfile =
|
||||||
ifM (doesFileExist contentfile)
|
ifM (liftIO $ doesFileExist contentfile)
|
||||||
( checkOr is_unlocked lockfile
|
( checkOr is_unlocked lockfile
|
||||||
, return is_missing
|
, return is_missing
|
||||||
)
|
)
|
||||||
|
@ -186,7 +186,7 @@ lockContentShared key a = lockContentUsing lock key $ do
|
||||||
withVerifiedCopy LockedCopy u (return True) a
|
withVerifiedCopy LockedCopy u (return True) a
|
||||||
where
|
where
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
lock contentfile Nothing = liftIO $ tryLockShared Nothing contentfile
|
lock contentfile Nothing = tryLockShared Nothing contentfile
|
||||||
lock _ (Just lockfile) = posixLocker tryLockShared lockfile
|
lock _ (Just lockfile) = posixLocker tryLockShared lockfile
|
||||||
#else
|
#else
|
||||||
lock = winLocker lockShared
|
lock = winLocker lockShared
|
||||||
|
@ -205,7 +205,7 @@ lockContentForRemoval key a = lockContentUsing lock key $
|
||||||
lock contentfile Nothing = bracket_
|
lock contentfile Nothing = bracket_
|
||||||
(thawContent contentfile)
|
(thawContent contentfile)
|
||||||
(freezeContent contentfile)
|
(freezeContent contentfile)
|
||||||
(liftIO $ tryLockExclusive Nothing contentfile)
|
(tryLockExclusive Nothing contentfile)
|
||||||
lock _ (Just lockfile) = posixLocker tryLockExclusive lockfile
|
lock _ (Just lockfile) = posixLocker tryLockExclusive lockfile
|
||||||
#else
|
#else
|
||||||
lock = winLocker lockExclusive
|
lock = winLocker lockExclusive
|
||||||
|
@ -216,11 +216,11 @@ lockContentForRemoval key a = lockContentUsing lock key $
|
||||||
type ContentLocker = FilePath -> Maybe LockFile -> Annex (Maybe LockHandle)
|
type ContentLocker = FilePath -> Maybe LockFile -> Annex (Maybe LockHandle)
|
||||||
|
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
posixLocker :: (Maybe FileMode -> LockFile -> IO (Maybe LockHandle)) -> LockFile -> Annex (Maybe LockHandle)
|
posixLocker :: (Maybe FileMode -> LockFile -> Annex (Maybe LockHandle)) -> LockFile -> Annex (Maybe LockHandle)
|
||||||
posixLocker takelock lockfile = do
|
posixLocker takelock lockfile = do
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
modifyContent lockfile $
|
modifyContent lockfile $
|
||||||
liftIO $ takelock (Just mode) lockfile
|
takelock (Just mode) lockfile
|
||||||
|
|
||||||
#else
|
#else
|
||||||
winLocker :: (LockFile -> IO (Maybe LockHandle)) -> ContentLocker
|
winLocker :: (LockFile -> IO (Maybe LockHandle)) -> ContentLocker
|
||||||
|
|
|
@ -20,7 +20,7 @@ import Annex
|
||||||
import Types.LockCache
|
import Types.LockCache
|
||||||
import qualified Git
|
import qualified Git
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ lockFileCached file = go =<< fromLockCache file
|
||||||
go Nothing = do
|
go Nothing = do
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
lockhandle <- liftIO $ noUmask mode $ lockShared (Just mode) file
|
lockhandle <- noUmask mode $ lockShared (Just mode) file
|
||||||
#else
|
#else
|
||||||
lockhandle <- liftIO $ waitToLock $ lockShared file
|
lockhandle <- liftIO $ waitToLock $ lockShared file
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,12 +64,12 @@ withExclusiveLock getlockfile a = do
|
||||||
lockfile <- fromRepo getlockfile
|
lockfile <- fromRepo getlockfile
|
||||||
createAnnexDirectory $ takeDirectory lockfile
|
createAnnexDirectory $ takeDirectory lockfile
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
bracketIO (lock mode lockfile) dropLock (const a)
|
bracket (lock mode lockfile) (liftIO . dropLock) (const a)
|
||||||
where
|
where
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
lock mode = noUmask mode . lockExclusive (Just mode)
|
lock mode = noUmask mode . lockExclusive (Just mode)
|
||||||
#else
|
#else
|
||||||
lock _mode = waitToLock . lockExclusive
|
lock _mode = liftIO . waitToLock . lockExclusive
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{- Tries to take an exclusive lock and run an action. If the lock is
|
{- Tries to take an exclusive lock and run an action. If the lock is
|
||||||
|
@ -79,12 +79,12 @@ tryExclusiveLock getlockfile a = do
|
||||||
lockfile <- fromRepo getlockfile
|
lockfile <- fromRepo getlockfile
|
||||||
createAnnexDirectory $ takeDirectory lockfile
|
createAnnexDirectory $ takeDirectory lockfile
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
bracketIO (lock mode lockfile) unlock go
|
bracket (lock mode lockfile) (liftIO . unlock) go
|
||||||
where
|
where
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
lock mode = noUmask mode . tryLockExclusive (Just mode)
|
lock mode = noUmask mode . tryLockExclusive (Just mode)
|
||||||
#else
|
#else
|
||||||
lock _mode = lockExclusive
|
lock _mode = liftIO . lockExclusive
|
||||||
#endif
|
#endif
|
||||||
unlock = maybe noop dropLock
|
unlock = maybe noop dropLock
|
||||||
go Nothing = return Nothing
|
go Nothing = return Nothing
|
||||||
|
|
|
@ -6,7 +6,19 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Annex.LockPool.PosixOrPid where
|
module Annex.LockPool.PosixOrPid (
|
||||||
|
LockFile,
|
||||||
|
LockHandle,
|
||||||
|
lockShared,
|
||||||
|
lockExclusive,
|
||||||
|
tryLockShared,
|
||||||
|
tryLockExclusive,
|
||||||
|
dropLock,
|
||||||
|
checkLocked,
|
||||||
|
LockStatus(..),
|
||||||
|
getLockStatus,
|
||||||
|
checkSaneLock,
|
||||||
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
|
|
|
@ -37,7 +37,7 @@ import Types.CleanupActions
|
||||||
import Annex.Index (addGitEnv)
|
import Annex.Index (addGitEnv)
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{- Generates parameters to ssh to a given host (or user@host) on a given
|
{- Generates parameters to ssh to a given host (or user@host) on a given
|
||||||
|
@ -159,7 +159,7 @@ sshCleanup = mapM_ cleanup =<< enumSocketFiles
|
||||||
let lockfile = socket2lock socketfile
|
let lockfile = socket2lock socketfile
|
||||||
unlockFile lockfile
|
unlockFile lockfile
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
v <- liftIO $ noUmask mode $ tryLockExclusive (Just mode) lockfile
|
v <- noUmask mode $ tryLockExclusive (Just mode) lockfile
|
||||||
case v of
|
case v of
|
||||||
Nothing -> noop
|
Nothing -> noop
|
||||||
Just lck -> do
|
Just lck -> do
|
||||||
|
|
|
@ -23,7 +23,7 @@ import Logs.Transfer as X
|
||||||
import Annex.Notification as X
|
import Annex.Notification as X
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
import Utility.Metered
|
import Utility.Metered
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
import Types.Remote (Verification(..))
|
import Types.Remote (Verification(..))
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
|
@ -79,7 +79,7 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do
|
||||||
info <- liftIO $ startTransferInfo file
|
info <- liftIO $ startTransferInfo file
|
||||||
(meter, tfile, metervar) <- mkProgressUpdater t info
|
(meter, tfile, metervar) <- mkProgressUpdater t info
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
(lck, inprogress) <- liftIO $ prep tfile mode info
|
(lck, inprogress) <- prep tfile mode info
|
||||||
if inprogress && not ignorelock
|
if inprogress && not ignorelock
|
||||||
then do
|
then do
|
||||||
showNote "transfer already in progress, or unable to take transfer lock"
|
showNote "transfer already in progress, or unable to take transfer lock"
|
||||||
|
@ -96,21 +96,23 @@ runTransfer' ignorelock t file shouldretry transferobserver transferaction = do
|
||||||
r <- tryLockExclusive (Just mode) lck
|
r <- tryLockExclusive (Just mode) lck
|
||||||
case r of
|
case r of
|
||||||
Nothing -> return (Nothing, True)
|
Nothing -> return (Nothing, True)
|
||||||
Just lockhandle -> ifM (checkSaneLock lck lockhandle)
|
Just lockhandle -> ifM (liftIO $ checkSaneLock lck lockhandle)
|
||||||
( do
|
( do
|
||||||
void $ tryIO $ writeTransferInfoFile info tfile
|
void $ liftIO $ tryIO $
|
||||||
|
writeTransferInfoFile info tfile
|
||||||
return (Just lockhandle, False)
|
return (Just lockhandle, False)
|
||||||
, return (Nothing, True)
|
, return (Nothing, True)
|
||||||
)
|
)
|
||||||
#else
|
#else
|
||||||
prep tfile _mode info = do
|
prep tfile _mode info = liftIO $ do
|
||||||
let lck = transferLockFile tfile
|
let lck = transferLockFile tfile
|
||||||
v <- catchMaybeIO $ lockExclusive lck
|
v <- catchMaybeIO $ lockExclusive lck
|
||||||
case v of
|
case v of
|
||||||
Nothing -> return (Nothing, False)
|
Nothing -> return (Nothing, False)
|
||||||
Just Nothing -> return (Nothing, True)
|
Just Nothing -> return (Nothing, True)
|
||||||
Just (Just lockhandle) -> do
|
Just (Just lockhandle) -> do
|
||||||
void $ tryIO $ writeTransferInfoFile info tfile
|
void $ liftIO $ tryIO $
|
||||||
|
writeTransferInfoFile info tfile
|
||||||
return (Just lockhandle, False)
|
return (Just lockhandle, False)
|
||||||
#endif
|
#endif
|
||||||
cleanup _ Nothing = noop
|
cleanup _ Nothing = noop
|
||||||
|
|
|
@ -17,7 +17,7 @@ import Utility.Metered
|
||||||
import Utility.Percentage
|
import Utility.Percentage
|
||||||
import Utility.QuickCheck
|
import Utility.QuickCheck
|
||||||
import Utility.PID
|
import Utility.PID
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
import Logs.TimeStamp
|
import Logs.TimeStamp
|
||||||
|
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
|
@ -136,25 +136,24 @@ checkTransfer t = do
|
||||||
void $ tryIO $ removeFile tfile
|
void $ tryIO $ removeFile tfile
|
||||||
void $ tryIO $ removeFile $ transferLockFile tfile
|
void $ tryIO $ removeFile $ transferLockFile tfile
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
liftIO $ do
|
let lck = transferLockFile tfile
|
||||||
let lck = transferLockFile tfile
|
v <- getLockStatus lck
|
||||||
v <- getLockStatus lck
|
case v of
|
||||||
case v of
|
StatusLockedBy pid -> liftIO $ catchDefaultIO Nothing $
|
||||||
StatusLockedBy pid -> catchDefaultIO Nothing $
|
readTransferInfoFile (Just pid) tfile
|
||||||
readTransferInfoFile (Just pid) tfile
|
StatusNoLockFile -> return Nothing
|
||||||
StatusNoLockFile -> return Nothing
|
StatusUnLocked -> do
|
||||||
StatusUnLocked -> do
|
-- Take a non-blocking lock while deleting
|
||||||
-- Take a non-blocking lock while deleting
|
-- the stale lock file. Ignore failure
|
||||||
-- the stale lock file. Ignore failure
|
-- due to permissions problems, races, etc.
|
||||||
-- due to permissions problems, races, etc.
|
void $ tryIO $ do
|
||||||
void $ tryIO $ do
|
r <- tryLockExclusive Nothing lck
|
||||||
r <- tryLockExclusive Nothing lck
|
case r of
|
||||||
case r of
|
Just lockhandle -> liftIO $ do
|
||||||
Just lockhandle -> do
|
cleanstale
|
||||||
cleanstale
|
dropLock lockhandle
|
||||||
dropLock lockhandle
|
_ -> noop
|
||||||
_ -> noop
|
return Nothing
|
||||||
return Nothing
|
|
||||||
#else
|
#else
|
||||||
v <- liftIO $ lockShared $ transferLockFile tfile
|
v <- liftIO $ lockShared $ transferLockFile tfile
|
||||||
liftIO $ case v of
|
liftIO $ case v of
|
||||||
|
|
|
@ -16,7 +16,7 @@ import Types.Remote
|
||||||
import Types.CleanupActions
|
import Types.CleanupActions
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Annex.LockFile
|
import Annex.LockFile
|
||||||
import Utility.LockPool
|
import Annex.LockPool
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,7 +83,7 @@ runHooks r starthook stophook a = do
|
||||||
unlockFile lck
|
unlockFile lck
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
mode <- annexFileMode
|
mode <- annexFileMode
|
||||||
v <- liftIO $ noUmask mode $ tryLockExclusive (Just mode) lck
|
v <- noUmask mode $ tryLockExclusive (Just mode) lck
|
||||||
#else
|
#else
|
||||||
v <- liftIO $ lockExclusive lck
|
v <- liftIO $ lockExclusive lck
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,6 @@ module Types.LockCache (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Utility.LockPool
|
import Utility.LockPool (LockHandle)
|
||||||
|
|
||||||
type LockCache = M.Map FilePath LockHandle
|
type LockCache = M.Map FilePath LockHandle
|
||||||
|
|
Loading…
Add table
Reference in a new issue