diff options
author | Russ Cox <rsc@golang.org> | 2020-10-29 14:17:47 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2020-12-09 19:12:23 +0000 |
commit | 4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493 (patch) | |
tree | c186cc25257b05fcb21cd8c1f1ee5961ebef6eb3 /src/crypto | |
parent | 5627a4dc3013fed02c4b8097413643b682cac276 (diff) | |
download | go-4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493.tar.gz go-4f1b0a44cb46f3df28f5ef82e5769ebeac1bc493.zip |
all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTemp
As part of #42026, these helpers from io/ioutil were moved to os.
(ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.)
Update the Go tree to use the preferred names.
As usual, code compiled with the Go 1.4 bootstrap toolchain
and code vendored from other sources is excluded.
ReadDir changes are in a separate CL, because they are not a
simple search and replace.
For #42026.
Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/266365
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/md5/gen.go | 4 | ||||
-rw-r--r-- | src/crypto/tls/handshake_test.go | 3 | ||||
-rw-r--r-- | src/crypto/tls/link_test.go | 3 | ||||
-rw-r--r-- | src/crypto/tls/tls.go | 6 | ||||
-rw-r--r-- | src/crypto/x509/name_constraints_test.go | 3 | ||||
-rw-r--r-- | src/crypto/x509/root_ios_gen.go | 4 | ||||
-rw-r--r-- | src/crypto/x509/root_plan9.go | 3 | ||||
-rw-r--r-- | src/crypto/x509/root_unix.go | 4 | ||||
-rw-r--r-- | src/crypto/x509/root_unix_test.go | 5 |
9 files changed, 15 insertions, 20 deletions
diff --git a/src/crypto/md5/gen.go b/src/crypto/md5/gen.go index a11f22059f..1468924cbc 100644 --- a/src/crypto/md5/gen.go +++ b/src/crypto/md5/gen.go @@ -15,8 +15,8 @@ import ( "bytes" "flag" "go/format" - "io/ioutil" "log" + "os" "strings" "text/template" ) @@ -37,7 +37,7 @@ func main() { if err != nil { log.Fatal(err) } - err = ioutil.WriteFile(*filename, data, 0644) + err = os.WriteFile(*filename, data, 0644) if err != nil { log.Fatal(err) } diff --git a/src/crypto/tls/handshake_test.go b/src/crypto/tls/handshake_test.go index 605be587b5..d9ff9fe948 100644 --- a/src/crypto/tls/handshake_test.go +++ b/src/crypto/tls/handshake_test.go @@ -13,7 +13,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net" "os" "os/exec" @@ -224,7 +223,7 @@ func parseTestData(r io.Reader) (flows [][]byte, err error) { // tempFile creates a temp file containing contents and returns its path. func tempFile(contents string) string { - file, err := ioutil.TempFile("", "go-tls-test") + file, err := os.CreateTemp("", "go-tls-test") if err != nil { panic("failed to create temp file: " + err.Error()) } diff --git a/src/crypto/tls/link_test.go b/src/crypto/tls/link_test.go index 8224216b5c..8c392ff7c4 100644 --- a/src/crypto/tls/link_test.go +++ b/src/crypto/tls/link_test.go @@ -7,7 +7,6 @@ package tls import ( "bytes" "internal/testenv" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -77,7 +76,7 @@ func main() { tls.Dial("", "", nil) } exeFile := filepath.Join(tmpDir, "x.exe") for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := ioutil.WriteFile(goFile, []byte(tt.program), 0644); err != nil { + if err := os.WriteFile(goFile, []byte(tt.program), 0644); err != nil { t.Fatal(err) } os.Remove(exeFile) diff --git a/src/crypto/tls/tls.go b/src/crypto/tls/tls.go index bf577cadea..19884f96e7 100644 --- a/src/crypto/tls/tls.go +++ b/src/crypto/tls/tls.go @@ -22,8 +22,8 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" "net" + "os" "strings" ) @@ -222,11 +222,11 @@ func (d *Dialer) DialContext(ctx context.Context, network, addr string) (net.Con // form a certificate chain. On successful return, Certificate.Leaf will // be nil because the parsed form of the certificate is not retained. func LoadX509KeyPair(certFile, keyFile string) (Certificate, error) { - certPEMBlock, err := ioutil.ReadFile(certFile) + certPEMBlock, err := os.ReadFile(certFile) if err != nil { return Certificate{}, err } - keyPEMBlock, err := ioutil.ReadFile(keyFile) + keyPEMBlock, err := os.ReadFile(keyFile) if err != nil { return Certificate{}, err } diff --git a/src/crypto/x509/name_constraints_test.go b/src/crypto/x509/name_constraints_test.go index 34055d07b5..3826c82c38 100644 --- a/src/crypto/x509/name_constraints_test.go +++ b/src/crypto/x509/name_constraints_test.go @@ -14,7 +14,6 @@ import ( "encoding/hex" "encoding/pem" "fmt" - "io/ioutil" "math/big" "net" "net/url" @@ -2005,7 +2004,7 @@ func TestConstraintCases(t *testing.T) { } func writePEMsToTempFile(certs []*Certificate) *os.File { - file, err := ioutil.TempFile("", "name_constraints_test") + file, err := os.CreateTemp("", "name_constraints_test") if err != nil { panic("cannot create tempfile") } diff --git a/src/crypto/x509/root_ios_gen.go b/src/crypto/x509/root_ios_gen.go index 2bcdab1a77..8bc6e7d9c4 100644 --- a/src/crypto/x509/root_ios_gen.go +++ b/src/crypto/x509/root_ios_gen.go @@ -27,9 +27,9 @@ import ( "fmt" "go/format" "io" - "io/ioutil" "log" "net/http" + "os" "path" "sort" "strings" @@ -155,7 +155,7 @@ func main() { if err != nil { log.Fatal(err) } - if err := ioutil.WriteFile(*output, source, 0644); err != nil { + if err := os.WriteFile(*output, source, 0644); err != nil { log.Fatal(err) } } diff --git a/src/crypto/x509/root_plan9.go b/src/crypto/x509/root_plan9.go index 09f0e23033..2dc4aaf5d7 100644 --- a/src/crypto/x509/root_plan9.go +++ b/src/crypto/x509/root_plan9.go @@ -7,7 +7,6 @@ package x509 import ( - "io/ioutil" "os" ) @@ -24,7 +23,7 @@ func loadSystemRoots() (*CertPool, error) { roots := NewCertPool() var bestErr error for _, file := range certFiles { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err == nil { roots.AppendCertsFromPEM(data) return roots, nil diff --git a/src/crypto/x509/root_unix.go b/src/crypto/x509/root_unix.go index 1090b69f83..3c643466ed 100644 --- a/src/crypto/x509/root_unix.go +++ b/src/crypto/x509/root_unix.go @@ -40,7 +40,7 @@ func loadSystemRoots() (*CertPool, error) { var firstErr error for _, file := range files { - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if err == nil { roots.AppendCertsFromPEM(data) break @@ -68,7 +68,7 @@ func loadSystemRoots() (*CertPool, error) { continue } for _, fi := range fis { - data, err := ioutil.ReadFile(directory + "/" + fi.Name()) + data, err := os.ReadFile(directory + "/" + fi.Name()) if err == nil { roots.AppendCertsFromPEM(data) } diff --git a/src/crypto/x509/root_unix_test.go b/src/crypto/x509/root_unix_test.go index b2e832ff36..878ed7c2fa 100644 --- a/src/crypto/x509/root_unix_test.go +++ b/src/crypto/x509/root_unix_test.go @@ -9,7 +9,6 @@ package x509 import ( "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -147,7 +146,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) { os.Setenv(certFileEnv, origFile) }() - tmpDir, err := ioutil.TempDir(os.TempDir(), "x509-issue35325") + tmpDir, err := os.MkdirTemp(os.TempDir(), "x509-issue35325") if err != nil { t.Fatalf("Failed to create temporary directory: %v", err) } @@ -166,7 +165,7 @@ func TestLoadSystemCertsLoadColonSeparatedDirs(t *testing.T) { t.Fatalf("Failed to create certificate dir: %v", err) } certOutFile := filepath.Join(certDir, "cert.crt") - if err := ioutil.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil { + if err := os.WriteFile(certOutFile, []byte(certPEM), 0655); err != nil { t.Fatalf("Failed to write certificate to file: %v", err) } certDirs = append(certDirs, certDir) |