Skip to content

Commit

Permalink
all: replace package ioutil with os and io in src
Browse files Browse the repository at this point in the history
For #45557

Change-Id: I56824135d86452603dd4ed4bab0e24c201bb0683
Reviewed-on: https://go-review.googlesource.com/c/go/+/426257
Run-TryBot: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Run-TryBot: Andy Pan <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
panjf2000 authored and gopherbot committed Sep 20, 2022
1 parent 1e7e160 commit f8c659b
Show file tree
Hide file tree
Showing 67 changed files with 252 additions and 287 deletions.
5 changes: 2 additions & 3 deletions src/cmd/asm/internal/asm/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"fmt"
"internal/buildcfg"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -51,7 +50,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
output := strings.Split(testOut.String(), "\n")

// Reconstruct expected output by independently "parsing" the input.
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -324,7 +323,7 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
}

// Reconstruct expected errors by independently "parsing" the input.
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
t.Error(err)
return
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/cgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go/token"
"internal/buildcfg"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -345,7 +344,7 @@ func main() {
input = aname
}

b, err := ioutil.ReadFile(input)
b, err := os.ReadFile(input)
if err != nil {
fatalf("%s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/cgo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"go/token"
"io/ioutil"
"os"
"os/exec"
)
Expand All @@ -21,13 +20,13 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
// Some compilers have trouble with standard input.
// Others have trouble with -xc.
// Avoid both problems by writing a file with a .c extension.
f, err := ioutil.TempFile("", "cgo-gcc-input-")
f, err := os.CreateTemp("", "cgo-gcc-input-")
if err != nil {
fatalf("%s", err)
}
name := f.Name()
f.Close()
if err := ioutil.WriteFile(name+".c", stdin, 0666); err != nil {
if err := os.WriteFile(name+".c", stdin, 0666); err != nil {
os.Remove(name)
fatalf("%s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"flag"
"fmt"
"internal/buildcfg"
"io/ioutil"
"log"
"os"
"reflect"
Expand Down Expand Up @@ -392,7 +391,7 @@ func readImportCfg(file string) {
Flag.Cfg.ImportMap = make(map[string]string)
}
Flag.Cfg.PackageFile = map[string]string{}
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
log.Fatalf("-importcfg: %v", err)
}
Expand Down Expand Up @@ -432,7 +431,7 @@ func readImportCfg(file string) {
}

func readEmbedCfg(file string) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
log.Fatalf("-embedcfg: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/dwarfgen/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"debug/dwarf"
"fmt"
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -221,7 +220,7 @@ func TestScopeRanges(t *testing.T) {
t.Skip("skipping on plan9; no DWARF symbol table in executables")
}

dir, err := ioutil.TempDir("", "TestScopeRanges")
dir, err := os.MkdirTemp("", "TestScopeRanges")
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
Expand Down Expand Up @@ -498,7 +497,7 @@ func TestEmptyDwarfRanges(t *testing.T) {
t.Skip("skipping on plan9; no DWARF symbol table in executables")
}

dir, err := ioutil.TempDir("", "TestEmptyDwarfRanges")
dir, err := os.MkdirTemp("", "TestEmptyDwarfRanges")
if err != nil {
t.Fatalf("could not create directory: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/importer/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ package importer

import (
"bufio"
"cmd/compile/internal/types2"
"fmt"
"go/build"
"internal/pkgbits"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

"cmd/compile/internal/types2"
)

// debugging/development support
Expand Down Expand Up @@ -149,7 +149,7 @@ func Import(packages map[string]*types2.Package, path, srcDir string, lookup fun
if size >= 0 {
r = io.LimitReader(r, int64(size))
}
data, err = ioutil.ReadAll(r)
data, err = io.ReadAll(r)
if err != nil {
break
}
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/ir/mknode.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go/parser"
"go/token"
"io/fs"
"io/ioutil"
"log"
"sort"
"strings"
Expand Down Expand Up @@ -160,7 +159,7 @@ func main() {
// write out mangled source so we can see the bug.
out = buf.Bytes()
}
err = ioutil.WriteFile("node_gen.go", out, 0666)
err = os.WriteFile("node_gen.go", out, 0666)
if err != nil {
log.Fatal(err)
}
Expand Down
11 changes: 5 additions & 6 deletions src/cmd/compile/internal/logopt/logopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package logopt

import (
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -88,15 +87,15 @@ func TestLogOpt(t *testing.T) {

testenv.MustHaveGoBuild(t)

dir, err := ioutil.TempDir("", "TestLogOpt")
dir, err := os.MkdirTemp("", "TestLogOpt")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)

dir = fixSlash(dir) // Normalize the directory name as much as possible, for Windows testing
src := filepath.Join(dir, "file.go")
if err := ioutil.WriteFile(src, []byte(srcCode), 0644); err != nil {
if err := os.WriteFile(src, []byte(srcCode), 0644); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -146,7 +145,7 @@ func s15a8(x *[15]int64) [15]int64 {
}
`
copy := filepath.Join(dir, "copy.go")
if err := ioutil.WriteFile(copy, []byte(copyCode), 0644); err != nil {
if err := os.WriteFile(copy, []byte(copyCode), 0644); err != nil {
t.Fatal(err)
}
outcopy := filepath.Join(dir, "copy.o")
Expand All @@ -169,7 +168,7 @@ func s15a8(x *[15]int64) [15]int64 {
if err != nil {
t.Error("-json=0,file://log/opt should have succeeded")
}
logged, err := ioutil.ReadFile(filepath.Join(dir, "log", "opt", "x", "copy.json"))
logged, err := os.ReadFile(filepath.Join(dir, "log", "opt", "x", "copy.json"))
if err != nil {
t.Error("-json=0,file://log/opt missing expected log file")
}
Expand All @@ -196,7 +195,7 @@ func s15a8(x *[15]int64) [15]int64 {
if err != nil {
t.Error("-json=0,file://log/opt should have succeeded")
}
logged, err := ioutil.ReadFile(filepath.Join(dir, "log", "opt", "x", "file.json"))
logged, err := os.ReadFile(filepath.Join(dir, "log", "opt", "x", "file.json"))
if err != nil {
t.Error("-json=0,file://log/opt missing expected log file")
}
Expand Down
12 changes: 5 additions & 7 deletions src/cmd/compile/internal/ssa/debug_lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import (
"bufio"
"bytes"
"flag"
"internal/buildcfg"
"runtime"
"sort"
"strings"

"fmt"
"internal/buildcfg"
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"testing"
)

Expand Down Expand Up @@ -129,7 +127,7 @@ func TestDebugLines_53456(t *testing.T) {
func compileAndDump(t *testing.T, file, function, moreGCFlags string) []byte {
testenv.MustHaveGoBuild(t)

tmpdir, err := ioutil.TempDir("", "debug_lines_test")
tmpdir, err := os.MkdirTemp("", "debug_lines_test")
if err != nil {
panic(fmt.Sprintf("Problem creating TempDir, error %v", err))
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/ssa/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"internal/testenv"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -223,7 +222,7 @@ func testNexting(t *testing.T, base, tag, gcflags string, count int, moreArgs ..

// Use a temporary directory unless -f is specified
if !*force {
tmpdir, err := ioutil.TempDir("", "debug_test")
tmpdir, err := os.MkdirTemp("", "debug_test")
if err != nil {
panic(fmt.Sprintf("Problem creating TempDir, error %v\n", err))
}
Expand Down Expand Up @@ -366,7 +365,7 @@ func (h *nextHist) write(filename string) {

func (h *nextHist) read(filename string) {
h.f2i = make(map[string]uint8)
bytes, err := ioutil.ReadFile(filename)
bytes, err := os.ReadFile(filename)
if err != nil {
panic(fmt.Sprintf("Problem reading %s, error %v\n", filename, err))
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/ssa/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"flag"
"fmt"
"go/format"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -500,7 +499,7 @@ func genOp() {
panic(err)
}

if err := ioutil.WriteFile("../opGen.go", b, 0666); err != nil {
if err := os.WriteFile("../opGen.go", b, 0666); err != nil {
log.Fatalf("can't write output: %v\n", err)
}

Expand All @@ -521,7 +520,7 @@ func genOp() {
log.Fatalf("bad opcode regexp %s: %v", pattern, err)
}

src, err := ioutil.ReadFile(a.genfile)
src, err := os.ReadFile(a.genfile)
if err != nil {
log.Fatalf("can't read %s: %v", a.genfile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/ssa/gen/rulegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"go/printer"
"go/token"
"io"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -280,7 +279,7 @@ func genRulesSuffix(arch arch, suff string) {
file, err := parser.ParseFile(fset, "", buf, parser.ParseComments)
if err != nil {
filename := fmt.Sprintf("%s_broken.go", arch.name)
if err := ioutil.WriteFile(filename, buf.Bytes(), 0644); err != nil {
if err := os.WriteFile(filename, buf.Bytes(), 0644); err != nil {
log.Printf("failed to dump broken code to %s: %v", filename, err)
} else {
log.Printf("dumped broken code to %s", filename)
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/ssagen/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ssagen
import (
"fmt"
"internal/buildcfg"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -59,7 +58,7 @@ func (s *SymABIs) canonicalize(linksym string) string {
// the symbol name and the third field is the ABI name, as one of the
// named cmd/internal/obj.ABI constants.
func (s *SymABIs) ReadSymABIs(file string) {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
log.Fatalf("-symabis: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/staticdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"go/constant"
"io"
"io/ioutil"
"os"
"sort"
"strconv"
Expand Down Expand Up @@ -124,7 +123,7 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj.
}
size := info.Size()
if size <= 1*1024 {
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return nil, 0, err
}
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/syntax/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"flag"
"fmt"
"internal/testenv"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -178,7 +177,7 @@ func testSyntaxErrors(t *testing.T, filename string) {
func TestSyntaxErrors(t *testing.T) {
testenv.MustHaveGoBuild(t) // we need access to source (testdata)

list, err := ioutil.ReadDir(testdata)
list, err := os.ReadDir(testdata)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit f8c659b

Please sign in to comment.