From db497638492bba06ce2a27f39bf72c6acaa395dc Mon Sep 17 00:00:00 2001
From: Richard Nyberg <rnyberg@murmeldjur.se>
Date: Sat, 18 Mar 2006 20:28:46 +0000
Subject: [PATCH] The previous commit was a bit over zealous; the block field
 should not be cleared for a failed piece in the full torrent test. This also
 fixes a bug where the content byte count wasn't decreased for failed pieces.

---
 btpd/content.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/btpd/content.c b/btpd/content.c
index d86d596..9521610 100644
--- a/btpd/content.c
+++ b/btpd/content.c
@@ -562,10 +562,8 @@ test_torrent(struct torrent *tp, volatile sig_atomic_t *cancel)
             break;
         if (test_hash(tp, hash, piece) == 0)
             set_bit(tp->cm->piece_field, piece);
-        else {
+        else
             clear_bit(tp->cm->piece_field, piece);
-            bzero(cm->block_field + piece * cm->bppbf, cm->bppbf);
-        }
         if (*cancel) {
             err = EINTR;
             break;
@@ -741,8 +739,10 @@ cm_td_start(struct cm_op *op)
             if (ok) {
                 set_bit(cm->pos_field, piece);
                 set_bit(cm->piece_field, piece);
-            } else
+            } else {
                 bzero(bf, cm->bppbf);
+                cm->ncontent_bytes -= torrent_piece_size(tp, piece);
+            }
         } else if (nblocks_got > 0)
             set_bit(cm->pos_field, piece);
     }