2015-07-31 20:00:13 +00:00
|
|
|
{- git-annex actions
|
|
|
|
-
|
2020-12-09 17:10:35 +00:00
|
|
|
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
2015-07-31 20:00:13 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-07-31 20:00:13 +00:00
|
|
|
-}
|
|
|
|
|
2020-12-11 19:28:58 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2019-06-19 16:35:08 +00:00
|
|
|
module Annex.Action (
|
2020-12-07 18:44:21 +00:00
|
|
|
action,
|
|
|
|
verifiedAction,
|
2019-06-19 16:35:08 +00:00
|
|
|
startup,
|
|
|
|
shutdown,
|
|
|
|
stopCoProcesses,
|
2020-12-09 17:10:35 +00:00
|
|
|
stopNonConcurrentSafeCoProcesses,
|
2019-06-19 16:35:08 +00:00
|
|
|
) where
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2015-07-31 20:00:13 +00:00
|
|
|
import qualified Annex
|
|
|
|
import Annex.Content
|
2020-04-17 18:36:45 +00:00
|
|
|
import Annex.CatFile
|
|
|
|
import Annex.CheckAttr
|
|
|
|
import Annex.HashObject
|
|
|
|
import Annex.CheckIgnore
|
2020-12-09 17:10:35 +00:00
|
|
|
import Annex.TransferrerPool
|
2015-07-31 20:00:13 +00:00
|
|
|
|
2020-12-11 19:28:58 +00:00
|
|
|
import Control.Concurrent.STM
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import System.Posix.Signals
|
|
|
|
#endif
|
|
|
|
|
2020-12-07 18:44:21 +00:00
|
|
|
{- Runs an action that may throw exceptions, catching and displaying them. -}
|
|
|
|
action :: Annex () -> Annex Bool
|
|
|
|
action a = tryNonAsync a >>= \case
|
|
|
|
Right () -> return True
|
|
|
|
Left e -> do
|
|
|
|
warning (show e)
|
|
|
|
return False
|
|
|
|
|
|
|
|
verifiedAction :: Annex Verification -> Annex (Bool, Verification)
|
|
|
|
verifiedAction a = tryNonAsync a >>= \case
|
|
|
|
Right v -> return (True, v)
|
|
|
|
Left e -> do
|
|
|
|
warning (show e)
|
|
|
|
return (False, UnVerified)
|
|
|
|
|
|
|
|
|
2015-07-31 20:00:13 +00:00
|
|
|
{- Actions to perform each time ran. -}
|
|
|
|
startup :: Annex ()
|
2020-12-11 19:28:58 +00:00
|
|
|
startup = do
|
|
|
|
#ifndef mingw32_HOST_OS
|
2021-04-02 19:26:21 +00:00
|
|
|
av <- Annex.getRead Annex.signalactions
|
2020-12-11 19:28:58 +00:00
|
|
|
let propagate sig = liftIO $ installhandleronce sig av
|
|
|
|
propagate sigINT
|
|
|
|
propagate sigQUIT
|
|
|
|
propagate sigTERM
|
|
|
|
propagate sigTSTP
|
|
|
|
propagate sigCONT
|
|
|
|
propagate sigHUP
|
|
|
|
-- sigWINCH is not propagated; it should not be needed,
|
|
|
|
-- and the concurrent-output library installs its own signal
|
|
|
|
-- handler for it.
|
|
|
|
-- sigSTOP and sigKILL cannot be caught, so will not be propagated.
|
|
|
|
where
|
|
|
|
installhandleronce sig av = void $
|
|
|
|
installHandler sig (CatchOnce (gotsignal sig av)) Nothing
|
|
|
|
gotsignal sig av = do
|
|
|
|
mapM_ (\a -> a (fromIntegral sig)) =<< atomically (readTVar av)
|
|
|
|
raiseSignal sig
|
|
|
|
installhandleronce sig av
|
|
|
|
#else
|
|
|
|
return ()
|
|
|
|
#endif
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
{- Cleanup actions. -}
|
|
|
|
shutdown :: Bool -> Annex ()
|
|
|
|
shutdown nocommit = do
|
|
|
|
saveState nocommit
|
2020-12-11 19:28:58 +00:00
|
|
|
sequence_ =<< M.elems <$> Annex.getState Annex.cleanupactions
|
2017-09-30 02:36:08 +00:00
|
|
|
stopCoProcesses
|
|
|
|
|
2020-12-09 17:10:35 +00:00
|
|
|
{- Stops all long-running child processes, including git query processes. -}
|
2020-04-17 18:36:45 +00:00
|
|
|
stopCoProcesses :: Annex ()
|
|
|
|
stopCoProcesses = do
|
2020-12-09 17:10:35 +00:00
|
|
|
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
|
2020-04-17 18:36:45 +00:00
|
|
|
catFileStop
|
|
|
|
checkAttrStop
|
|
|
|
hashObjectStop
|
|
|
|
checkIgnoreStop
|