From 617362ddf0b8c71ca7383f23bb4b853e5bac5970 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 27 May 2023 15:05:23 +1000 Subject: [PATCH] go1.19 compat --- client-nowasm_test.go | 2 +- client.go | 5 ++--- storage/mmap.go | 6 +++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client-nowasm_test.go b/client-nowasm_test.go index 3ce43f2a..687f4204 100644 --- a/client-nowasm_test.go +++ b/client-nowasm_test.go @@ -59,7 +59,7 @@ func TestIssue335(t *testing.T) { cfg.DefaultStorage = mmapStorage cl, err := NewClient(cfg) c.Assert(err, qt.IsNil) - defer logErr(cl.Close, "closing client") + defer cl.Close() tor, new, err := cl.AddTorrentSpec(TorrentSpecFromMetaInfo(mi)) c.Assert(err, qt.IsNil) c.Assert(new, qt.IsTrue) diff --git a/client.go b/client.go index f1a7a3c7..a87e4439 100644 --- a/client.go +++ b/client.go @@ -425,10 +425,9 @@ func (cl *Client) eachDhtServer(f func(DhtServer)) { } // Stops the client. All connections to peers are closed and all activity will come to a halt. -func (cl *Client) Close() error { +func (cl *Client) Close() (errs []error) { var closeGroup sync.WaitGroup // For concurrent cleanup to complete before returning cl.lock() - var errs []error for _, t := range cl.torrents { err := t.close(&closeGroup) if err != nil { @@ -442,7 +441,7 @@ func (cl *Client) Close() error { cl.unlock() cl.event.Broadcast() closeGroup.Wait() // defer is LIFO. We want to Wait() after cl.unlock() - return errors.Join(errs...) + return } func (cl *Client) ipBlockRange(ip net.IP) (r iplist.Range, blocked bool) { diff --git a/storage/mmap.go b/storage/mmap.go index 1b5d05a2..1851c323 100644 --- a/storage/mmap.go +++ b/storage/mmap.go @@ -215,7 +215,11 @@ func (m mmapWithFile) Unmap() (err error) { if m.mmap != nil { err = m.mmap.Unmap() } - return errors.Join(err, m.f.Close()) + fileErr := m.f.Close() + if err == nil { + err = fileErr + } + return } func (m mmapWithFile) Bytes() []byte { -- 2.44.0