{- git-annex actions
-
- - Copyright 2010-2015 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
startup,
shutdown,
stopCoProcesses,
+ stopNonConcurrentSafeCoProcesses,
) where
import qualified Data.Map as M
import Annex.CheckAttr
import Annex.HashObject
import Annex.CheckIgnore
+import Annex.TransferrerPool
{- Runs an action that may throw exceptions, catching and displaying them. -}
action :: Annex () -> Annex Bool
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
stopCoProcesses
-{- Stops all long-running git query processes. -}
+{- Stops all long-running child processes, including git query processes. -}
stopCoProcesses :: Annex ()
stopCoProcesses = do
+ stopNonConcurrentSafeCoProcesses
+ emptyTransferrerPool
+
+{- Stops long-running child processes that use handles that are not safe
+ - for multiple threads to access at the same time. -}
+stopNonConcurrentSafeCoProcesses :: Annex ()
+stopNonConcurrentSafeCoProcesses = do
catFileStop
checkAttrStop
hashObjectStop
- Also closes various handles in it. -}
mergeState :: AnnexState -> Annex ()
mergeState st = do
- st' <- liftIO $ snd <$> run st stopCoProcesses
+ st' <- liftIO $ snd <$> run st stopNonConcurrentSafeCoProcesses
forM_ (M.toList $ Annex.cleanup st') $
uncurry addCleanup
Annex.Queue.mergeFrom st'
interruptProcessGroupOf $ transferrerHandle t
threadDelay 50000 -- 0.05 second grace period
terminateProcess $ transferrerHandle t
+
+{- Stop all transferrers in the pool. -}
+emptyTransferrerPool :: Annex ()
+emptyTransferrerPool = do
+ poolvar <- Annex.getState Annex.transferrerpool
+ pool <- liftIO $ atomically $ swapTVar poolvar []
+ liftIO $ forM_ pool $ \case
+ TransferrerPoolItem (Just t) _ -> shutdownTransferrer t
+ TransferrerPoolItem Nothing _ -> noop