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

@@ -5,7 +5,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"github.com/restic/restic/internal/crypto"
@@ -171,7 +171,7 @@ func restoreAndVerify(t *testing.T, tempdir string, content []TestFile, files ma
func verifyRestore(t *testing.T, r *fileRestorer, repo *TestRepo) {
for _, file := range r.files {
target := r.targetPath(file.location)
data, err := ioutil.ReadFile(target)
data, err := os.ReadFile(target)
if err != nil {
t.Errorf("unable to read file %v: %v", file.location, err)
continue

View File

@@ -1,7 +1,7 @@
package restorer
import (
"io/ioutil"
"os"
"testing"
rtest "github.com/restic/restic/internal/test"
@@ -28,11 +28,11 @@ func TestFilesWriterBasic(t *testing.T) {
rtest.OK(t, w.writeToFile(f2, []byte{2}, 1, -1, false))
rtest.Equals(t, 0, len(w.buckets[0].files))
buf, err := ioutil.ReadFile(f1)
buf, err := os.ReadFile(f1)
rtest.OK(t, err)
rtest.Equals(t, []byte{1, 1}, buf)
buf, err = ioutil.ReadFile(f2)
buf, err = os.ReadFile(f2)
rtest.OK(t, err)
rtest.Equals(t, []byte{2, 2}, buf)
}

View File

@@ -3,7 +3,7 @@ package restorer
import (
"bytes"
"context"
"io/ioutil"
"io"
"math"
"os"
"path/filepath"
@@ -401,7 +401,7 @@ func TestRestorer(t *testing.T) {
}
for filename, content := range test.Files {
data, err := ioutil.ReadFile(filepath.Join(tempdir, filepath.FromSlash(filename)))
data, err := os.ReadFile(filepath.Join(tempdir, filepath.FromSlash(filename)))
if err != nil {
t.Errorf("unable to read file %v: %v", filename, err)
continue
@@ -477,7 +477,7 @@ func TestRestorerRelative(t *testing.T) {
}
for filename, content := range test.Files {
data, err := ioutil.ReadFile(filepath.Join(tempdir, "restore", filepath.FromSlash(filename)))
data, err := os.ReadFile(filepath.Join(tempdir, "restore", filepath.FromSlash(filename)))
if err != nil {
t.Errorf("unable to read file %v: %v", filename, err)
continue
@@ -825,7 +825,7 @@ func TestVerifyCancel(t *testing.T) {
defer cancel()
rtest.OK(t, res.RestoreTo(ctx, tempdir))
err := ioutil.WriteFile(filepath.Join(tempdir, "foo"), []byte("bar"), 0644)
err := os.WriteFile(filepath.Join(tempdir, "foo"), []byte("bar"), 0644)
rtest.OK(t, err)
var errs []error
@@ -850,7 +850,7 @@ func TestRestorerSparseFiles(t *testing.T) {
target := &fs.Reader{
Mode: 0600,
Name: "/zeros",
ReadCloser: ioutil.NopCloser(bytes.NewReader(zeros[:])),
ReadCloser: io.NopCloser(bytes.NewReader(zeros[:])),
}
sc := archiver.NewScanner(target)
err := sc.Scan(context.TODO(), []string{"/zeros"})
@@ -873,7 +873,7 @@ func TestRestorerSparseFiles(t *testing.T) {
rtest.OK(t, err)
filename := filepath.Join(tempdir, "zeros")
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
rtest.OK(t, err)
rtest.Equals(t, len(zeros[:]), len(content))