fix remote fsck to run in remote

This commit is contained in:
Joey Hess 2013-10-14 15:05:10 -04:00
parent c78aaed317
commit a6e9386d39
2 changed files with 18 additions and 6 deletions

View file

@ -42,6 +42,7 @@ import Utility.Metered
#ifndef mingw32_HOST_OS
import Utility.CopyFile
#endif
import Utility.Env
import Utility.Batch
import Remote.Helper.Git
import Remote.Helper.Messages
@ -410,7 +411,13 @@ fsckOnRemote r params
Just (c, ps) -> batchCommand c ps
| otherwise = return $ do
program <- readProgramFile
batchCommand program $ Param "fsck" : params
env <- getEnvironment
r' <- Git.Config.read r
let env' =
[ ("GIT_WORK_TREE", Git.repoPath r')
, ("GIT_DIR", Git.localGitDir r')
] ++ env
batchCommandEnv program (Param "fsck" : params) (Just env')
{- Runs an action on a local repository inexpensively, by making an annex
- monad using that repository. -}

View file

@ -17,6 +17,7 @@ import Control.Concurrent.Async
import System.Posix.Process
#endif
import qualified Control.Exception as E
import System.Process (env)
{- Runs an operation, at batch priority.
-
@ -48,11 +49,11 @@ maxNice = 19
- exception, it sends the command a SIGTERM, and after the command
- finishes shuttting down, it re-raises the async exception. -}
batchCommand :: String -> [CommandParam] -> IO Bool
batchCommand command params = do
(_, _, _, pid) <- createProcess $ proc "sh"
[ "-c"
, "exec " ++ nicedcommand
]
batchCommand command params = batchCommandEnv command params Nothing
batchCommandEnv :: String -> [CommandParam] -> Maybe [(String, String)] -> IO Bool
batchCommandEnv command params environ = do
(_, _, _, pid) <- createProcess $ p { env = environ }
r <- E.try (waitForProcess pid) :: IO (Either E.SomeException ExitCode)
case r of
Right ExitSuccess -> return True
@ -62,6 +63,10 @@ batchCommand command params = do
void $ waitForProcess pid
E.throwIO asyncexception
where
p = proc "sh"
[ "-c"
, "exec " ++ nicedcommand
]
commandline = unwords $ map shellEscape $ command : toCommand params
nicedcommand
| Build.SysConfig.nice = "nice " ++ commandline