all: Remove usage of deprecated io/ioutil (#7971)

As of Go 1.16 io/ioutil is deprecated. This replaces usage with the
corresponding functions in package os and package io.
This commit is contained in:
Jakob Borg
2021-11-22 08:59:47 +01:00
committed by GitHub
parent bf89bffb0b
commit 4b750b6dc3
71 changed files with 190 additions and 235 deletions
+1 -2
View File
@@ -7,7 +7,6 @@
package fs
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -21,7 +20,7 @@ import (
func setup(t *testing.T) (*BasicFilesystem, string) {
t.Helper()
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
+1 -2
View File
@@ -13,7 +13,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -530,7 +529,7 @@ func renameTestFile(name string, old string, new string) {
func modifyTestFile(name string, file string, content string) {
joined := filepath.Join(testDirAbs, name, file)
err := ioutil.WriteFile(joined, []byte(content), 0755)
err := os.WriteFile(joined, []byte(content), 0755)
if err != nil {
panic(fmt.Sprintf("Failed to modify test file %s: %s", joined, err))
}
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"fmt"
"hash/fnv"
"io"
"io/ioutil"
"math/rand"
"net/url"
"os"
@@ -787,7 +786,7 @@ func (f *fakeFile) readShortAt(p []byte, offs int64) (int, error) {
diff := offs - minOffs
if diff > 0 {
lr := io.LimitReader(f.rng, diff)
io.Copy(ioutil.Discard, lr)
io.Copy(io.Discard, lr)
}
f.offset = offs
+6 -7
View File
@@ -10,7 +10,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
@@ -88,7 +87,7 @@ func TestFakeFS(t *testing.T) {
}
// Read
bs0, err := ioutil.ReadAll(fd)
bs0, err := io.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
@@ -101,7 +100,7 @@ func TestFakeFS(t *testing.T) {
if err != nil {
t.Fatal(err)
}
bs1, err := ioutil.ReadAll(fd)
bs1, err := io.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
@@ -139,7 +138,7 @@ func testFakeFSRead(t *testing.T, fs Filesystem) {
// Read
fd.Seek(0, io.SeekStart)
bs0, err := ioutil.ReadAll(fd)
bs0, err := io.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
@@ -154,7 +153,7 @@ func testFakeFSRead(t *testing.T, fs Filesystem) {
if n != len(buf0) {
t.Fatal("short read")
}
buf1, err := ioutil.ReadAll(fd)
buf1, err := io.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
@@ -252,7 +251,7 @@ func TestFakeFSCaseInsensitive(t *testing.T) {
func createTestDir(t *testing.T) (string, bool) {
t.Helper()
testDir, err := ioutil.TempDir("", "")
testDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("could not create temporary dir for testing: %s", err)
}
@@ -328,7 +327,7 @@ func testFakeFSCaseInsensitive(t *testing.T, fs Filesystem) {
t.Fatal(err)
}
bs2, err := ioutil.ReadAll(fd2)
bs2, err := io.ReadAll(fd2)
if err != nil {
t.Fatal(err)
}
+2 -3
View File
@@ -9,7 +9,6 @@ package fs
import (
"bytes"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@@ -257,7 +256,7 @@ func TestCopyRange(tttt *testing.T) {
paths = []string{""}
}
for _, path := range paths {
testPath, err := ioutil.TempDir(path, "")
testPath, err := os.MkdirTemp(path, "")
if err != nil {
tttt.Fatal(err)
}
@@ -273,7 +272,7 @@ func TestCopyRange(tttt *testing.T) {
tt.Run(testCase.name, func(t *testing.T) {
srcBuf := make([]byte, testCase.srcSize)
dstBuf := make([]byte, testCase.dstSize)
td, err := ioutil.TempDir(testPath, "")
td, err := os.MkdirTemp(testPath, "")
if err != nil {
t.Fatal(err)
}
+8 -9
View File
@@ -8,7 +8,6 @@ package fs
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -20,9 +19,9 @@ func TestMtimeFS(t *testing.T) {
os.RemoveAll("testdata")
defer os.RemoveAll("testdata")
os.Mkdir("testdata", 0755)
ioutil.WriteFile("testdata/exists0", []byte("hello"), 0644)
ioutil.WriteFile("testdata/exists1", []byte("hello"), 0644)
ioutil.WriteFile("testdata/exists2", []byte("hello"), 0644)
os.WriteFile("testdata/exists0", []byte("hello"), 0644)
os.WriteFile("testdata/exists1", []byte("hello"), 0644)
os.WriteFile("testdata/exists2", []byte("hello"), 0644)
// a random time with nanosecond precision
testTime := time.Unix(1234567890, 123456789)
@@ -83,7 +82,7 @@ func TestMtimeFS(t *testing.T) {
}
func TestMtimeFSWalk(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -93,7 +92,7 @@ func TestMtimeFSWalk(t *testing.T) {
mtimefs := newMtimeFS(underlying, make(mapStore))
mtimefs.chtimes = failChtimes
if err := ioutil.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
t.Fatal(err)
}
@@ -137,7 +136,7 @@ func TestMtimeFSWalk(t *testing.T) {
}
func TestMtimeFSOpen(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -147,7 +146,7 @@ func TestMtimeFSOpen(t *testing.T) {
mtimefs := newMtimeFS(underlying, make(mapStore))
mtimefs.chtimes = failChtimes
if err := ioutil.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
t.Fatal(err)
}
@@ -200,7 +199,7 @@ func TestMtimeFSInsensitive(t *testing.T) {
os.RemoveAll("testdata")
defer os.RemoveAll("testdata")
os.Mkdir("testdata", 0755)
ioutil.WriteFile("testdata/FiLe", []byte("hello"), 0644)
os.WriteFile("testdata/FiLe", []byte("hello"), 0644)
// a random time with nanosecond precision
testTime := time.Unix(1234567890, 123456789)