From 25990f44ee0cdfae9fdafab72991f88e54a1a843 Mon Sep 17 00:00:00 2001 From: BonkaBonka Date: Tue, 3 Jan 2017 21:44:19 -0500 Subject: [PATCH] Abort verify at first hash mismatch. --- cmd/torrent-verify/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/torrent-verify/main.go b/cmd/torrent-verify/main.go index 4e5774d9..dfd14a74 100644 --- a/cmd/torrent-verify/main.go +++ b/cmd/torrent-verify/main.go @@ -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 }