chore: io/ioutil has been deprecated

This commit is contained in:
Christian Schwarz 2024-09-08 13:15:26 +00:00
parent 48c5b60024
commit 740ab4b1b2
9 changed files with 11 additions and 20 deletions

View File

@ -2,7 +2,6 @@ package config
import (
"fmt"
"io/ioutil"
"log/syslog"
"os"
"time"
@ -671,7 +670,7 @@ func ParseConfig(path string) (i *Config, err error) {
var bytes []byte
if bytes, err = ioutil.ReadFile(path); err != nil {
if bytes, err = os.ReadFile(path); err != nil {
return
}

View File

@ -5,7 +5,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
@ -64,7 +63,7 @@ func (o *FSOp) Run(ctx context.Context, e Execer) error {
if o.Encrypted {
const passphraseFilePath = "/tmp/zreplplatformtest.encryption.passphrase"
const passphrase = "foobar2342"
err := ioutil.WriteFile(passphraseFilePath, []byte(passphrase), 0600)
err := os.WriteFile(passphraseFilePath, []byte(passphrase), 0600)
if err != nil {
panic(err)
}

View File

@ -6,7 +6,6 @@ import (
"go/format"
"go/parser"
"go/token"
"io/ioutil"
"os"
"sort"
"strings"
@ -132,7 +131,7 @@ var Cases = []Case {
formatted, err := format.Source(buf.Bytes())
check(err)
err = ioutil.WriteFile("generated_cases.go", formatted, 0664)
err = os.WriteFile("generated_cases.go", formatted, 0664)
check(err)
}

View File

@ -3,7 +3,6 @@ package tests
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
@ -102,7 +101,7 @@ func SendStreamCloseAfterEOFRead(ctx *platformtest.Context) {
sendStream := sendStreamTest(ctx)
_, err := io.Copy(ioutil.Discard, sendStream)
_, err := io.Copy(io.Discard, sendStream)
require.NoError(ctx, err)
var buf [128]byte
@ -122,7 +121,7 @@ func SendStreamMultipleCloseAfterEOF(ctx *platformtest.Context) {
sendStream := sendStreamTest(ctx)
_, err := io.Copy(ioutil.Discard, sendStream)
_, err := io.Copy(io.Discard, sendStream)
require.NoError(ctx, err)
var buf [128]byte

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"sync"
"syscall"
@ -354,7 +353,7 @@ func (c *Conn) Shutdown(deadline time.Time) error {
// TODO DoS mitigation by reading limited number of bytes
// see discussion above why this is non-trivial
defer prometheus.NewTimer(prom.ShutdownDrainSeconds).ObserveDuration()
n, _ := io.Copy(ioutil.Discard, c.nc)
n, _ := io.Copy(io.Discard, c.nc)
prom.ShutdownDrainBytesRead.Observe(float64(n))
return closeWire("close")

View File

@ -5,7 +5,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"
"path"
@ -47,7 +46,7 @@ func main() {
flag.StringVar(&args.testCase, "testcase", "", "")
flag.Parse()
bytes, err := ioutil.ReadFile(args.configPath)
bytes, err := os.ReadFile(args.configPath)
noerror(err)
err = yaml.UnmarshalStrict(bytes, &conf)
noerror(err)

View File

@ -3,7 +3,6 @@ package main
import (
"bytes"
"io"
"io/ioutil"
"log"
"github.com/zrepl/zrepl/transport"
@ -83,7 +82,7 @@ func (CloseWrite) receiver(wire transport.Wire) {
// consume half the test data, then detect an error, send it and CloseWrite
r := io.LimitReader(wire, int64(5*len(closeWriteTestSendData)/3))
_, err := io.Copy(ioutil.Discard, r)
_, err := io.Copy(io.Discard, r)
noerror(err)
var errBuf bytes.Buffer
@ -95,7 +94,7 @@ func (CloseWrite) receiver(wire transport.Wire) {
noerror(err)
// drain wire, as documented in transport.Wire, this is the only way we know the client closed the conn
_, err = io.Copy(ioutil.Discard, wire)
_, err = io.Copy(io.Discard, wire)
if err != nil {
// io.Copy masks io.EOF to nil, and we expect io.EOF from the client's Close() call
log.Panicf("unexpected error returned from reading conn: %s", err)

View File

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"time"
@ -14,7 +13,7 @@ import (
func ParseCAFile(certfile string) (*x509.CertPool, error) {
pool := x509.NewCertPool()
pem, err := ioutil.ReadFile(certfile)
pem, err := os.ReadFile(certfile)
if err != nil {
return nil, err
}

View File

@ -3,7 +3,6 @@ package zfs
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@ -20,7 +19,7 @@ func getPipeCapacityHint(envvar string) int {
// https://github.com/zrepl/zrepl/issues/424#issuecomment-800370928
// https://bugzilla.kernel.org/show_bug.cgi?id=212295
if _, err := os.Stat("/proc/sys/fs/pipe-max-size"); err == nil {
if dat, err := ioutil.ReadFile("/proc/sys/fs/pipe-max-size"); err == nil {
if dat, err := os.ReadFile("/proc/sys/fs/pipe-max-size"); err == nil {
if capacity, err = strconv.ParseInt(strings.TrimSpace(string(dat)), 10, 64); err != nil {
capacity = 1 << 25
}