From 847bb72223aea8c2c4c7df90fc3a50e3d0b4e1a4 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 9 Apr 2025 15:05:26 +1000 Subject: [PATCH] Add Torrent.VerifyDataContext --- torrent.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 { -- 2.48.1