From: Matt Joiner Date: Tue, 27 Feb 2024 12:22:07 +0000 (+1100) Subject: cmd/torrent download: Handle interrupt when linear discarding X-Git-Tag: v1.55.0~1 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=edf59f0b1fb2c9e6e19a14d8257f647302ad1baf;p=btrtrc.git cmd/torrent download: Handle interrupt when linear discarding --- diff --git a/cmd/torrent/download.go b/cmd/torrent/download.go index 1fc4759f..60482018 100644 --- a/cmd/torrent/download.go +++ b/cmd/torrent/download.go @@ -171,10 +171,18 @@ func addTorrents( defer wg.Done() waitForPieces(ctx, t, 0, t.NumPieces()) }() - if flags.LinearDiscard { - r := t.NewReader() - io.Copy(io.Discard, r) - r.Close() + done := make(chan struct{}) + go func() { + defer close(done) + if flags.LinearDiscard { + r := t.NewReader() + io.Copy(io.Discard, r) + r.Close() + } + }() + select { + case <-done: + case <-ctx.Done(): } } else { for _, f := range t.Files() {