2015-07-31 20:00:13 +00:00
|
|
|
{- git-annex actions
|
|
|
|
-
|
|
|
|
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Annex.Action where
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
#ifndef mingw32_HOST_OS
|
2017-12-31 20:08:31 +00:00
|
|
|
import System.Posix.Process (getAnyProcessStatus)
|
|
|
|
import Utility.Exception
|
2015-07-31 20:00:13 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
2017-09-30 02:36:08 +00:00
|
|
|
import Annex.CatFile
|
|
|
|
import Annex.CheckAttr
|
|
|
|
import Annex.HashObject
|
|
|
|
import Annex.CheckIgnore
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
{- Actions to perform each time ran. -}
|
|
|
|
startup :: Annex ()
|
2019-01-21 21:21:02 +00:00
|
|
|
startup = return ()
|
2015-07-31 20:00:13 +00:00
|
|
|
|
|
|
|
{- Cleanup actions. -}
|
|
|
|
shutdown :: Bool -> Annex ()
|
|
|
|
shutdown nocommit = do
|
|
|
|
saveState nocommit
|
|
|
|
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
|
2017-09-30 02:36:08 +00:00
|
|
|
stopCoProcesses
|
2015-07-31 20:00:13 +00:00
|
|
|
liftIO reapZombies -- zombies from long-running git processes
|
2017-09-30 02:36:08 +00:00
|
|
|
|
|
|
|
{- Stops all long-running git query processes. -}
|
|
|
|
stopCoProcesses :: Annex ()
|
|
|
|
stopCoProcesses = do
|
|
|
|
catFileStop
|
|
|
|
checkAttrStop
|
|
|
|
hashObjectStop
|
|
|
|
checkIgnoreStop
|
2017-12-31 20:08:31 +00:00
|
|
|
|
|
|
|
{- Reaps any zombie processes that may be hanging around.
|
|
|
|
-
|
|
|
|
- Warning: Not thread safe. Anything that was expecting to wait
|
|
|
|
- on a process and get back an exit status is going to be confused
|
|
|
|
- if this reap gets there first. -}
|
|
|
|
reapZombies :: IO ()
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
reapZombies =
|
|
|
|
-- throws an exception when there are no child processes
|
|
|
|
catchDefaultIO Nothing (getAnyProcessStatus False True)
|
|
|
|
>>= maybe (return ()) (const reapZombies)
|
|
|
|
|
|
|
|
#else
|
|
|
|
reapZombies = return ()
|
|
|
|
#endif
|