Skip to content

Commit

Permalink
all: replace io/ioutil with io and os package
Browse files Browse the repository at this point in the history
Signed-off-by: cui fliter <[email protected]>
  • Loading branch information
cuishuang committed Sep 17, 2022
1 parent c1b48ff commit 6a58019
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 42 deletions.
11 changes: 5 additions & 6 deletions cmd/bent/bent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"flag"
"fmt"
"io/fs"
"io/ioutil"
"math/rand"
"os"
"os/exec"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 . /
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions driver/driver_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions driver/driver_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package driver
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strconv"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
21 changes: 10 additions & 11 deletions garbage/nethttp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"

"golang.org/x/benchmarks/driver"
)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions sweet/benchmarks/biogo-igor/igor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"

"golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions sweet/benchmarks/internal/driver/mem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package driver

import (
"fmt"
"io/ioutil"
"os"
"regexp"
"strconv"
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions sweet/benchmarks/markdown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -18,15 +17,15 @@ import (
)

func run(mddir string) error {
files, err := ioutil.ReadDir(mddir)
files, err := os.ReadDir(mddir)
if err != nil {
return err
}

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
}
Expand Down
3 changes: 1 addition & 2 deletions sweet/cmd/sweet/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions sweet/cmd/sweet/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions sweet/generators/gvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions sweet/generators/tile38.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6a58019

Please sign in to comment.