diff options
author | Joey Hess <joey@kitenet.net> | 2012-09-16 01:53:06 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-09-16 01:53:06 -0400 |
commit | 0b12db64d834979d49ed378235b0c19b34e4a4d6 (patch) | |
tree | fe1eb17238da3cb34f4e481c8f1267612397d889 /Backend | |
parent | 947b447626e04754cab397df9e7187ec127f85d7 (diff) |
Avoid crashing on encoding errors in filenames when writing transfer info files and reading from checksum commands.
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/SHA.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs index 497e7d7e2..bfb94df99 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -16,6 +16,7 @@ import Types.KeySource import qualified Build.SysConfig as SysConfig import Data.Digest.Pure.SHA import qualified Data.ByteString.Lazy as L +import System.Process type SHASize = Int @@ -55,7 +56,7 @@ shaN shasize file filesize = do case shaCommand shasize filesize of Left sha -> liftIO $ sha <$> L.readFile file Right command -> liftIO $ parse command . lines <$> - readProcess command (toCommand [File file]) + readsha command (toCommand [File file]) where parse command [] = bad command parse command (l:_) @@ -64,6 +65,16 @@ shaN shasize file filesize = do where sha = fst $ separate (== ' ') l bad command = error $ command ++ " parse error" + {- sha commands output the filename, so need to set fileEncoding -} + readsha command args = + withHandle StdoutHandle createProcessSuccess p $ \h -> do + fileEncoding h + output <- hGetContentsStrict h + hClose h + return output + where + p = (proc command args) + { std_out = CreatePipe } shaCommand :: SHASize -> Integer -> Either (L.ByteString -> String) String shaCommand shasize filesize |