mirror of
https://github.com/restic/restic.git
synced 2025-10-09 13:49:58 +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:
@@ -4,7 +4,6 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
@@ -18,7 +17,7 @@ func fixpath(name string) string {
|
||||
// TempFile creates a temporary file which has already been deleted (on
|
||||
// supported platforms)
|
||||
func TempFile(dir, prefix string) (f *os.File, err error) {
|
||||
f, err = ioutil.TempFile(dir, prefix)
|
||||
f, err = os.CreateTemp(dir, prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ func fixpath(name string) string {
|
||||
|
||||
// TempFile creates a temporary file which is marked as delete-on-close
|
||||
func TempFile(dir, prefix string) (f *os.File, err error) {
|
||||
// slightly modified implementation of ioutil.TempFile(dir, prefix) to allow us to add
|
||||
// slightly modified implementation of os.CreateTemp(dir, prefix) to allow us to add
|
||||
// the FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE flags.
|
||||
// These provide two large benefits:
|
||||
// FILE_ATTRIBUTE_TEMPORARY tells Windows to keep the file in memory only if possible
|
||||
|
@@ -2,7 +2,7 @@ package fs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
@@ -20,7 +20,7 @@ func verifyFileContentOpen(t testing.TB, fs FS, filename string, want []byte) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(f)
|
||||
buf, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func verifyFileContentOpenFile(t testing.TB, fs FS, filename string, want []byte
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(f)
|
||||
buf, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func TestFSReader(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
fs := &Reader{
|
||||
Name: filename,
|
||||
ReadCloser: ioutil.NopCloser(bytes.NewReader(data)),
|
||||
ReadCloser: io.NopCloser(bytes.NewReader(data)),
|
||||
|
||||
Mode: 0644,
|
||||
Size: int64(len(data)),
|
||||
@@ -355,7 +355,7 @@ func TestFSReaderDir(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
fs := &Reader{
|
||||
Name: test.filename,
|
||||
ReadCloser: ioutil.NopCloser(bytes.NewReader(data)),
|
||||
ReadCloser: io.NopCloser(bytes.NewReader(data)),
|
||||
|
||||
Mode: 0644,
|
||||
Size: int64(len(data)),
|
||||
@@ -410,7 +410,7 @@ func TestFSReaderMinFileSize(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
fs := &Reader{
|
||||
Name: "testfile",
|
||||
ReadCloser: ioutil.NopCloser(strings.NewReader(test.data)),
|
||||
ReadCloser: io.NopCloser(strings.NewReader(test.data)),
|
||||
Mode: 0644,
|
||||
ModTime: time.Now(),
|
||||
AllowEmptyFile: test.allowEmpty,
|
||||
@@ -421,7 +421,7 @@ func TestFSReaderMinFileSize(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(f)
|
||||
buf, err := io.ReadAll(f)
|
||||
if test.readMustErr {
|
||||
if err == nil {
|
||||
t.Fatal("expected error not found, got nil")
|
||||
|
@@ -2,7 +2,6 @@ package fs
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNoatime(t *testing.T) {
|
||||
f, err := ioutil.TempFile("", "restic-test-noatime")
|
||||
f, err := os.CreateTemp("", "restic-test-noatime")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestExtendedStat(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
filename := filepath.Join(tempdir, "file")
|
||||
err := ioutil.WriteFile(filename, []byte("foobar"), 0640)
|
||||
err := os.WriteFile(filename, []byte("foobar"), 0640)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user