]> git.rkrishnan.org Git - functorrent.git/commitdiff
bugfix: calculate proper file offset
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 25 Jul 2015 06:42:03 +0000 (12:12 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 25 Jul 2015 06:42:03 +0000 (12:12 +0530)
src/FuncTorrent/Peer.hs

index 845c14aa0d51f675a9ee00184c761ebeae0db486..baf9ce8d7fce2f381bd26d8446647e0bd859b726 100644 (file)
@@ -218,7 +218,8 @@ msgLoop pState pieceStatus | not (meInterested pState) && heChoking pState = do
                                    then
                                    putStrLn $ "Hash mismatch: " ++ show (hash (pieceStatus ! workPiece)) ++ " vs " ++ show (take 20 (SHA1.hash pBS))
                                    else do
-                                   let fileOffset = if workPiece == 0 then 0 else (len (pieceStatus ! (workPiece - 1)))
+                                   let fileOffset = if workPiece == 0 then 0 else workPiece * len (pieceStatus ! (workPiece - 1))
+                                   putStrLn $ "Write into file at offset: " ++ show fileOffset
                                    writeFileAtOffset "/tmp/download.file" fileOffset pBS
                                    msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus)
                           | otherwise = do