From: Ramakrishnan Muthukrishnan Date: Sat, 25 Jul 2015 01:29:20 +0000 (+0530) Subject: bugfix: use the previous piece length times number of pieces to calculate offset X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css//%22file:/%22?a=commitdiff_plain;h=40c4dccba2b180faa3857fddb0a2b8968785fa90;p=functorrent.git bugfix: use the previous piece length times number of pieces to calculate offset --- diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index 0bce055..9984a2a 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -220,7 +220,8 @@ msgLoop pState pieceStatus | meInterested pState == False && then putStrLn $ "Hash mismatch: " ++ show (hash (pieceStatus ! workPiece)) ++ " vs " ++ show (take 20 (SHA1.hash pBS)) else do - writeFileAtOffset "/tmp/download.file" (workPiece * pLen) pBS + let fileOffset = if workPiece == 0 then 0 else (len (pieceStatus ! (workPiece - 1))) + writeFileAtOffset "/tmp/download.file" fileOffset pBS msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus) | otherwise = do msg <- getMsg (handle pState)