deal with possibility of short read by S.hGet

It may read less than requested, and may yield an empty string if the
file was somehow shorter than expected.
This commit is contained in:
Joey Hess 2021-02-09 22:15:33 -04:00
parent 62e152f210
commit 94f6210b68
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -172,11 +172,14 @@ runLocal runst runner a = case a of
where
go iv n
| n == 0 = return ()
| n > fromIntegral defaultChunkSize = do
updateIncremental iv =<< S.hGet h defaultChunkSize
go iv (n - fromIntegral defaultChunkSize)
| otherwise =
updateIncremental iv =<< S.hGet h (fromIntegral n)
| otherwise = do
let c = if n > fromIntegral defaultChunkSize
then defaultChunkSize
else fromIntegral n
b <- S.hGet h c
updateIncremental iv b
unless (b == S.empty) $
go iv (n - fromIntegral (S.length b))
storefile dest (Offset o) (Len l) getb incrementalverifier validitycheck p ti = do
v <- runner getb