go: removed io/ioutil

Since the minimum required version of Go has been bumped to 1.16, the
deprecation of io/ioutil can now be acted upon. This Commit removes the
remaining dependencies on ioutil and replaces them with their io or os
counterparts.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Moritz Poldrack 2022-08-17 16:19:45 +02:00 committed by Robin Jarry
parent 1b91b68e73
commit 9cffc45f03
20 changed files with 34 additions and 47 deletions

View file

@ -3,7 +3,7 @@ package account
import ( import (
"bytes" "bytes"
"errors" "errors"
"io/ioutil" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -89,7 +89,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
return nil, err return nil, err
} }
defer recoverFile.Close() defer recoverFile.Close()
data, err := ioutil.ReadAll(recoverFile) data, err := io.ReadAll(recoverFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"path" "path"
@ -124,7 +123,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
} }
if attachFull { if attachFull {
tmpDir, err := ioutil.TempDir("", "aerc-tmp-attachment") tmpDir, err := os.MkdirTemp("", "aerc-tmp-attachment")
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package msgview
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime" "mime"
"os" "os"
"time" "time"
@ -60,7 +59,7 @@ func (Open) Execute(aerc *widgets.Aerc, args []string) error {
} }
} }
tmpFile, err := ioutil.TempFile(os.TempDir(), "aerc-*"+extension) tmpFile, err := os.CreateTemp(os.TempDir(), "aerc-*"+extension)
if err != nil { if err != nil {
aerc.PushError(err.Error()) aerc.PushError(err.Error())
return return

View file

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime" "mime"
"net/mail" "net/mail"
"os/exec" "os/exec"
@ -100,7 +99,7 @@ func (c *Completer) completeAddress(s string) ([]string, string, error) {
completions, err := readCompletions(stdout) completions, err := readCompletions(stdout)
if err != nil { if err != nil {
buf, _ := ioutil.ReadAll(stderr) buf, _ := io.ReadAll(stderr)
msg := strings.TrimSpace(string(buf)) msg := strings.TrimSpace(string(buf))
if msg != "" { if msg != "" {
msg = ": " + msg msg = ": " + msg

View file

@ -3,7 +3,6 @@ package config
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/url" "net/url"
"os" "os"
@ -407,7 +406,7 @@ func installTemplate(root, name string) error {
} }
var data []byte var data []byte
for _, dir := range searchDirs { for _, dir := range searchDirs {
data, err = ioutil.ReadFile(path.Join(dir, name)) data, err = os.ReadFile(path.Join(dir, name))
if err == nil { if err == nil {
break break
} }
@ -415,7 +414,7 @@ func installTemplate(root, name string) error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(path.Join(root, name), data, 0o644) err = os.WriteFile(path.Join(root, name), data, 0o644)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package gpgbin
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
) )
@ -12,7 +11,7 @@ import (
// the signature is also verified // the signature is also verified
func Decrypt(r io.Reader) (*models.MessageDetails, error) { func Decrypt(r io.Reader) (*models.MessageDetails, error) {
md := new(models.MessageDetails) md := new(models.MessageDetails)
orig, err := ioutil.ReadAll(r) orig, err := io.ReadAll(r)
if err != nil { if err != nil {
return md, err return md, err
} }

View file

@ -3,7 +3,6 @@ package gpgbin
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"os" "os"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
@ -15,7 +14,7 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
args := []string{"--verify"} args := []string{"--verify"}
if s != nil { if s != nil {
// Detached sig, save the sig to a tmp file and send msg over stdin // Detached sig, save the sig to a tmp file and send msg over stdin
sig, err := ioutil.TempFile("", "sig") sig, err := os.CreateTemp("", "sig")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -24,7 +23,7 @@ func Verify(m io.Reader, s io.Reader) (*models.MessageDetails, error) {
defer os.Remove(sig.Name()) defer os.Remove(sig.Name())
args = append(args, sig.Name(), "-") args = append(args, sig.Name(), "-")
} }
orig, err := ioutil.ReadAll(m) orig, err := io.ReadAll(m)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -122,7 +121,7 @@ func (m *Mail) Decrypt(r io.Reader, decryptKeys openpgp.PromptFunction) (*models
if pgpReader.MessageDetails.IsSigned { if pgpReader.MessageDetails.IsSigned {
// we should consume the UnverifiedBody until EOF in order // we should consume the UnverifiedBody until EOF in order
// to get the correct signature data // to get the correct signature data
data, err := ioutil.ReadAll(pgpReader.MessageDetails.UnverifiedBody) data, err := io.ReadAll(pgpReader.MessageDetails.UnverifiedBody)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -3,7 +3,6 @@ package lib
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"github.com/ProtonMail/go-crypto/openpgp" "github.com/ProtonMail/go-crypto/openpgp"
"github.com/emersion/go-message" "github.com/emersion/go-message"
@ -77,7 +76,7 @@ func NewMessageStoreView(messageInfo *models.MessageInfo,
cb(nil, err) cb(nil, err)
return return
} }
msv.message, err = ioutil.ReadAll(md.Body) msv.message, err = io.ReadAll(md.Body)
if err != nil { if err != nil {
cb(nil, err) cb(nil, err)
return return

View file

@ -1,7 +1,7 @@
package parse_test package parse_test
import ( import (
"io/ioutil" "io"
"strings" "strings"
"testing" "testing"
@ -75,7 +75,7 @@ func TestHyperlinks(t *testing.T) {
// make sure reader is exact copy of input reader // make sure reader is exact copy of input reader
reader, links := parse.HttpLinks(strings.NewReader(test.text)) reader, links := parse.HttpLinks(strings.NewReader(test.text))
if data, err := ioutil.ReadAll(reader); err != nil { if data, err := io.ReadAll(reader); err != nil {
t.Errorf("could not read text: %v", err) t.Errorf("could not read text: %v", err)
} else if string(data) != test.text { } else if string(data) != test.text {
t.Errorf("did not copy input reader correctly") t.Errorf("did not copy input reader correctly")

View file

@ -2,7 +2,7 @@ package logging
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"os" "os"
) )
@ -24,7 +24,7 @@ func Init() {
func ErrorLogger() *log.Logger { func ErrorLogger() *log.Logger {
if err == nil { if err == nil {
return log.New(ioutil.Discard, "", log.LstdFlags) return log.New(io.Discard, "", log.LstdFlags)
} }
return err return err
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/textproto" "net/textproto"
"os" "os"
"os/exec" "os/exec"
@ -92,7 +91,7 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig,
logging.Errorf("could not complete header: %v", err) logging.Errorf("could not complete header: %v", err)
}) })
email, err := ioutil.TempFile("", "aerc-compose-*.eml") email, err := os.CreateTemp("", "aerc-compose-*.eml")
if err != nil { if err != nil {
// TODO: handle this better // TODO: handle this better
return nil, err return nil, err
@ -454,7 +453,7 @@ func (c *Composer) readSignatureFromFile() []byte {
if err != nil { if err != nil {
return nil return nil
} }
signature, err := ioutil.ReadFile(sigFile) signature, err := os.ReadFile(sigFile)
if err != nil { if err != nil {
c.aerc.PushError( c.aerc.PushError(
fmt.Sprintf(" Error loading signature from file: %v", sigFile)) fmt.Sprintf(" Error loading signature from file: %v", sigFile))

View file

@ -2,7 +2,6 @@ package lib
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -12,7 +11,7 @@ import (
func TestMessageInfoParser(t *testing.T) { func TestMessageInfoParser(t *testing.T) {
rootDir := "testdata/message/valid" rootDir := "testdata/message/valid"
msgFiles, err := ioutil.ReadDir(rootDir) msgFiles, err := os.ReadDir(rootDir)
die(err) die(err)
for _, fi := range msgFiles { for _, fi := range msgFiles {
@ -37,7 +36,7 @@ func TestMessageInfoParser(t *testing.T) {
func TestMessageInfoHandledError(t *testing.T) { func TestMessageInfoHandledError(t *testing.T) {
rootDir := "testdata/message/invalid" rootDir := "testdata/message/invalid"
msgFiles, err := ioutil.ReadDir(rootDir) msgFiles, err := os.ReadDir(rootDir)
die(err) die(err)
for _, fi := range msgFiles { for _, fi := range msgFiles {

View file

@ -1,7 +1,7 @@
package lib package lib
import ( import (
"io/ioutil" "io"
"net/textproto" "net/textproto"
"strings" "strings"
"unicode" "unicode"
@ -129,7 +129,7 @@ func searchMessage(message RawMessage, criteria *searchCriteria,
return false, err return false, err
} }
defer reader.Close() defer reader.Close()
bytes, err := ioutil.ReadAll(reader) bytes, err := io.ReadAll(reader)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -141,7 +141,7 @@ func searchMessage(message RawMessage, criteria *searchCriteria,
return false, err return false, err
} }
defer reader.Close() defer reader.Close()
bytes, err := ioutil.ReadAll(reader) bytes, err := io.ReadAll(reader)
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -1,7 +1,7 @@
package maildir package maildir
import ( import (
"io/ioutil" "io"
"net/textproto" "net/textproto"
"strings" "strings"
"unicode" "unicode"
@ -151,7 +151,7 @@ func (w *Worker) searchKey(key uint32, criteria *searchCriteria,
if err != nil { if err != nil {
return false, err return false, err
} }
bytes, err := ioutil.ReadAll(reader) bytes, err := io.ReadAll(reader)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -163,7 +163,7 @@ func (w *Worker) searchKey(key uint32, criteria *searchCriteria,
return false, err return false, err
} }
defer reader.Close() defer reader.Close()
bytes, err := ioutil.ReadAll(reader) bytes, err := io.ReadAll(reader)
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -543,7 +542,7 @@ func (w *Worker) handleFetchFullMessages(msg *types.FetchFullMessages) error {
return err return err
} }
defer r.Close() defer r.Close()
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }

View file

@ -3,7 +3,6 @@ package mboxer
import ( import (
"errors" "errors"
"io" "io"
"io/ioutil"
"time" "time"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
@ -23,7 +22,7 @@ func Read(r io.Reader) ([]lib.RawMessage, error) {
return nil, err return nil, err
} }
content, err := ioutil.ReadAll(msg) content, err := io.ReadAll(msg)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/lib" "git.sr.ht/~rjarry/aerc/worker/lib"
@ -150,7 +149,7 @@ func (f *container) newUid() (next uint32) {
} }
func (f *container) Append(r io.Reader, flags []models.Flag) error { func (f *container) Append(r io.Reader, flags []models.Flag) error {
data, err := ioutil.ReadAll(r) data, err := io.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }
@ -170,7 +169,7 @@ type message struct {
} }
func (m *message) NewReader() (io.ReadCloser, error) { func (m *message) NewReader() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(m.content)), nil return io.NopCloser(bytes.NewReader(m.content)), nil
} }
func (m *message) ModelFlags() ([]models.Flag, error) { func (m *message) ModelFlags() ([]models.Flag, error) {

View file

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -224,7 +224,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
continue continue
} }
defer r.Close() defer r.Close()
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
logging.Errorf("could not get message reader: %w", err) logging.Errorf("could not get message reader: %w", err)
continue continue

View file

@ -9,7 +9,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
@ -396,7 +396,7 @@ func (w *worker) handleFetchFullMessages(msg *types.FetchFullMessages) error {
return err return err
} }
defer r.Close() defer r.Close()
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return err return err
} }