Preserve parent environment when running hooks of the hook special remote.

This commit is contained in:
Joey Hess 2012-06-04 21:52:36 -04:00
parent b86825e42b
commit 13118136c0
2 changed files with 12 additions and 6 deletions

View file

@ -10,6 +10,7 @@ module Remote.Hook (remote) where
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Map as M
import System.Exit
import System.Environment
import Common.Annex
import Types.Remote
@ -59,9 +60,12 @@ hookSetup u c = do
gitConfigSpecialRemote u c' "hooktype" hooktype
return c'
hookEnv :: Key -> Maybe FilePath -> Maybe [(String, String)]
hookEnv k f = Just $ fileenv f ++ keyenv
hookEnv :: Key -> Maybe FilePath -> IO (Maybe [(String, String)])
hookEnv k f = Just <$> mergeenv (fileenv f ++ keyenv)
where
mergeenv l = M.toList .
M.union (M.fromList l)
<$> M.fromList <$> getEnvironment
env s v = ("ANNEX_" ++ s, v)
keyenv =
[ env "KEY" (show k)
@ -88,8 +92,9 @@ runHook hooktype hook k f a = maybe (return False) run =<< lookupHook hooktype h
where
run command = do
showOutput -- make way for hook output
ifM (liftIO $ boolSystemEnv
"sh" [Param "-c", Param command] $ hookEnv k f)
ifM (liftIO $
boolSystemEnv "sh" [Param "-c", Param command]
=<< hookEnv k f)
( a
, do
warning $ hook ++ " hook exited nonzero!"
@ -129,14 +134,14 @@ checkPresent r h k = do
liftIO $ catchMsgIO $ check v
where
findkey s = show k `elem` lines s
env = hookEnv k Nothing
check Nothing = error "checkpresent hook misconfigured"
check (Just hook) = do
(frompipe, topipe) <- createPipe
pid <- forkProcess $ do
_ <- dupTo topipe stdOutput
closeFd frompipe
executeFile "sh" True ["-c", hook] env
executeFile "sh" True ["-c", hook]
=<< hookEnv k Nothing
closeFd topipe
fromh <- fdToHandle frompipe
reply <- hGetContentsStrict fromh

1
debian/changelog vendored
View file

@ -8,6 +8,7 @@ git-annex (3.20120523) UNRELEASED; urgency=low
unsupported backend.
* Require that the SHA256 backend can be used when building, since it's the
default.
* Preserve parent environment when running hooks of the hook special remote.
-- Joey Hess <joeyh@debian.org> Sun, 27 May 2012 20:55:29 -0400