From edf59f0b1fb2c9e6e19a14d8257f647302ad1baf Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 27 Feb 2024 23:22:07 +1100 Subject: [PATCH] cmd/torrent download: Handle interrupt when linear discarding --- cmd/torrent/download.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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() { -- 2.44.0