Handle ioutil deprecations (#53526)

* replace ioutil.ReadFile -> os.ReadFile

* replace ioutil.ReadAll -> io.ReadAll

* replace ioutil.TempFile -> os.CreateTemp

* replace ioutil.NopCloser -> io.NopCloser

* replace ioutil.WriteFile -> os.WriteFile

* replace ioutil.TempDir -> os.MkdirTemp

* replace ioutil.Discard -> io.Discard
This commit is contained in:
Jo
2022-08-10 15:37:51 +02:00
committed by GitHub
parent 4926767737
commit 062d255124
140 changed files with 462 additions and 492 deletions
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@@ -142,7 +141,7 @@ func sendRequestGetBytes(client http.Client, repoUrl string, subPaths ...string)
logger.Warn("Failed to close stream", "err", err)
}
}()
return ioutil.ReadAll(bodyReader)
return io.ReadAll(bodyReader)
}
func sendRequest(client http.Client, repoUrl string, subPaths ...string) (io.ReadCloser, error) {
@@ -191,7 +190,7 @@ func handleResponse(res *http.Response) (io.ReadCloser, error) {
}
if res.StatusCode/100 == 4 {
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
defer func() {
if err := res.Body.Close(); err != nil {
logger.Warn("Failed to close response body", "err", err)
@@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"net/http"
"testing"
@@ -19,7 +18,7 @@ func TestHandleResponse(t *testing.T) {
resp := makeResponse(t, 200, "test")
bodyReader, err := handleResponse(resp)
require.NoError(t, err)
body, err := ioutil.ReadAll(bodyReader)
body, err := io.ReadAll(bodyReader)
require.NoError(t, err)
assert.Equal(t, "test", string(body))
})
@@ -81,7 +80,7 @@ func makeResponse(t *testing.T, status int, body string) *http.Response {
func makeBody(t *testing.T, body string) io.ReadCloser {
t.Helper()
reader := ioutil.NopCloser(bytes.NewReader([]byte(body)))
reader := io.NopCloser(bytes.NewReader([]byte(body)))
t.Cleanup(func() {
err := reader.Close()
assert.NoError(t, err)
+1 -1
View File
@@ -25,5 +25,5 @@ func (i IoUtilImp) ReadFile(filename string) ([]byte, error) {
// from command line flag "pluginsDir". If the user shouldn't be reading from this directory, they shouldn't have
// the permission in the file system.
// nolint:gosec
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
}