mirror of
https://github.com/restic/restic.git
synced 2025-12-03 20:11:52 +00:00
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:
3
internal/cache/backend_test.go
vendored
3
internal/cache/backend_test.go
vendored
@@ -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")
|
||||
|
||||
5
internal/cache/cache.go
vendored
5
internal/cache/cache.go
vendored
@@ -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)
|
||||
}
|
||||
|
||||
3
internal/cache/file.go
vendored
3
internal/cache/file.go
vendored
@@ -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
|
||||
}
|
||||
|
||||
8
internal/cache/file_test.go
vendored
8
internal/cache/file_test.go
vendored
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user