Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: update references to symbols moved from io/ioutil to io #42874

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions misc/android/go_android_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -276,7 +275,7 @@ func adbCopyGoroot() error {
if err := syscall.Flock(int(stat.Fd()), syscall.LOCK_EX); err != nil {
return err
}
s, err := ioutil.ReadAll(stat)
s, err := io.ReadAll(stat)
if err != nil {
return err
}
Expand All @@ -294,7 +293,7 @@ func adbCopyGoroot() error {
goroot := runtime.GOROOT()
// Build go for android.
goCmd := filepath.Join(goroot, "bin", "go")
tmpGo, err := ioutil.TempFile("", "go_android_exec-cmd-go-*")
tmpGo, err := os.CreateTemp("", "go_android_exec-cmd-go-*")
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions misc/cgo/errors/badsym_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package errorstest

import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestBadSymbol(t *testing.T) {

makeFile := func(mdir, base, source string) string {
ret := filepath.Join(mdir, base)
if err := ioutil.WriteFile(ret, []byte(source), 0644); err != nil {
if err := os.WriteFile(ret, []byte(source), 0644); err != nil {
t.Fatal(err)
}
return ret
Expand Down Expand Up @@ -100,7 +99,7 @@ func TestBadSymbol(t *testing.T) {
// _cgo_import.go.

rewrite := func(from, to string) {
obj, err := ioutil.ReadFile(from)
obj, err := os.ReadFile(from)
if err != nil {
t.Fatal(err)
}
Expand All @@ -115,7 +114,7 @@ func TestBadSymbol(t *testing.T) {

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

if err := ioutil.WriteFile(to, obj, 0644); err != nil {
if err := os.WriteFile(to, obj, 0644); err != nil {
t.Fatal(err)
}
}
Expand Down
5 changes: 2 additions & 3 deletions misc/cgo/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package errorstest
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -25,7 +24,7 @@ func check(t *testing.T, file string) {
t.Run(file, func(t *testing.T) {
t.Parallel()

contents, err := ioutil.ReadFile(path(file))
contents, err := os.ReadFile(path(file))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -56,7 +55,7 @@ func check(t *testing.T, file string) {
}

func expect(t *testing.T, file string, errors []*regexp.Regexp) {
dir, err := ioutil.TempDir("", filepath.Base(t.Name()))
dir, err := os.MkdirTemp("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 4 additions & 5 deletions misc/cgo/errors/ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -463,7 +462,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
gopath = *tmp
dir = ""
} else {
d, err := ioutil.TempDir("", filepath.Base(t.Name()))
d, err := os.MkdirTemp("", filepath.Base(t.Name()))
if err != nil {
t.Fatal(err)
}
Expand All @@ -475,7 +474,7 @@ func buildPtrTests(t *testing.T) (dir, exe string) {
if err := os.MkdirAll(src, 0777); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module ptrtest"), 0666); err != nil {
t.Fatal(err)
}

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

if err := ioutil.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
if err := os.WriteFile(filepath.Join(src, "cgo1.go"), cgo1.Bytes(), 0666); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
if err := os.WriteFile(filepath.Join(src, "cgo2.go"), cgo2.Bytes(), 0666); err != nil {
t.Fatal(err)
}

Expand Down
5 changes: 2 additions & 3 deletions misc/cgo/life/life_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package life_test

import (
"bytes"
"io/ioutil"
"log"
"os"
"os/exec"
Expand All @@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
}

func testMain(m *testing.M) int {
GOPATH, err := ioutil.TempDir("", "cgolife")
GOPATH, err := os.MkdirTemp("", "cgolife")
if err != nil {
log.Panic(err)
}
Expand All @@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := ioutil.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
if err := os.WriteFile("go.mod", []byte("module cgolife\n"), 0666); err != nil {
log.Panic(err)
}

Expand Down
5 changes: 2 additions & 3 deletions misc/cgo/stdio/stdio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package stdio_test

import (
"bytes"
"io/ioutil"
"log"
"os"
"os/exec"
Expand All @@ -21,7 +20,7 @@ func TestMain(m *testing.M) {
}

func testMain(m *testing.M) int {
GOPATH, err := ioutil.TempDir("", "cgostdio")
GOPATH, err := os.MkdirTemp("", "cgostdio")
if err != nil {
log.Panic(err)
}
Expand All @@ -38,7 +37,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := ioutil.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
if err := os.WriteFile("go.mod", []byte("module cgostdio\n"), 0666); err != nil {
log.Panic(err)
}

Expand Down
6 changes: 3 additions & 3 deletions misc/cgo/test/issue1435.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package cgotest

import (
"fmt"
"io/ioutil"
"os"
"strings"
"syscall"
"testing"
Expand Down Expand Up @@ -64,15 +64,15 @@ import "C"
func compareStatus(filter, expect string) error {
expected := filter + expect
pid := syscall.Getpid()
fs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
fs, err := os.ReadDir(fmt.Sprintf("/proc/%d/task", pid))
if err != nil {
return fmt.Errorf("unable to find %d tasks: %v", pid, err)
}
expectedProc := fmt.Sprintf("Pid:\t%d", pid)
foundAThread := false
for _, f := range fs {
tf := fmt.Sprintf("/proc/%s/status", f.Name())
d, err := ioutil.ReadFile(tf)
d, err := os.ReadFile(tf)
if err != nil {
// There are a surprising number of ways this
// can error out on linux. We've seen all of
Expand Down
5 changes: 2 additions & 3 deletions misc/cgo/test/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package cgotest

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -37,7 +36,7 @@ func TestCrossPackageTests(t *testing.T) {
}
}

GOPATH, err := ioutil.TempDir("", "cgotest")
GOPATH, err := os.MkdirTemp("", "cgotest")
if err != nil {
t.Fatal(err)
}
Expand All @@ -47,7 +46,7 @@ func TestCrossPackageTests(t *testing.T) {
if err := overlayDir(modRoot, "testdata"); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
if err := os.WriteFile(filepath.Join(modRoot, "go.mod"), []byte("module cgotest\n"), 0666); err != nil {
t.Fatal(err)
}

Expand Down
11 changes: 5 additions & 6 deletions misc/cgo/testcarchive/carchive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"debug/elf"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -53,7 +52,7 @@ func testMain(m *testing.M) int {
// We need a writable GOPATH in which to run the tests.
// Construct one in a temporary directory.
var err error
GOPATH, err = ioutil.TempDir("", "carchive_test")
GOPATH, err = os.MkdirTemp("", "carchive_test")
if err != nil {
log.Panic(err)
}
Expand All @@ -74,7 +73,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := ioutil.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
if err := os.WriteFile("go.mod", []byte("module testcarchive\n"), 0666); err != nil {
log.Panic(err)
}

Expand Down Expand Up @@ -176,7 +175,7 @@ func genHeader(t *testing.T, header, dir string) {
// The 'cgo' command generates a number of additional artifacts,
// but we're only interested in the header.
// Shunt the rest of the outputs to a temporary directory.
objDir, err := ioutil.TempDir(GOPATH, "_obj")
objDir, err := os.MkdirTemp(GOPATH, "_obj")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -252,7 +251,7 @@ var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)
// the user and make the files change based on details of the location
// of GOPATH.
func checkLineComments(t *testing.T, hdrname string) {
hdr, err := ioutil.ReadFile(hdrname)
hdr, err := os.ReadFile(hdrname)
if err != nil {
if !os.IsNotExist(err) {
t.Error(err)
Expand Down Expand Up @@ -618,7 +617,7 @@ func TestExtar(t *testing.T) {
t.Fatal(err)
}
s := strings.Replace(testar, "PWD", dir, 1)
if err := ioutil.WriteFile("testar", []byte(s), 0777); err != nil {
if err := os.WriteFile("testar", []byte(s), 0777); err != nil {
t.Fatal(err)
}

Expand Down
4 changes: 2 additions & 2 deletions misc/cgo/testcarchive/testdata/libgo6/sigprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
package main

import (
"io/ioutil"
"io"
"runtime/pprof"
)

import "C"

//export go_start_profile
func go_start_profile() {
pprof.StartCPUProfile(ioutil.Discard)
pprof.StartCPUProfile(io.Discard)
}

//export go_stop_profile
Expand Down
17 changes: 8 additions & 9 deletions misc/cgo/testcshared/cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -125,7 +124,7 @@ func testMain(m *testing.M) int {
// Copy testdata into GOPATH/src/testcshared, along with a go.mod file
// declaring the same path.

GOPATH, err := ioutil.TempDir("", "cshared_test")
GOPATH, err := os.MkdirTemp("", "cshared_test")
if err != nil {
log.Panic(err)
}
Expand All @@ -140,7 +139,7 @@ func testMain(m *testing.M) int {
log.Panic(err)
}
os.Setenv("PWD", modRoot)
if err := ioutil.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
if err := os.WriteFile("go.mod", []byte("module testcshared\n"), 0666); err != nil {
log.Panic(err)
}

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

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

// Test that installing a second time recreates the header file.
func TestCachedInstall(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "cshared")
tmpdir, err := os.MkdirTemp("", "cshared")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -719,14 +718,14 @@ func TestCachedInstall(t *testing.T) {
// copyFile copies src to dst.
func copyFile(t *testing.T, dst, src string) {
t.Helper()
data, err := ioutil.ReadFile(src)
data, err := os.ReadFile(src)
if err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(dst, data, 0666); err != nil {
if err := os.WriteFile(dst, data, 0666); err != nil {
t.Fatal(err)
}
}
Expand All @@ -743,7 +742,7 @@ func TestGo2C2Go(t *testing.T) {

t.Parallel()

tmpdir, err := ioutil.TempDir("", "cshared-TestGo2C2Go")
tmpdir, err := os.MkdirTemp("", "cshared-TestGo2C2Go")
if err != nil {
t.Fatal(err)
}
Expand Down
Loading