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
parent
c1b48ff119
commit
fdd6c4b5cd
|
@ -15,7 +15,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -226,17 +225,17 @@ results will also appear in 'bench'.
|
||||||
}
|
}
|
||||||
|
|
||||||
todo := &Todo{}
|
todo := &Todo{}
|
||||||
blobB, err := ioutil.ReadFile(benchFile)
|
blobB, err := os.ReadFile(benchFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("There was an error opening or reading file %s: %v\n", benchFile, err)
|
fmt.Printf("There was an error opening or reading file %s: %v\n", benchFile, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
blobC, err := ioutil.ReadFile(confFile)
|
blobC, err := os.ReadFile(confFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("There was an error opening or reading file %s: %v\n", confFile, err)
|
fmt.Printf("There was an error opening or reading file %s: %v\n", confFile, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
blobS, err := ioutil.ReadFile(suiteFile)
|
blobS, err := os.ReadFile(suiteFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("There was an error opening or reading file %s: %v\n", suiteFile, err)
|
fmt.Printf("There was an error opening or reading file %s: %v\n", suiteFile, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -1130,7 +1129,7 @@ func checkAndSetUpFileSystem(shouldInit bool) error {
|
||||||
copyAsset(configs, "configs", s)
|
copyAsset(configs, "configs", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ioutil.WriteFile("Dockerfile",
|
err := os.WriteFile("Dockerfile",
|
||||||
[]byte(`
|
[]byte(`
|
||||||
FROM ubuntu
|
FROM ubuntu
|
||||||
ADD . /
|
ADD . /
|
||||||
|
@ -1172,7 +1171,7 @@ func copyAsset(fs embed.FS, dir, file string) {
|
||||||
fmt.Printf("Error reading asset %s\n", file)
|
fmt.Printf("Error reading asset %s\n", file)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(file, bytes, 0664)
|
err = os.WriteFile(file, bytes, 0664)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error writing %s\n", file)
|
fmt.Printf("Error writing %s\n", file)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -105,7 +104,7 @@ func Size(file string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVMPeak() uint64 {
|
func getVMPeak() uint64 {
|
||||||
data, err := ioutil.ReadFile("/proc/self/status")
|
data, err := os.ReadFile("/proc/self/status")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to read /proc/self/status: %v", err)
|
log.Printf("Failed to read /proc/self/status: %v", err)
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -7,8 +7,8 @@ package driver
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -72,7 +72,7 @@ func RunAndCollectSysStats(cmd *exec.Cmd, res *Result, N uint64, prefix string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func procCPUTime() (uint64, error) {
|
func procCPUTime() (uint64, error) {
|
||||||
b, err := ioutil.ReadFile("/dev/cputime")
|
b, err := os.ReadFile("/dev/cputime")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ var src = `
|
||||||
// // handle error
|
// // handle error
|
||||||
// }
|
// }
|
||||||
// defer resp.Body.Close()
|
// 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
|
// For control over HTTP client headers, redirect policy, and other
|
||||||
|
@ -90,7 +90,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"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.
|
// No need to check for errors: if it fails, Transport won't reuse it anyway.
|
||||||
const maxBodySlurpSize = 2 << 10
|
const maxBodySlurpSize = 2 << 10
|
||||||
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
|
if resp.ContentLength == -1 || resp.ContentLength <= maxBodySlurpSize {
|
||||||
io.CopyN(ioutil.Discard, resp.Body, maxBodySlurpSize)
|
io.CopyN(io.Discard, resp.Body, maxBodySlurpSize)
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if urlStr = resp.Header.Get("Location"); urlStr == "" {
|
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)
|
rc, ok := body.(io.ReadCloser)
|
||||||
if !ok && body != nil {
|
if !ok && body != nil {
|
||||||
rc = ioutil.NopCloser(body)
|
rc = io.NopCloser(body)
|
||||||
}
|
}
|
||||||
req := &Request{
|
req := &Request{
|
||||||
Method: method,
|
Method: method,
|
||||||
|
@ -2744,7 +2743,7 @@ func parsePostForm(r *Request) (vs url.Values, err error) {
|
||||||
maxFormSize = int64(10 << 20)
|
maxFormSize = int64(10 << 20)
|
||||||
reader = io.LimitReader(r.Body, maxFormSize+1)
|
reader = io.LimitReader(r.Body, maxFormSize+1)
|
||||||
}
|
}
|
||||||
b, e := ioutil.ReadAll(reader)
|
b, e := io.ReadAll(reader)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = e
|
err = e
|
||||||
|
@ -4011,7 +4010,7 @@ func (cw *chunkWriter) writeHeader(p []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if discard {
|
if discard {
|
||||||
_, err := io.CopyN(ioutil.Discard, w.req.Body, maxPostHandlerReadBytes+1)
|
_, err := io.CopyN(io.Discard, w.req.Body, maxPostHandlerReadBytes+1)
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
|
|
||||||
|
@ -5190,7 +5189,7 @@ func (globalOptionsHandler) ServeHTTP(w ResponseWriter, r *Request) {
|
||||||
if r.ContentLength != 0 {
|
if r.ContentLength != 0 {
|
||||||
|
|
||||||
mb := MaxBytesReader(w, r.Body, 4<<10)
|
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
|
io.Closer
|
||||||
}{
|
}{
|
||||||
eofReaderWithWriteTo{},
|
eofReaderWithWriteTo{},
|
||||||
ioutil.NopCloser(nil),
|
io.NopCloser(nil),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that an io.Copy from an eofReader won't require a buffer.
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
var nextra int64
|
var nextra int64
|
||||||
nextra, err = io.Copy(ioutil.Discard, t.Body)
|
nextra, err = io.Copy(io.Discard, t.Body)
|
||||||
ncopy += nextra
|
ncopy += nextra
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6301,7 +6300,7 @@ func (b *body) Close() error {
|
||||||
} else {
|
} else {
|
||||||
var n int64
|
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 {
|
if err == io.EOF {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
@ -6311,7 +6310,7 @@ func (b *body) Close() error {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
||||||
_, err = io.Copy(ioutil.Discard, bodyLocked{b})
|
_, err = io.Copy(io.Discard, bodyLocked{b})
|
||||||
}
|
}
|
||||||
b.closed = true
|
b.closed = true
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -7,7 +7,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -51,7 +51,7 @@ func makeOneRequest() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
b, err := ioutil.ReadAll(res.Body)
|
b, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ReadAll: %v", err)
|
log.Fatalf("ReadAll: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"golang.org/x/benchmarks/driver"
|
"golang.org/x/benchmarks/driver"
|
||||||
)
|
)
|
||||||
|
@ -47,7 +46,7 @@ func makeBytes() []byte {
|
||||||
r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
|
r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
|
||||||
r = base64.NewDecoder(base64.StdEncoding, r)
|
r = base64.NewDecoder(base64.StdEncoding, r)
|
||||||
r = bzip2.NewReader(r)
|
r = bzip2.NewReader(r)
|
||||||
b, err := ioutil.ReadAll(r)
|
b, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
|
"golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
|
||||||
|
@ -41,7 +41,7 @@ func main() {
|
||||||
log.Fatal("error: input GFF file required")
|
log.Fatal("error: input GFF file required")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(flag.Arg(0))
|
data, err := os.ReadFile(flag.Arg(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %v", err)
|
log.Fatalf("error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ package driver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -20,7 +19,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func readStat(pid int, r *regexp.Regexp) (uint64, error) {
|
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 {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(mddir string) error {
|
func run(mddir string) error {
|
||||||
files, err := ioutil.ReadDir(mddir)
|
files, err := os.ReadDir(mddir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -26,7 +25,7 @@ func run(mddir string) error {
|
||||||
contents := make([][]byte, 0, len(files))
|
contents := make([][]byte, 0, len(files))
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if !file.IsDir() && filepath.Ext(file.Name()) == ".md" {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -157,7 +156,7 @@ func copyDirContents(dst, src string) error {
|
||||||
|
|
||||||
func rmDirContents(dir string) error {
|
func rmDirContents(dir string) error {
|
||||||
log.CommandPrintf("rm -rf %s/*", dir)
|
log.CommandPrintf("rm -rf %s/*", dir)
|
||||||
fs, err := ioutil.ReadDir(dir)
|
fs, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -157,7 +156,7 @@ func (c *runCmd) Run(args []string) error {
|
||||||
var err error
|
var err error
|
||||||
if c.workDir == "" {
|
if c.workDir == "" {
|
||||||
// Create a temporary work tree for running the benchmarks.
|
// Create a temporary work tree for running the benchmarks.
|
||||||
c.workDir, err = ioutil.TempDir("", "gosweet")
|
c.workDir, err = os.MkdirTemp("", "gosweet")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating work root: %w", err)
|
return fmt.Errorf("creating work root: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -238,7 +237,7 @@ func (c *runCmd) Run(args []string) error {
|
||||||
configDir := filepath.Dir(configFile)
|
configDir := filepath.Dir(configFile)
|
||||||
|
|
||||||
// Read and parse the configuration file.
|
// Read and parse the configuration file.
|
||||||
b, err := ioutil.ReadFile(configFile)
|
b, err := os.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read %q: %v", configFile, err)
|
return fmt.Errorf("failed to read %q: %v", configFile, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -67,7 +66,7 @@ func (_ GVisor) Generate(cfg *common.GenConfig) error {
|
||||||
// copy of runsc. Get and build it from the harness.
|
// copy of runsc. Get and build it from the harness.
|
||||||
//
|
//
|
||||||
// Create a temporary directory where we can put the gVisor source.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -68,7 +67,7 @@ func (_ Tile38) Generate(cfg *common.GenConfig) error {
|
||||||
|
|
||||||
// Create a temporary directory where we can put the Tile38
|
// Create a temporary directory where we can put the Tile38
|
||||||
// source and build it.
|
// source and build it.
|
||||||
tmpDir, err := ioutil.TempDir("", "tile38-gen")
|
tmpDir, err := os.MkdirTemp("", "tile38-gen")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
// storeGeoJSON writes an entire GeoJSON object (which may contain many polygons)
|
||||||
// to a Tile38 database.
|
// to a Tile38 database.
|
||||||
func storeGeoJSON(c redis.Conn, jsonFile string) error {
|
func storeGeoJSON(c redis.Conn, jsonFile string) error {
|
||||||
b, err := ioutil.ReadFile(jsonFile)
|
b, err := os.ReadFile(jsonFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue