Skip to content

Commit a040ebe

Browse files
KimMachineGunianlancetaylor
authored andcommitted
all: update references to symbols moved from io/ioutil to io
Update references missed in CL 263142. For #41190 Change-Id: I778760a6a69bd0440fec0848bdef539c9ccb4ee1 GitHub-Last-Rev: dda42b0 GitHub-Pull-Request: #42874 Reviewed-on: https://go-review.googlesource.com/c/go/+/273946 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Cherry Zhang <cherryyz@google.com>
1 parent 9abedf4 commit a040ebe

37 files changed

+93
-119
lines changed

misc/android/go_android_exec.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"fmt"
1515
"go/build"
1616
"io"
17-
"io/ioutil"
1817
"log"
1918
"os"
2019
"os/exec"
@@ -276,7 +275,7 @@ func adbCopyGoroot() error {
276275
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
277276
return err
278277
}
279-
s, err := ioutil.ReadAll(stat)
278+
s, err := io.ReadAll(stat)
280279
if err != nil {
281280
return err
282281
}
@@ -294,7 +293,7 @@ func adbCopyGoroot() error {
294293
goroot := runtime.GOROOT()
295294
// Build go for android.
296295
goCmd := filepath.Join(goroot, "bin", "go")
297-
tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*")
296+
tmpGo, err := os.CreateTemp("", "go_android_exec-cmd-go-*")
298297
if err != nil {
299298
return err
300299
}

misc/cgo/errors/badsym_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package errorstest
66

77
import (
88
"bytes"
9-
"io/ioutil"
109
"os"
1110
"os/exec"
1211
"path/filepath"
@@ -55,7 +54,7 @@ func TestBadSymbol(t *testing.T) {
5554

5655
makeFile := func(mdir, base, source string) string {
5756
ret := filepath.Join(mdir, base)
58-
if err := ioutil.WriteFile(ret, []byte(source), 0644); err != nil {
57+
if err := os.WriteFile(ret, []byte(source), 0644); err != nil {
5958
t.Fatal(err)
6059
}
6160
return ret
@@ -100,7 +99,7 @@ func TestBadSymbol(t *testing.T) {
10099
// _cgo_import.go.
101100

102101
rewrite := func(from, to string) {
103-
obj, err := ioutil.ReadFile(from)
102+
obj, err := os.ReadFile(from)
104103
if err != nil {
105104
t.Fatal(err)
106105
}
@@ -115,7 +114,7 @@ func TestBadSymbol(t *testing.T) {
115114

116115
obj = bytes.ReplaceAll(obj, []byte(magicInput), []byte(magicReplace))
117116

118-
if err := ioutil.WriteFile(to, obj, 0644); err != nil {
117+
if err := os.WriteFile(to, obj, 0644); err != nil {
119118
t.Fatal(err)
120119
}
121120
}

misc/cgo/errors/errors_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package errorstest
77
import (
88
"bytes"
99
"fmt"
10-
"io/ioutil"
1110
"os"
1211
"os/exec"
1312
"path/filepath"
@@ -25,7 +24,7 @@ func check(t *testing.T, file string) {
2524
t.Run(file, func(t *testing.T) {
2625
t.Parallel()
2726

28-
contents, err := ioutil.ReadFile(path(file))
27+
contents, err := os.ReadFile(path(file))
2928
if err != nil {
3029
t.Fatal(err)
3130
}
@@ -56,7 +55,7 @@ func check(t *testing.T, file string) {
5655
}
5756

5857
func expect(t *testing.T, file string, errors []*regexp.Regexp) {
59-
dir, err := ioutil.TempDir("", filepath.Base(t.Name()))
58+
dir, err := os.MkdirTemp("", filepath.Base(t.Name()))
6059
if err != nil {
6160
t.Fatal(err)
6261
}

misc/cgo/errors/ptr_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"bytes"
1111
"flag"
1212
"fmt"
13-
"io/ioutil"
1413
"os"
1514
"os/exec"
1615
"path/filepath"
@@ -463,7 +462,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
463462
gopath = *tmp
464463
dir = ""
465464
} else {
466-
d, err := ioutil.TempDir("", filepath.Base(t.Name()))
465+
d, err := os.MkdirTemp("", filepath.Base(t.Name()))
467466
if err != nil {
468467
t.Fatal(err)
469468
}
@@ -475,7 +474,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
475474
if err := os.MkdirAll(src, 0777); err != nil {
476475
t.Fatal(err)
477476
}
478-
if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
477+
if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
479478
t.Fatal(err)
480479
}
481480

@@ -535,10 +534,10 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
535534
fmt.Fprintf(&cgo1, "}\n\n")
536535
fmt.Fprintf(&cgo1, "%s\n", ptrTestMain)
537536

538-
if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
537+
if err := os.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
539538
t.Fatal(err)
540539
}
541-
if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
540+
if err := os.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
542541
t.Fatal(err)
543542
}
544543

misc/cgo/life/life_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package life_test
66

77
import (
88
"bytes"
9-
"io/ioutil"
109
"log"
1110
"os"
1211
"os/exec"
@@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
2120
}
2221

2322
func testMain(m *testing.M) int {
24-
GOPATH, err := ioutil.TempDir("", "cgolife")
23+
GOPATH, err := os.MkdirTemp("", "cgolife")
2524
if err != nil {
2625
log.Panic(err)
2726
}
@@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
3837
log.Panic(err)
3938
}
4039
os.Setenv("PWD", modRoot)
41-
if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
40+
if err := os.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
4241
log.Panic(err)
4342
}
4443

misc/cgo/stdio/stdio_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package stdio_test
66

77
import (
88
"bytes"
9-
"io/ioutil"
109
"log"
1110
"os"
1211
"os/exec"
@@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
2120
}
2221

2322
func testMain(m *testing.M) int {
24-
GOPATH, err := ioutil.TempDir("", "cgostdio")
23+
GOPATH, err := os.MkdirTemp("", "cgostdio")
2524
if err != nil {
2625
log.Panic(err)
2726
}
@@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
3837
log.Panic(err)
3938
}
4039
os.Setenv("PWD", modRoot)
41-
if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
40+
if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
4241
log.Panic(err)
4342
}
4443

misc/cgo/test/issue1435.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package cgotest
88

99
import (
1010
"fmt"
11-
"io/ioutil"
11+
"os"
1212
"strings"
1313
"syscall"
1414
"testing"
@@ -64,15 +64,15 @@ import "C"
6464
func compareStatus(filter, expect string) error {
6565
expected := filter + expect
6666
pid := syscall.Getpid()
67-
fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
67+
fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
6868
if err != nil {
6969
return fmt.Errorf("unable to find %d tasks: %v", pid, err)
7070
}
7171
expectedProc := fmt.Sprintf("Pid:\t%d", pid)
7272
foundAThread := false
7373
for _, f := range fs {
7474
tf := fmt.Sprintf("/proc/%s/status", f.Name())
75-
d, err := ioutil.ReadFile(tf)
75+
d, err := os.ReadFile(tf)
7676
if err != nil {
7777
// There are a surprising number of ways this
7878
// can error out on linux. We've seen all of

misc/cgo/test/pkg_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package cgotest
66

77
import (
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"path/filepath"
@@ -37,7 +36,7 @@ func TestCrossPackageTests(t *testing.T) {
3736
}
3837
}
3938

40-
GOPATH, err := ioutil.TempDir("", "cgotest")
39+
GOPATH, err := os.MkdirTemp("", "cgotest")
4140
if err != nil {
4241
t.Fatal(err)
4342
}
@@ -47,7 +46,7 @@ func TestCrossPackageTests(t *testing.T) {
4746
if err := overlayDir(modRoot, "testdata"); err != nil {
4847
t.Fatal(err)
4948
}
50-
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
49+
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
5150
t.Fatal(err)
5251
}
5352

misc/cgo/testcarchive/carchive_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"debug/elf"
1111
"flag"
1212
"fmt"
13-
"io/ioutil"
1413
"log"
1514
"os"
1615
"os/exec"
@@ -53,7 +52,7 @@ func testMain(m *testing.M) int {
5352
// We need a writable GOPATH in which to run the tests.
5453
// Construct one in a temporary directory.
5554
var err error
56-
GOPATH, err = ioutil.TempDir("", "carchive_test")
55+
GOPATH, err = os.MkdirTemp("", "carchive_test")
5756
if err != nil {
5857
log.Panic(err)
5958
}
@@ -74,7 +73,7 @@ func testMain(m *testing.M) int {
7473
log.Panic(err)
7574
}
7675
os.Setenv("PWD", modRoot)
77-
if err := ioutil.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
76+
if err := os.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
7877
log.Panic(err)
7978
}
8079

@@ -176,7 +175,7 @@ func genHeader(t *testing.T, header, dir string) {
176175
// The 'cgo' command generates a number of additional artifacts,
177176
// but we're only interested in the header.
178177
// Shunt the rest of the outputs to a temporary directory.
179-
objDir, err := ioutil.TempDir(GOPATH, "_obj")
178+
objDir, err := os.MkdirTemp(GOPATH, "_obj")
180179
if err != nil {
181180
t.Fatal(err)
182181
}
@@ -252,7 +251,7 @@ var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)
252251
// the user and make the files change based on details of the location
253252
// of GOPATH.
254253
func checkLineComments(t *testing.T, hdrname string) {
255-
hdr, err := ioutil.ReadFile(hdrname)
254+
hdr, err := os.ReadFile(hdrname)
256255
if err != nil {
257256
if !os.IsNotExist(err) {
258257
t.Error(err)
@@ -618,7 +617,7 @@ func TestExtar(t *testing.T) {
618617
t.Fatal(err)
619618
}
620619
s := strings.Replace(testar, "PWD", dir, 1)
621-
if err := ioutil.WriteFile("testar", []byte(s), 0777); err != nil {
620+
if err := os.WriteFile("testar", []byte(s), 0777); err != nil {
622621
t.Fatal(err)
623622
}
624623

misc/cgo/testcarchive/testdata/libgo6/sigprof.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
package main
66

77
import (
8-
"io/ioutil"
8+
"io"
99
"runtime/pprof"
1010
)
1111

1212
import "C"
1313

1414
//export go_start_profile
1515
func go_start_profile() {
16-
pprof.StartCPUProfile(ioutil.Discard)
16+
pprof.StartCPUProfile(io.Discard)
1717
}
1818

1919
//export go_stop_profile

misc/cgo/testcshared/cshared_test.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"encoding/binary"
1212
"flag"
1313
"fmt"
14-
"io/ioutil"
1514
"log"
1615
"os"
1716
"os/exec"
@@ -125,7 +124,7 @@ func testMain(m *testing.M) int {
125124
// Copy testdata into GOPATH/src/testcshared, along with a go.mod file
126125
// declaring the same path.
127126

128-
GOPATH, err := ioutil.TempDir("", "cshared_test")
127+
GOPATH, err := os.MkdirTemp("", "cshared_test")
129128
if err != nil {
130129
log.Panic(err)
131130
}
@@ -140,7 +139,7 @@ func testMain(m *testing.M) int {
140139
log.Panic(err)
141140
}
142141
os.Setenv("PWD", modRoot)
143-
if err := ioutil.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
142+
if err := os.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
144143
log.Panic(err)
145144
}
146145

@@ -260,7 +259,7 @@ func createHeaders() error {
260259
// The 'cgo' command generates a number of additional artifacts,
261260
// but we're only interested in the header.
262261
// Shunt the rest of the outputs to a temporary directory.
263-
objDir, err := ioutil.TempDir("", "testcshared_obj")
262+
objDir, err := os.MkdirTemp("", "testcshared_obj")
264263
if err != nil {
265264
return err
266265
}
@@ -381,7 +380,7 @@ func main() {
381380

382381
srcfile := filepath.Join(tmpdir, "test.go")
383382
objfile := filepath.Join(tmpdir, "test.dll")
384-
if err := ioutil.WriteFile(srcfile, []byte(prog), 0666); err != nil {
383+
if err := os.WriteFile(srcfile, []byte(prog), 0666); err != nil {
385384
t.Fatal(err)
386385
}
387386
argv := []string{"build", "-buildmode=c-shared"}
@@ -643,7 +642,7 @@ func TestPIE(t *testing.T) {
643642

644643
// Test that installing a second time recreates the header file.
645644
func TestCachedInstall(t *testing.T) {
646-
tmpdir, err := ioutil.TempDir("", "cshared")
645+
tmpdir, err := os.MkdirTemp("", "cshared")
647646
if err != nil {
648647
t.Fatal(err)
649648
}
@@ -719,14 +718,14 @@ func TestCachedInstall(t *testing.T) {
719718
// copyFile copies src to dst.
720719
func copyFile(t *testing.T, dst, src string) {
721720
t.Helper()
722-
data, err := ioutil.ReadFile(src)
721+
data, err := os.ReadFile(src)
723722
if err != nil {
724723
t.Fatal(err)
725724
}
726725
if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
727726
t.Fatal(err)
728727
}
729-
if err := ioutil.WriteFile(dst, data, 0666); err != nil {
728+
if err := os.WriteFile(dst, data, 0666); err != nil {
730729
t.Fatal(err)
731730
}
732731
}
@@ -743,7 +742,7 @@ func TestGo2C2Go(t *testing.T) {
743742

744743
t.Parallel()
745744

746-
tmpdir, err := ioutil.TempDir("", "cshared-TestGo2C2Go")
745+
tmpdir, err := os.MkdirTemp("", "cshared-TestGo2C2Go")
747746
if err != nil {
748747
t.Fatal(err)
749748
}

0 commit comments

Comments
 (0)