Replace most usages of ioutil with the underlying function

The ioutil functions are deprecated since Go 1.17 and only wrap another
library function. Thus directly call the underlying function.

This commit only mechanically replaces the function calls.
This commit is contained in:
Michael Eischer
2022-12-02 19:36:43 +01:00
parent 2d5e28e777
commit ff7ef5007e
57 changed files with 119 additions and 159 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"math/rand"
"sync"
"testing"
@@ -203,7 +202,7 @@ func TestBackendRemoveBroken(t *testing.T) {
_ = rd.Close()
}()
test.OK(t, err)
cached, err := ioutil.ReadAll(rd)
cached, err := io.ReadAll(rd)
test.OK(t, err)
if !bytes.Equal(cached, data) {
t.Fatalf("wrong data cache")

View File

@@ -2,7 +2,6 @@ package cache
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@@ -26,7 +25,7 @@ const dirMode = 0700
const fileMode = 0644
func readVersion(dir string) (v uint, err error) {
buf, err := ioutil.ReadFile(filepath.Join(dir, "version"))
buf, err := os.ReadFile(filepath.Join(dir, "version"))
if errors.Is(err, os.ErrNotExist) {
return 0, nil
}
@@ -130,7 +129,7 @@ func New(id string, basedir string) (c *Cache, err error) {
}
if v < cacheVersion {
err = ioutil.WriteFile(filepath.Join(cachedir, "version"), []byte(fmt.Sprintf("%d", cacheVersion)), fileMode)
err = os.WriteFile(filepath.Join(cachedir, "version"), []byte(fmt.Sprintf("%d", cacheVersion)), fileMode)
if err != nil {
return nil, errors.WithStack(err)
}

View File

@@ -2,7 +2,6 @@ package cache
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -106,7 +105,7 @@ func (c *Cache) Save(h restic.Handle, rd io.Reader) error {
// First save to a temporary location. This allows multiple concurrent
// restics to use a single cache dir.
f, err := ioutil.TempFile(dir, "tmp-")
f, err := os.CreateTemp(dir, "tmp-")
if err != nil {
return err
}

View File

@@ -3,7 +3,7 @@ package cache
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"math/rand"
"os"
"runtime"
@@ -55,7 +55,7 @@ func load(t testing.TB, c *Cache, h restic.Handle) []byte {
t.Fatalf("load() returned nil reader")
}
buf, err := ioutil.ReadAll(rd)
buf, err := io.ReadAll(rd)
if err != nil {
t.Fatal(err)
}
@@ -174,7 +174,7 @@ func TestFileLoad(t *testing.T) {
t.Fatal(err)
}
buf, err := ioutil.ReadAll(rd)
buf, err := io.ReadAll(rd)
if err != nil {
t.Fatal(err)
}
@@ -258,7 +258,7 @@ func TestFileSaveConcurrent(t *testing.T) {
}
defer func() { _ = f.Close() }()
read, err := ioutil.ReadAll(f)
read, err := io.ReadAll(f)
if err == nil && !bytes.Equal(read, data) {
err = errors.New("mismatch between Save and Load")
}