restart coprocess in raw mode
authorJoey Hess <joeyh@joeyh.name>
Tue, 1 Nov 2016 18:03:55 +0000 (14:03 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 1 Nov 2016 18:03:59 +0000 (14:03 -0400)
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.

CHANGELOG
Git/CatFile.hs
Git/CheckAttr.hs
Git/CheckIgnore.hs
Git/HashObject.hs
Git/Tree.hs
Utility/CoProcess.hs

index 6a1301b3eba4abae8386a5cb9e8001cb34acce5a..a939435cf424dbfd02704a0b58caef36a5976e8b 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
 
   * Assistant, repair: Fix ignoring of git fsck errors due to
index 9af46fb51523458aa9aefa4281aabd80d227c424..061349f0547df377465ecfc9d5d8548d8455ca19 100644 (file)
@@ -51,7 +51,7 @@ catFileStart' restartable repo = CatFileHandle
        <$> startp "--batch"
        <*> startp "--batch-check=%(objectname) %(objecttype) %(objectsize)"
   where
-       startp p = CoProcess.rawMode =<< gitCoProcessStart restartable
+       startp p = gitCoProcessStart restartable
                [ Param "cat-file"
                , Param p
                ] repo
index b94bc0ee164e4931e9ae17ed634f21942ab9dada..a248f498227283d33369d1ca1d2b4497e0f6e53f 100644 (file)
@@ -24,7 +24,7 @@ type Attr = String
 checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle
 checkAttrStart attrs repo = do
        currdir <- getCurrentDirectory
-       h <- CoProcess.rawMode =<< gitCoProcessStart True params repo
+       h <- gitCoProcessStart True params repo
        oldgit <- Git.Version.older "1.7.7"
        return (h, attrs, oldgit, currdir)
   where
index 7d30e5ada96c710ac22d3d0a77f8b99b3d9da0d3..594882a81d73fe60a590bf45fa63fd91da3d9e16 100644 (file)
@@ -37,7 +37,7 @@ type CheckIgnoreHandle = CoProcess.CoProcessHandle
  -}
 checkIgnoreStart :: Repo -> IO (Maybe CheckIgnoreHandle)
 checkIgnoreStart repo = ifM supportedGitVersion
-       ( Just <$> (CoProcess.rawMode =<< gitCoProcessStart True params repo')
+       ( Just <$> gitCoProcessStart True params repo'
        , return Nothing
        )
   where
index ed3baf4c6e8707bb96bb9dbcafa9db3c805672a1..4cd54ef54c3590956946b97e3b288b5c7e29c9c7 100644 (file)
@@ -20,7 +20,7 @@ import Utility.Tmp
 type HashObjectHandle = CoProcess.CoProcessHandle
 
 hashObjectStart :: Repo -> IO HashObjectHandle
-hashObjectStart = CoProcess.rawMode <=< gitCoProcessStart True
+hashObjectStart = gitCoProcessStart True
        [ Param "hash-object"
        , Param "-w"
        , Param "--stdin-paths"
index c341e1f5bf434c34b371d3cd8c31121cd3b0325f..282643f498341eef3e98dbbec1a7f232e14e716e 100644 (file)
@@ -59,7 +59,7 @@ newtype MkTreeHandle = MkTreeHandle CoProcess.CoProcessHandle
 withMkTreeHandle :: (MonadIO m, MonadMask m) => Repo -> (MkTreeHandle -> m a) -> m a
 withMkTreeHandle repo a = bracketIO setup cleanup (a . MkTreeHandle)
   where
-       setup = CoProcess.rawMode =<< gitCoProcessStart False ps repo
+       setup = gitCoProcessStart False ps repo
        ps = [Param "mktree", Param "--batch", Param "-z"]
        cleanup = CoProcess.stop
 
index 9854b47fcd824fc3d1d54d71cf285ef7df9ecb3b..94d5ac3bc4172efc76a12531527c15227ae6576a 100644 (file)
@@ -13,7 +13,6 @@ module Utility.CoProcess (
        start,
        stop,
        query,
-       rawMode
 ) where
 
 import Common
@@ -44,7 +43,15 @@ start numrestarts cmd params environ = do
 start' :: CoProcessSpec -> IO CoProcessState
 start' s = do
        (pid, from, to) <- startInteractiveProcess (coProcessCmd s) (coProcessParams s) (coProcessEnv s)
+       rawMode from
+       rawMode to
        return $ CoProcessState pid to from s
+  where
+       rawMode h = do
+               fileEncoding h
+#ifdef mingw32_HOST_OS
+               hSetNewlineMode h noNewlineTranslation
+#endif
 
 stop :: CoProcessHandle -> IO ()
 stop ch = do
@@ -79,16 +86,3 @@ query ch send receive = do
                        { coProcessNumRestarts = coProcessNumRestarts (coProcessSpec s) - 1 }
                putMVar ch s'
                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