Skip to content

Commit

Permalink
all: replace deprecated io/ioutil with io and os
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Sep 22, 2023
1 parent ebc3e61 commit b734d9b
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 97 deletions.
5 changes: 2 additions & 3 deletions _scripts/gen-faq-toc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
Expand Down Expand Up @@ -34,7 +33,7 @@ const (
)

func spliceDocs(docpath string, docs []byte, outpath string) {
docbuf, err := ioutil.ReadFile(docpath)
docbuf, err := os.ReadFile(docpath)
if err != nil {
log.Fatalf("could not read doc file: %v", err)
}
Expand All @@ -59,7 +58,7 @@ func spliceDocs(docpath string, docs []byte, outpath string) {
outbuf.Write([]byte(footer))

if outpath != "-" {
err = ioutil.WriteFile(outpath, outbuf.Bytes(), 0664)
err = os.WriteFile(outpath, outbuf.Bytes(), 0o664)
must(err, "could not write documentation file: %v", err)
} else {
os.Stdout.Write(outbuf.Bytes())
Expand Down
5 changes: 2 additions & 3 deletions _scripts/gen-starlark-bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"go/format"
"go/token"
"go/types"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -279,7 +278,7 @@ const (
)

func spliceDocs(docpath string, docs []byte, outpath string) {
docbuf, err := ioutil.ReadFile(docpath)
docbuf, err := os.ReadFile(docpath)
if err != nil {
log.Fatalf("could not read doc file: %v", err)
}
Expand All @@ -304,7 +303,7 @@ func spliceDocs(docpath string, docs []byte, outpath string) {
outbuf = append(outbuf, []byte(footer)...)

if outpath != "-" {
err = ioutil.WriteFile(outpath, outbuf, 0664)
err = os.WriteFile(outpath, outbuf, 0o664)
if err != nil {
log.Fatalf("could not write documentation file: %v", err)
}
Expand Down
27 changes: 13 additions & 14 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"go/token"
"go/types"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -341,7 +340,7 @@ func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte
}

func slurpFile(t *testing.T, filename string) []byte {
saved, err := ioutil.ReadFile(filename)
saved, err := os.ReadFile(filename)
if err != nil {
t.Fatalf("Could not read %s: %v", filename, err)
}
Expand Down Expand Up @@ -390,7 +389,7 @@ func TestGeneratedDoc(t *testing.T) {
cmd.Dir = projectRoot()
err := cmd.Run()
assertNoError(err, t, "go run _scripts/gen-usage-docs.go")
entries, err := ioutil.ReadDir(tempDir)
entries, err := os.ReadDir(tempDir)
assertNoError(err, t, "ReadDir")
for _, doc := range entries {
docFilename := "Documentation/usage/" + doc.Name()
Expand Down Expand Up @@ -912,7 +911,7 @@ func TestTrace(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if !bytes.Contains(output, expected) {
Expand All @@ -936,7 +935,7 @@ func TestTrace2(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if !bytes.Contains(output, expected) {
Expand Down Expand Up @@ -964,7 +963,7 @@ func TestTraceMultipleGoroutines(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if !bytes.Contains(output, expected) {
Expand All @@ -978,7 +977,7 @@ func TestTraceMultipleGoroutines(t *testing.T) {

func TestTracePid(t *testing.T) {
if runtime.GOOS == "linux" {
bs, _ := ioutil.ReadFile("/proc/sys/kernel/yama/ptrace_scope")
bs, _ := os.ReadFile("/proc/sys/kernel/yama/ptrace_scope")
if bs == nil || strings.TrimSpace(string(bs)) != "0" {
t.Logf("can not run TestAttachDetach: %v\n", bs)
return
Expand Down Expand Up @@ -1007,7 +1006,7 @@ func TestTracePid(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if !bytes.Contains(output, expected) {
Expand Down Expand Up @@ -1035,7 +1034,7 @@ func TestTraceBreakpointExists(t *testing.T) {

defer cmd.Wait()

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if bytes.Contains(output, []byte("Breakpoint exists")) {
Expand All @@ -1057,7 +1056,7 @@ func TestTracePrintStack(t *testing.T) {

defer cmd.Wait()

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

if !bytes.Contains(output, []byte("Stack:")) && !bytes.Contains(output, []byte("main.main")) {
Expand Down Expand Up @@ -1095,7 +1094,7 @@ func TestTraceEBPF(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
Expand Down Expand Up @@ -1155,7 +1154,7 @@ func TestTraceEBPF2(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
Expand Down Expand Up @@ -1203,7 +1202,7 @@ func TestTraceEBPF3(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
Expand Down Expand Up @@ -1251,7 +1250,7 @@ func TestTraceEBPF4(t *testing.T) {

assertNoError(cmd.Start(), t, "running trace")

output, err := ioutil.ReadAll(rdr)
output, err := io.ReadAll(rdr)
assertNoError(err, t, "ReadAll")

cmd.Wait()
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package config
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/user"
"path"
Expand Down Expand Up @@ -166,7 +165,7 @@ func LoadConfig() (*Config, error) {
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return &Config{}, fmt.Errorf("unable to read config data: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dwarf/frame/entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package frame

import (
"encoding/binary"
"io/ioutil"
"io"
"os"
"testing"
"unsafe"
Expand Down Expand Up @@ -146,7 +146,7 @@ func BenchmarkFDEForPC(b *testing.B) {
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
b.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dwarf/frame/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package frame
import (
"bytes"
"encoding/binary"
"io/ioutil"
"io"
"os"
"testing"
)
Expand Down Expand Up @@ -47,7 +47,7 @@ func BenchmarkParse(b *testing.B) {
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
b.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/dwarf/line/line_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"debug/pe"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -191,7 +191,7 @@ func loadBenchmarkData(tb testing.TB) DebugLines {
tb.Fatal("Could not find test data", p, err)
}

data, err := ioutil.ReadFile(p)
data, err := os.ReadFile(p)
if err != nil {
tb.Fatal("Could not read test data", err)
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestDebugLineC(t *testing.T) {
t.Fatal("Could not find test data", p, err)
}

data, err := ioutil.ReadFile(p)
data, err := os.ReadFile(p)
if err != nil {
t.Fatal("Could not read test data", err)
}
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestDebugLineDwarf4(t *testing.T) {
if err != nil {
t.Fatal("Could not open test data (zlib)", err)
}
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
t.Fatal("Could not read test data", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/dwarf/line/state_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

Expand All @@ -27,7 +26,7 @@ func slurpGzip(path string) ([]byte, error) {
return nil, err
}
defer gzin.Close()
return ioutil.ReadAll(gzin)
return io.ReadAll(gzin)
}

func TestGrafana(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gobuild/defaultexe.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gobuild

import (
"io/ioutil"
"os"
"runtime"

"github.com/go-delve/delve/pkg/logflags"
Expand All @@ -14,7 +14,7 @@ func DefaultDebugBinaryPath(name string) string {
if runtime.GOOS == "windows" {
pattern += "*.exe"
}
f, err := ioutil.TempFile(".", pattern)
f, err := os.CreateTemp(".", pattern)
if err != nil {
logflags.DebuggerLogger().Errorf("could not create temporary file for build output: %v", err)
if runtime.GOOS == "windows" {
Expand Down
3 changes: 1 addition & 2 deletions pkg/logflags/logflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -194,7 +193,7 @@ func Setup(logFlag bool, logstr, logDest string) error {
}
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
if !logFlag {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
if logstr != "" {
return errLogstrWithoutLog
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go/token"
"hash/crc32"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -1352,7 +1351,7 @@ func (bi *BinaryInfo) openSeparateDebugInfo(image *Image, exe *elf.File, debugIn

if debugFilePath != "" {
// CRC check
buf, err := ioutil.ReadFile(debugFilePath)
buf, err := os.ReadFile(debugFilePath)
if err == nil {
computedCRC := crc32.ChecksumIEEE(buf)
if crc != computedCRC {
Expand Down Expand Up @@ -1567,7 +1566,7 @@ func (bi *BinaryInfo) getDebugLink(exe *elf.File) (debugLink string, crc uint32)
}

br := gnuDebugLink.Open()
buf, err := ioutil.ReadAll(br)
buf, err := io.ReadAll(br)
if err != nil {
bi.logger.Warnf("can't read .gnu_debuglink: %v", err)
return
Expand Down
5 changes: 2 additions & 3 deletions pkg/proc/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"go/constant"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -222,9 +221,9 @@ func withCoreFile(t *testing.T, name, args string) *proc.TargetGroup {
p, err := OpenCore(corePath, fix.Path, []string{})
if err != nil {
t.Errorf("OpenCore(%q) failed: %v", corePath, err)
pat, err := ioutil.ReadFile("/proc/sys/kernel/core_pattern")
pat, err := os.ReadFile("/proc/sys/kernel/core_pattern")
t.Errorf("read core_pattern: %q, %v", pat, err)
apport, err := ioutil.ReadFile("/var/log/apport.log")
apport, err := os.ReadFile("/var/log/apport.log")
t.Errorf("read apport log: %q, %v", apport, err)
t.Fatalf("previous errors")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/proc/core/minidump/minidump.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"os"
"unicode/utf16"
"unsafe"

Expand Down Expand Up @@ -318,7 +318,7 @@ const (

// Open reads the minidump file at path and returns it as a Minidump structure.
func Open(path string, logfn func(fmt string, args ...interface{})) (*Minidump, error) {
rawbuf, err := ioutil.ReadFile(path) //TODO(aarzilli): mmap?
rawbuf, err := os.ReadFile(path) //TODO(aarzilli): mmap?
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit b734d9b

Please sign in to comment.