fix meter display on resume

It still needs to be offset, otherwise on resume from 80% it will
display 1%..20%.

Seems that this bug must have affected P2P.Annex as well where it runs
this code, but apparently it didn't affect it in a very user-visible
way. Maybe the transfer log file was updated incorrectly?
This commit is contained in:
Joey Hess 2024-07-24 10:28:48 -04:00
parent 7bd616e169
commit 0594338a78
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -224,28 +224,29 @@ writeVerifyChunk Nothing h c = S.hPut h c
{- Given a file handle that is open for reading (and likely also for writing), {- Given a file handle that is open for reading (and likely also for writing),
- and an offset, feeds the current content of the file up to the offset to - and an offset, feeds the current content of the file up to the offset to
- the IncrementalVerifier. Leaves the file seeked to the offset. - the IncrementalVerifier. Leaves the file seeked to the offset.
- Also updates the meter to the offset. -} - Returns the meter with the offset applied. -}
resumeVerifyFromOffset resumeVerifyFromOffset
:: Integer :: Integer
-> Maybe IncrementalVerifier -> Maybe IncrementalVerifier
-> MeterUpdate -> MeterUpdate
-> Handle -> Handle
-> IO MeterUpdate -> IO MeterUpdate
resumeVerifyFromOffset o incrementalverifier p h resumeVerifyFromOffset o incrementalverifier meterupdate h
| o /= 0 = do | o /= 0 = do
p' <- case incrementalverifier of p' <- case incrementalverifier of
Just iv -> do Just iv -> do
go iv o go iv o
return p return offsetmeterupdate
_ -> return $ offsetMeterUpdate p (toBytesProcessed o) _ -> return offsetmeterupdate
-- Make sure the handle is seeked to the offset. -- Make sure the handle is seeked to the offset.
-- (Reading the file probably left it there -- (Reading the file probably left it there
-- when that was done, but let's be sure.) -- when that was done, but let's be sure.)
hSeek h AbsoluteSeek o hSeek h AbsoluteSeek o
return p' return p'
| otherwise = return p | otherwise = return meterupdate
where where
offsetmeterupdate = offsetMeterUpdate meterupdate (toBytesProcessed o)
go iv n go iv n
| n == 0 = return () | n == 0 = return ()
| otherwise = do | otherwise = do