all: replace io/ioutil with io and os package

For golang/go#45557

Change-Id: Ib1e5d3116f04adaacb4d6b81898db255b3d5bd04
GitHub-Last-Rev: 6a580196cb
GitHub-Pull-Request: golang/benchmarks#3
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/430856
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
pull/4/head
cui fliter 2022-09-17 01:24:18 +00:00 committed by Gopher Robot
parent c1b48ff119
commit fdd6c4b5cd
13 changed files with 32 additions and 42 deletions

View File

@ -15,7 +15,6 @@ import (
"flag"
"fmt"
"io/fs"
"io/ioutil"
"math/rand"
"os"
"os/exec"
@ -226,17 +225,17 @@ results will also appear in 'bench'.
}
todo := &Todo{}
blobB, err := ioutil.ReadFile(benchFile)
blobB, err := os.ReadFile(benchFile)
if err != nil {
fmt.Printf("There was an error opening or reading file %s: %v\n", benchFile, err)
os.Exit(1)
}
blobC, err := ioutil.ReadFile(confFile)
blobC, err := os.ReadFile(confFile)
if err != nil {
fmt.Printf("There was an error opening or reading file %s: %v\n", confFile, err)
os.Exit(1)
}
blobS, err := ioutil.ReadFile(suiteFile)
blobS, err := os.ReadFile(suiteFile)
if err != nil {
fmt.Printf("There was an error opening or reading file %s: %v\n", suiteFile, err)
os.Exit(1)
@ -1130,7 +1129,7 @@ func checkAndSetUpFileSystem(shouldInit bool) error {
copyAsset(configs, "configs", s)
}
err := ioutil.WriteFile("Dockerfile",
err := os.WriteFile("Dockerfile",
[]byte(`
FROM ubuntu
ADD . /
@ -1172,7 +1171,7 @@ func copyAsset(fs embed.FS, dir, file string) {
fmt.Printf("Error reading asset %s\n", file)
os.Exit(1)
}
err = ioutil.WriteFile(file, bytes, 0664)
err = os.WriteFile(file, bytes, 0664)
if err != nil {
fmt.Printf("Error writing %s\n", file)
os.Exit(1)

View File

@ -11,7 +11,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@ -105,7 +104,7 @@ func Size(file string) string {
}
func getVMPeak() uint64 {
data, err := ioutil.ReadFile("/proc/self/status")
data, err := os.ReadFile("/proc/self/status")
if err != nil {
log.Printf("Failed to read /proc/self/status: %v", err)
return 0

View File

@ -7,8 +7,8 @@ package driver
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
@ -72,7 +72,7 @@ func RunAndCollectSysStats(cmd *exec.Cmd, res *Result, N uint64, prefix string)
}
func procCPUTime() (uint64, error) {
b, err := ioutil.ReadFile("/dev/cputime")
b, err := os.ReadFile("/dev/cputime")
if err != nil {
return 0, err
}

View File

@ -22,7 +22,7 @@ var src = `
// // handle error
// }
// defer resp.Body.Close()
// body, err := ioutil.ReadAll(resp.Body)
// body, err := io.ReadAll(resp.Body)
// // ...
//
// For control over HTTP client headers, redirect policy, and other
@ -90,7 +90,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"mime"
"mime/multipart"
@ -469,7 +468,7 @@ func (c *Client) doFollowingRedirects(ireq *Request, shouldRedirect func(int) bo
// No need to check for errors: if it fails, Transport won't reuse it anyway.
const maxBodySlurpSize = 2 << 10
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
io.CopyN(io.Discard, resp.Body, maxBodySlurpSize)
}
resp.Body.Close()
if urlStr = resp.Header.Get("Location"); urlStr == "" {
@ -2495,7 +2494,7 @@ func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
}
rc, ok := body.(io.ReadCloser)
if !ok && body != nil {
rc = ioutil.NopCloser(body)
rc = io.NopCloser(body)
}
req := &Request{
Method: method,
@ -2744,7 +2743,7 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
maxFormSize = int64(10 << 20)
reader = io.LimitReader(r.Body, maxFormSize+1)
}
b, e := ioutil.ReadAll(reader)
b, e := io.ReadAll(reader)
if e != nil {
if err == nil {
err = e
@ -4011,7 +4010,7 @@ func (cw *chunkWriter) writeHeader(p []byte) {
}
if discard {
_, err := io.CopyN(ioutil.Discard, w.req.Body, maxPostHandlerReadBytes+1)
_, err := io.CopyN(io.Discard, w.req.Body, maxPostHandlerReadBytes+1)
switch err {
case nil:
@ -5190,7 +5189,7 @@ func (globalOptionsHandler) ServeHTTP(w ResponseWriter, r *Request) {
if r.ContentLength != 0 {
mb := MaxBytesReader(w, r.Body, 4<<10)
io.Copy(ioutil.Discard, mb)
io.Copy(io.Discard, mb)
}
}
@ -5207,7 +5206,7 @@ var eofReader = &struct {
io.Closer
}{
eofReaderWithWriteTo{},
ioutil.NopCloser(nil),
io.NopCloser(nil),
}
// Verify that an io.Copy from an eofReader won't require a buffer.
@ -5813,7 +5812,7 @@ func (t *transferWriter) WriteBody(w io.Writer) error {
return err
}
var nextra int64
nextra, err = io.Copy(ioutil.Discard, t.Body)
nextra, err = io.Copy(io.Discard, t.Body)
ncopy += nextra
}
if err != nil {
@ -6301,7 +6300,7 @@ func (b *body) Close() error {
} else {
var n int64
n, err = io.CopyN(ioutil.Discard, bodyLocked{b}, maxPostHandlerReadBytes)
n, err = io.CopyN(io.Discard, bodyLocked{b}, maxPostHandlerReadBytes)
if err == io.EOF {
err = nil
}
@ -6311,7 +6310,7 @@ func (b *body) Close() error {
}
default:
_, err = io.Copy(ioutil.Discard, bodyLocked{b})
_, err = io.Copy(io.Discard, bodyLocked{b})
}
b.closed = true
return err

View File

@ -7,7 +7,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
@ -51,7 +51,7 @@ func makeOneRequest() bool {
return false
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalf("ReadAll: %v", err)
}

View File

@ -12,7 +12,6 @@ import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"golang.org/x/benchmarks/driver"
)
@ -47,7 +46,7 @@ func makeBytes() []byte {
r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
r = base64.NewDecoder(base64.StdEncoding, r)
r = bzip2.NewReader(r)
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
panic(err)
}

View File

@ -10,8 +10,8 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
"golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
@ -41,7 +41,7 @@ func main() {
log.Fatal("error: input GFF file required")
}
data, err := ioutil.ReadFile(flag.Arg(0))
data, err := os.ReadFile(flag.Arg(0))
if err != nil {
log.Fatalf("error: %v", err)
}

View File

@ -6,7 +6,6 @@ package driver
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strconv"
@ -20,7 +19,7 @@ var (
)
func readStat(pid int, r *regexp.Regexp) (uint64, error) {
b, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/status", pid))
b, err := os.ReadFile(fmt.Sprintf("/proc/%d/status", pid))
if err != nil {
return 0, err
}

View File

@ -8,7 +8,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -18,7 +17,7 @@ import (
)
func run(mddir string) error {
files, err := ioutil.ReadDir(mddir)
files, err := os.ReadDir(mddir)
if err != nil {
return err
}
@ -26,7 +25,7 @@ func run(mddir string) error {
contents := make([][]byte, 0, len(files))
for _, file := range files {
if !file.IsDir() && filepath.Ext(file.Name()) == ".md" {
content, err := ioutil.ReadFile(filepath.Join(mddir, file.Name()))
content, err := os.ReadFile(filepath.Join(mddir, file.Name()))
if err != nil {
return err
}

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -157,7 +156,7 @@ func copyDirContents(dst, src string) error {
func rmDirContents(dir string) error {
log.CommandPrintf("rm -rf %s/*", dir)
fs, err := ioutil.ReadDir(dir)
fs, err := os.ReadDir(dir)
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -157,7 +156,7 @@ func (c *runCmd) Run(args []string) error {
var err error
if c.workDir == "" {
// Create a temporary work tree for running the benchmarks.
c.workDir, err = ioutil.TempDir("", "gosweet")
c.workDir, err = os.MkdirTemp("", "gosweet")
if err != nil {
return fmt.Errorf("creating work root: %w", err)
}
@ -238,7 +237,7 @@ func (c *runCmd) Run(args []string) error {
configDir := filepath.Dir(configFile)
// Read and parse the configuration file.
b, err := ioutil.ReadFile(configFile)
b, err := os.ReadFile(configFile)
if err != nil {
return fmt.Errorf("failed to read %q: %v", configFile, err)
}

View File

@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -67,7 +66,7 @@ func (_ GVisor) Generate(cfg *common.GenConfig) error {
// copy of runsc. Get and build it from the harness.
//
// Create a temporary directory where we can put the gVisor source.
tmpDir, err := ioutil.TempDir("", "gvisor-gen")
tmpDir, err := os.MkdirTemp("", "gvisor-gen")
if err != nil {
return err
}

View File

@ -9,7 +9,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -68,7 +67,7 @@ func (_ Tile38) Generate(cfg *common.GenConfig) error {
// Create a temporary directory where we can put the Tile38
// source and build it.
tmpDir, err := ioutil.TempDir("", "tile38-gen")
tmpDir, err := os.MkdirTemp("", "tile38-gen")
if err != nil {
return err
}
@ -292,7 +291,7 @@ func storeGeoObj(c redis.Conn, g *geoObj) error {
// storeGeoJSON writes an entire GeoJSON object (which may contain many polygons)
// to a Tile38 database.
func storeGeoJSON(c redis.Conn, jsonFile string) error {
b, err := ioutil.ReadFile(jsonFile)
b, err := os.ReadFile(jsonFile)
if err != nil {
return err
}