Avoid crashing on encoding errors in filenames when writing transfer info files and reading from checksum commands.
This commit is contained in:
parent
947b447626
commit
0b12db64d8
4 changed files with 39 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue