Abort verify at first hash mismatch.

This commit is contained in:
BonkaBonka 2017-01-03 21:44:19 -05:00
parent 9cf09dba8a
commit 25990f44ee
1 changed files with 6 additions and 2 deletions

View File

@ -51,9 +51,13 @@ func verifyTorrent(info *metainfo.Info, root string) error {
hash := sha1.New()
_, err := io.Copy(hash, io.NewSectionReader(span, p.Offset(), p.Length()))
if err != nil {
log.Fatal(err)
return err
}
fmt.Printf("%d: %x: %v\n", i, p.Hash(), bytes.Equal(hash.Sum(nil), p.Hash().Bytes()))
good := bytes.Equal(hash.Sum(nil), p.Hash().Bytes())
if !good {
return fmt.Errorf("hash mismatch at piece %d", i)
}
fmt.Printf("%d: %x: %v\n", i, p.Hash(), good)
}
return nil
}