maildir,notmuch: avoid leaking open files

Previously, Message.NewReader returned the wrapped buffered reader
without a reference to the opened file, so the files descriptors
were left unclosed after reading.  Now, the file reader is returned
directly and closed on the call site.  Buffering is not needed here
because it is an implementation detail of go-message.

Fixes: https://todo.sr.ht/~rjarry/aerc/9
This commit is contained in:
Nguyễn Gia Phong 2022-01-20 01:10:08 +07:00 committed by Robin Jarry
parent beae17a6da
commit 904ffacb0e
7 changed files with 16 additions and 28 deletions
worker/lib

View file

@ -1,9 +1,9 @@
package lib
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -36,23 +36,17 @@ func TestMessageInfoHandledError(t *testing.T) {
}
type mockRawMessage struct {
body []byte
}
func newMockRawMessage(body []byte) *mockRawMessage {
return &mockRawMessage{
body: body,
}
path string
}
func newMockRawMessageFromPath(p string) *mockRawMessage {
b, err := ioutil.ReadFile(p)
die(err)
return newMockRawMessage(b)
return &mockRawMessage{
path: p,
}
}
func (m *mockRawMessage) NewReader() (io.Reader, error) {
return bytes.NewReader(m.body), nil
func (m *mockRawMessage) NewReader() (io.ReadCloser, error) {
return os.Open(m.path)
}
func (m *mockRawMessage) ModelFlags() ([]models.Flag, error) { return nil, nil }
func (m *mockRawMessage) Labels() ([]string, error) { return nil, nil }