Merge pull request #144 from BonkaBonka/fastfail

Abort verify at first hash mismatch.
This commit is contained in:
Matt Joiner 2017-01-04 14:42:59 +11:00 committed by GitHub
commit 984a69c73a
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
}