set locale encoding after fdTohandle
fdToHandle does not set the usual system locale encoding, so when the Handle is used for any String IO, it needs to be done manually for correctness. I don't know if this fixes any bugs. It might eg, fix a bug with multicast receive of a file. Sponsored-by: Leon Schuermann
This commit is contained in:
parent
1e847fd1af
commit
06a813ad44
4 changed files with 22 additions and 5 deletions
|
@ -18,6 +18,7 @@ import System.Posix.IO
|
||||||
#else
|
#else
|
||||||
import System.Process (createPipeFd)
|
import System.Process (createPipeFd)
|
||||||
#endif
|
#endif
|
||||||
|
import GHC.IO.Encoding (getLocaleEncoding)
|
||||||
|
|
||||||
multicastReceiveEnv :: String
|
multicastReceiveEnv :: String
|
||||||
multicastReceiveEnv = "GIT_ANNEX_MULTICAST_RECEIVE"
|
multicastReceiveEnv = "GIT_ANNEX_MULTICAST_RECEIVE"
|
||||||
|
@ -34,6 +35,7 @@ multicastCallbackEnv = do
|
||||||
(rfd, wfd) <- createPipeFd
|
(rfd, wfd) <- createPipeFd
|
||||||
#endif
|
#endif
|
||||||
rh <- fdToHandle rfd
|
rh <- fdToHandle rfd
|
||||||
|
getLocaleEncoding >>= hSetEncoding rh
|
||||||
environ <- addEntry multicastReceiveEnv (show wfd) <$> getEnvironment
|
environ <- addEntry multicastReceiveEnv (show wfd) <$> getEnvironment
|
||||||
return (gitannex, environ, rh)
|
return (gitannex, environ, rh)
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ runMulticastReceive :: [String] -> String -> IO ()
|
||||||
runMulticastReceive ("-I":_sessionid:fs) hs = case readish hs of
|
runMulticastReceive ("-I":_sessionid:fs) hs = case readish hs of
|
||||||
Just fd -> do
|
Just fd -> do
|
||||||
h <- fdToHandle fd
|
h <- fdToHandle fd
|
||||||
|
getLocaleEncoding >>= hSetEncoding h
|
||||||
mapM_ (hPutStrLn h) fs
|
mapM_ (hPutStrLn h) fs
|
||||||
hClose h
|
hClose h
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
|
|
15
Assistant.hs
15
Assistant.hs
|
@ -56,6 +56,8 @@ import Annex.Path
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
import Utility.Env
|
import Utility.Env
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
|
#else
|
||||||
|
import GHC.IO.Encoding (getLocaleEncoding)
|
||||||
#endif
|
#endif
|
||||||
import qualified Utility.Debug as Debug
|
import qualified Utility.Debug as Debug
|
||||||
|
|
||||||
|
@ -82,10 +84,15 @@ startDaemon assistant foreground startdelay cannotrun listenhost listenport star
|
||||||
let logfd = handleToFd =<< openLog (fromOsPath logfile)
|
let logfd = handleToFd =<< openLog (fromOsPath logfile)
|
||||||
if foreground
|
if foreground
|
||||||
then do
|
then do
|
||||||
origout <- liftIO $ catchMaybeIO $
|
enc <- liftIO getLocaleEncoding
|
||||||
fdToHandle =<< dup stdOutput
|
origout <- liftIO $ catchMaybeIO $ do
|
||||||
origerr <- liftIO $ catchMaybeIO $
|
h <- fdToHandle =<< dup stdOutput
|
||||||
fdToHandle =<< dup stdError
|
hSetEncoding h enc
|
||||||
|
return h
|
||||||
|
origerr <- liftIO $ catchMaybeIO $ do
|
||||||
|
h <- fdToHandle =<< dup stdError
|
||||||
|
hSetEncoding h enc
|
||||||
|
return h
|
||||||
let undaemonize = Utility.Daemon.foreground logfd (Just pidfile)
|
let undaemonize = Utility.Daemon.foreground logfd (Just pidfile)
|
||||||
start undaemonize $
|
start undaemonize $
|
||||||
case startbrowser of
|
case startbrowser of
|
||||||
|
|
|
@ -49,6 +49,7 @@ import System.Posix.Types
|
||||||
import System.Posix.IO.ByteString
|
import System.Posix.IO.ByteString
|
||||||
import System.Posix.Files.ByteString
|
import System.Posix.Files.ByteString
|
||||||
import System.Posix.Process
|
import System.Posix.Process
|
||||||
|
import GHC.IO.Encoding (getLocaleEncoding)
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Class (liftIO, MonadIO)
|
import Control.Monad.IO.Class (liftIO, MonadIO)
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -213,7 +214,9 @@ linkToLock (Just _) src dest = do
|
||||||
(Just $ combineModes readModes)
|
(Just $ combineModes readModes)
|
||||||
(defaultFileFlags { exclusive = True })
|
(defaultFileFlags { exclusive = True })
|
||||||
(CloseOnExecFlag True)
|
(CloseOnExecFlag True)
|
||||||
fdToHandle fd
|
h <- fdToHandle fd
|
||||||
|
getLocaleEncoding >>= hSetEncoding h
|
||||||
|
return h
|
||||||
let cleanup = hClose
|
let cleanup = hClose
|
||||||
let go h = F.readFileString src >>= hPutStr h
|
let go h = F.readFileString src >>= hPutStr h
|
||||||
bracket setup cleanup go
|
bracket setup cleanup go
|
||||||
|
|
|
@ -23,6 +23,7 @@ import Control.Monad
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
import qualified System.Posix.IO
|
import qualified System.Posix.IO
|
||||||
|
import GHC.IO.Encoding (getLocaleEncoding)
|
||||||
#else
|
#else
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
#endif
|
#endif
|
||||||
|
@ -51,6 +52,9 @@ processTranscript'' cp input = do
|
||||||
System.Posix.IO.setFdOption writef System.Posix.IO.CloseOnExec True
|
System.Posix.IO.setFdOption writef System.Posix.IO.CloseOnExec True
|
||||||
readh <- System.Posix.IO.fdToHandle readf
|
readh <- System.Posix.IO.fdToHandle readf
|
||||||
writeh <- System.Posix.IO.fdToHandle writef
|
writeh <- System.Posix.IO.fdToHandle writef
|
||||||
|
enc <- getLocaleEncoding
|
||||||
|
hSetEncoding readh enc
|
||||||
|
hSetEncoding writeh enc
|
||||||
return (readh, writeh)
|
return (readh, writeh)
|
||||||
let cleanup (readh, writeh) = do
|
let cleanup (readh, writeh) = do
|
||||||
hClose readh
|
hClose readh
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue