From: Matt Joiner Date: Wed, 9 Apr 2025 05:05:26 +0000 (+1000) Subject: Add Torrent.VerifyDataContext X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=847bb72223aea8c2c4c7df90fc3a50e3d0b4e1a4;p=btrtrc.git Add Torrent.VerifyDataContext --- diff --git a/torrent.go b/torrent.go index f8cfec77..33dd9fc4 100644 --- a/torrent.go +++ b/torrent.go @@ -2674,12 +2674,23 @@ func (t *Torrent) queuePieceCheck(pieceIndex pieceIndex) (targetVerifies pieceVe return } -// Forces all the pieces to be re-hashed. See also Piece.VerifyData. This should not be called -// before the Info is available. -func (t *Torrent) VerifyData() { +// Deprecated: Use Torrent.VerifyDataContext. +func (t *Torrent) VerifyData() error { + return t.VerifyDataContext(context.Background()) +} + +// Forces all the pieces to be re-hashed. See also Piece.VerifyDataContext. This +// should not be called before the Info is available. TODO: Make this operate +// concurrently within the configured piece hashers limit. +func (t *Torrent) VerifyDataContext(ctx context.Context) error { for i := 0; i < t.NumPieces(); i++ { - t.Piece(i).VerifyData() + err := t.Piece(i).VerifyDataContext(ctx) + if err != nil { + err = fmt.Errorf("verifying piece %v: %w", i, err) + return err + } } + return nil } func (t *Torrent) connectingToPeerAddr(addrStr string) bool {