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/cmd/gofmt | |
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/cmd/gofmt')
-rw-r--r-- | src/cmd/gofmt/gofmt.go | 5 | ||||
-rw-r--r-- | src/cmd/gofmt/gofmt_test.go | 13 |
2 files changed, 8 insertions, 10 deletions
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index 719c681a3e..2793c2c2a4 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -15,7 +15,6 @@ import ( "go/token" "io" "io/fs" - "io/ioutil" "os" "path/filepath" "runtime" @@ -137,7 +136,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error if err != nil { return err } - err = ioutil.WriteFile(filename, res, perm) + err = os.WriteFile(filename, res, perm) if err != nil { os.Rename(bakname, filename) return err @@ -278,7 +277,7 @@ const chmodSupported = runtime.GOOS != "windows" // the chosen file name. func backupFile(filename string, data []byte, perm fs.FileMode) (string, error) { // create backup file - f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename)) + f, err := os.CreateTemp(filepath.Dir(filename), filepath.Base(filename)) if err != nil { return "", err } diff --git a/src/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go index 98d3eb7eb2..bf2adfe64c 100644 --- a/src/cmd/gofmt/gofmt_test.go +++ b/src/cmd/gofmt/gofmt_test.go @@ -7,7 +7,6 @@ package main import ( "bytes" "flag" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -93,7 +92,7 @@ func runTest(t *testing.T, in, out string) { return } - expected, err := ioutil.ReadFile(out) + expected, err := os.ReadFile(out) if err != nil { t.Error(err) return @@ -102,7 +101,7 @@ func runTest(t *testing.T, in, out string) { if got := buf.Bytes(); !bytes.Equal(got, expected) { if *update { if in != out { - if err := ioutil.WriteFile(out, got, 0666); err != nil { + if err := os.WriteFile(out, got, 0666); err != nil { t.Error(err) } return @@ -116,7 +115,7 @@ func runTest(t *testing.T, in, out string) { if err == nil { t.Errorf("%s", d) } - if err := ioutil.WriteFile(in+".gofmt", got, 0666); err != nil { + if err := os.WriteFile(in+".gofmt", got, 0666); err != nil { t.Error(err) } } @@ -157,7 +156,7 @@ func TestCRLF(t *testing.T) { const input = "testdata/crlf.input" // must contain CR/LF's const golden = "testdata/crlf.golden" // must not contain any CR's - data, err := ioutil.ReadFile(input) + data, err := os.ReadFile(input) if err != nil { t.Error(err) } @@ -165,7 +164,7 @@ func TestCRLF(t *testing.T) { t.Errorf("%s contains no CR/LF's", input) } - data, err = ioutil.ReadFile(golden) + data, err = os.ReadFile(golden) if err != nil { t.Error(err) } @@ -175,7 +174,7 @@ func TestCRLF(t *testing.T) { } func TestBackupFile(t *testing.T) { - dir, err := ioutil.TempDir("", "gofmt_test") + dir, err := os.MkdirTemp("", "gofmt_test") if err != nil { t.Fatal(err) } |