restart coprocess in raw mode
Restarting a crashing git process could result in filename encoding issues when not in a unicode locale, as the restarted processes's handles were not read in raw mode. Since rawMode is always used when starting a coprocess, didn't bother to parameterise it and just always enable it for simplicity. This commit was sponsored by Jake Vosloo on Patreon.
This commit is contained in:
parent
f08ad2f916
commit
e23028d19b
7 changed files with 21 additions and 19 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
git-annex (6.20161032) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* Restarting a crashing git process could result in filename encoding
|
||||||
|
issues when not in a unicode locale, as the restarted processes's
|
||||||
|
handles were not read in raw mode.
|
||||||
|
|
||||||
|
-- Joey Hess <id@joeyh.name> Tue, 01 Nov 2016 14:02:06 -0400
|
||||||
|
|
||||||
git-annex (6.20161031) unstable; urgency=medium
|
git-annex (6.20161031) unstable; urgency=medium
|
||||||
|
|
||||||
* Assistant, repair: Fix ignoring of git fsck errors due to
|
* Assistant, repair: Fix ignoring of git fsck errors due to
|
||||||
|
|
|
@ -51,7 +51,7 @@ catFileStart' restartable repo = CatFileHandle
|
||||||
<$> startp "--batch"
|
<$> startp "--batch"
|
||||||
<*> startp "--batch-check=%(objectname) %(objecttype) %(objectsize)"
|
<*> startp "--batch-check=%(objectname) %(objecttype) %(objectsize)"
|
||||||
where
|
where
|
||||||
startp p = CoProcess.rawMode =<< gitCoProcessStart restartable
|
startp p = gitCoProcessStart restartable
|
||||||
[ Param "cat-file"
|
[ Param "cat-file"
|
||||||
, Param p
|
, Param p
|
||||||
] repo
|
] repo
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Attr = String
|
||||||
checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle
|
checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle
|
||||||
checkAttrStart attrs repo = do
|
checkAttrStart attrs repo = do
|
||||||
currdir <- getCurrentDirectory
|
currdir <- getCurrentDirectory
|
||||||
h <- CoProcess.rawMode =<< gitCoProcessStart True params repo
|
h <- gitCoProcessStart True params repo
|
||||||
oldgit <- Git.Version.older "1.7.7"
|
oldgit <- Git.Version.older "1.7.7"
|
||||||
return (h, attrs, oldgit, currdir)
|
return (h, attrs, oldgit, currdir)
|
||||||
where
|
where
|
||||||
|
|
|
@ -37,7 +37,7 @@ type CheckIgnoreHandle = CoProcess.CoProcessHandle
|
||||||
-}
|
-}
|
||||||
checkIgnoreStart :: Repo -> IO (Maybe CheckIgnoreHandle)
|
checkIgnoreStart :: Repo -> IO (Maybe CheckIgnoreHandle)
|
||||||
checkIgnoreStart repo = ifM supportedGitVersion
|
checkIgnoreStart repo = ifM supportedGitVersion
|
||||||
( Just <$> (CoProcess.rawMode =<< gitCoProcessStart True params repo')
|
( Just <$> gitCoProcessStart True params repo'
|
||||||
, return Nothing
|
, return Nothing
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
|
@ -20,7 +20,7 @@ import Utility.Tmp
|
||||||
type HashObjectHandle = CoProcess.CoProcessHandle
|
type HashObjectHandle = CoProcess.CoProcessHandle
|
||||||
|
|
||||||
hashObjectStart :: Repo -> IO HashObjectHandle
|
hashObjectStart :: Repo -> IO HashObjectHandle
|
||||||
hashObjectStart = CoProcess.rawMode <=< gitCoProcessStart True
|
hashObjectStart = gitCoProcessStart True
|
||||||
[ Param "hash-object"
|
[ Param "hash-object"
|
||||||
, Param "-w"
|
, Param "-w"
|
||||||
, Param "--stdin-paths"
|
, Param "--stdin-paths"
|
||||||
|
|
|
@ -59,7 +59,7 @@ newtype MkTreeHandle = MkTreeHandle CoProcess.CoProcessHandle
|
||||||
withMkTreeHandle :: (MonadIO m, MonadMask m) => Repo -> (MkTreeHandle -> m a) -> m a
|
withMkTreeHandle :: (MonadIO m, MonadMask m) => Repo -> (MkTreeHandle -> m a) -> m a
|
||||||
withMkTreeHandle repo a = bracketIO setup cleanup (a . MkTreeHandle)
|
withMkTreeHandle repo a = bracketIO setup cleanup (a . MkTreeHandle)
|
||||||
where
|
where
|
||||||
setup = CoProcess.rawMode =<< gitCoProcessStart False ps repo
|
setup = gitCoProcessStart False ps repo
|
||||||
ps = [Param "mktree", Param "--batch", Param "-z"]
|
ps = [Param "mktree", Param "--batch", Param "-z"]
|
||||||
cleanup = CoProcess.stop
|
cleanup = CoProcess.stop
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ module Utility.CoProcess (
|
||||||
start,
|
start,
|
||||||
stop,
|
stop,
|
||||||
query,
|
query,
|
||||||
rawMode
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common
|
import Common
|
||||||
|
@ -44,7 +43,15 @@ start numrestarts cmd params environ = do
|
||||||
start' :: CoProcessSpec -> IO CoProcessState
|
start' :: CoProcessSpec -> IO CoProcessState
|
||||||
start' s = do
|
start' s = do
|
||||||
(pid, from, to) <- startInteractiveProcess (coProcessCmd s) (coProcessParams s) (coProcessEnv s)
|
(pid, from, to) <- startInteractiveProcess (coProcessCmd s) (coProcessParams s) (coProcessEnv s)
|
||||||
|
rawMode from
|
||||||
|
rawMode to
|
||||||
return $ CoProcessState pid to from s
|
return $ CoProcessState pid to from s
|
||||||
|
where
|
||||||
|
rawMode h = do
|
||||||
|
fileEncoding h
|
||||||
|
#ifdef mingw32_HOST_OS
|
||||||
|
hSetNewlineMode h noNewlineTranslation
|
||||||
|
#endif
|
||||||
|
|
||||||
stop :: CoProcessHandle -> IO ()
|
stop :: CoProcessHandle -> IO ()
|
||||||
stop ch = do
|
stop ch = do
|
||||||
|
@ -79,16 +86,3 @@ query ch send receive = do
|
||||||
{ coProcessNumRestarts = coProcessNumRestarts (coProcessSpec s) - 1 }
|
{ coProcessNumRestarts = coProcessNumRestarts (coProcessSpec s) - 1 }
|
||||||
putMVar ch s'
|
putMVar ch s'
|
||||||
query ch send receive
|
query ch send receive
|
||||||
|
|
||||||
rawMode :: CoProcessHandle -> IO CoProcessHandle
|
|
||||||
rawMode ch = do
|
|
||||||
s <- readMVar ch
|
|
||||||
raw $ coProcessFrom s
|
|
||||||
raw $ coProcessTo s
|
|
||||||
return ch
|
|
||||||
where
|
|
||||||
raw h = do
|
|
||||||
fileEncoding h
|
|
||||||
#ifdef mingw32_HOST_OS
|
|
||||||
hSetNewlineMode h noNewlineTranslation
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue