]> git.rkrishnan.org Git - functorrent.git/commitdiff
bugfix: use the previous piece length times number of pieces to calculate offset
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 25 Jul 2015 01:29:20 +0000 (06:59 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 25 Jul 2015 01:29:20 +0000 (06:59 +0530)
src/FuncTorrent/Peer.hs

index 0bce055a9327b5c4ad8cbc658e82510fbf509acf..9984a2ac2ed979df480dd25f26c6515e02f809e8 100644 (file)
@@ -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)