Merge pull request #7203 from jeffwidman/drop-deprecated-ioutil

Drop deprecated `ioutil`
This commit is contained in:
Akihiro Suda 2022-07-24 03:18:04 +09:00 committed by GitHub
commit db3ecb286b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 17 deletions

View File

@ -18,7 +18,7 @@ package compression
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"testing" "testing"
@ -31,7 +31,7 @@ func BenchmarkDecompression(b *testing.B) {
resp, err := http.Get(benchmarkTestDataURL) resp, err := http.Get(benchmarkTestDataURL)
require.NoError(b, err) require.NoError(b, err)
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
require.NoError(b, err) require.NoError(b, err)
resp.Body.Close() resp.Body.Close()

View File

@ -19,7 +19,6 @@ package client
import ( import (
"archive/tar" "archive/tar"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -46,7 +45,7 @@ func TestExport(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
dstFile, err := ioutil.TempFile("", "export-import-test") dstFile, err := os.CreateTemp("", "export-import-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -21,7 +21,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"os" "os"
"math/rand" "math/rand"
@ -76,7 +75,7 @@ func testExportImport(t *testing.T, imageName string) {
t.Fatal(err) t.Fatal(err)
} }
dstFile, err := ioutil.TempFile("", "export-import-test") dstFile, err := os.CreateTemp("", "export-import-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -22,7 +22,7 @@ package integration
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"os" "os"
"os/exec" "os/exec"
@ -75,7 +75,7 @@ func TestSandboxRemoveWithoutIPLeakage(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer f.Close() defer f.Close()
data, err := ioutil.ReadAll(f) data, err := io.ReadAll(f)
require.NoError(t, err) require.NoError(t, err)
var jsonData map[string]interface{} var jsonData map[string]interface{}

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -1524,14 +1523,14 @@ func writeFilesToTempDir(tmpDirPattern string, content []string) (string, error)
return "", nil return "", nil
} }
dir, err := ioutil.TempDir("", tmpDirPattern) dir, err := os.MkdirTemp("", tmpDirPattern)
if err != nil { if err != nil {
return "", err return "", err
} }
for idx, data := range content { for idx, data := range content {
file := filepath.Join(dir, fmt.Sprintf("spec-%d.yaml", idx)) file := filepath.Join(dir, fmt.Sprintf("spec-%d.yaml", idx))
err := ioutil.WriteFile(file, []byte(data), 0644) err := os.WriteFile(file, []byte(data), 0644)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -1524,14 +1523,14 @@ func writeFilesToTempDir(tmpDirPattern string, content []string) (string, error)
return "", nil return "", nil
} }
dir, err := ioutil.TempDir("", tmpDirPattern) dir, err := os.MkdirTemp("", tmpDirPattern)
if err != nil { if err != nil {
return "", err return "", err
} }
for idx, data := range content { for idx, data := range content {
file := filepath.Join(dir, fmt.Sprintf("spec-%d.yaml", idx)) file := filepath.Join(dir, fmt.Sprintf("spec-%d.yaml", idx))
err := ioutil.WriteFile(file, []byte(data), 0644) err := os.WriteFile(file, []byte(data), 0644)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -20,7 +20,6 @@
package config package config
import ( import (
"io/ioutil"
"os" "os"
fuzz "github.com/AdaLogics/go-fuzz-headers" fuzz "github.com/AdaLogics/go-fuzz-headers"
@ -28,7 +27,7 @@ import (
func FuzzParseHostsFile(data []byte) int { func FuzzParseHostsFile(data []byte) int {
f := fuzz.NewConsumer(data) f := fuzz.NewConsumer(data)
dir, err := ioutil.TempDir("", "fuzz-") dir, err := os.MkdirTemp("", "fuzz-")
if err != nil { if err != nil {
return 0 return 0
} }

View File

@ -456,7 +456,7 @@ func (s *snapshotter) openOrCreateScratch(ctx context.Context, sizeGB int, scrat
log.G(ctx).Debugf("vhdx %s not found, creating a new one", vhdFileName) log.G(ctx).Debugf("vhdx %s not found, creating a new one", vhdFileName)
// Golang logic for ioutil.TempFile without the file creation // Golang logic for os.CreateTemp without the file creation
r := uint32(time.Now().UnixNano() + int64(os.Getpid())) r := uint32(time.Now().UnixNano() + int64(os.Getpid()))
r = r*1664525 + 1013904223 // constants from Numerical Recipes r = r*1664525 + 1013904223 // constants from Numerical Recipes