all: replace deprecated io/ioutil with io and os (#3509)

This commit is contained in:
Oleksandr Redko 2023-09-25 21:41:59 +03:00 committed by GitHub
parent 224a2805a4
commit 899ba72505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 76 additions and 95 deletions

@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"regexp"
@ -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)
}
@ -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())

@ -7,7 +7,6 @@ import (
"go/format"
"go/token"
"go/types"
"io/ioutil"
"log"
"os"
"strings"
@ -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)
}
@ -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)
}

@ -9,7 +9,6 @@ import (
"go/token"
"go/types"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
@ -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)
}
@ -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()
@ -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) {
@ -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) {
@ -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) {
@ -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
@ -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) {
@ -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")) {
@ -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")) {
@ -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()
@ -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()
@ -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()
@ -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()

@ -3,7 +3,6 @@ package config
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/user"
"path"
@ -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)
}

@ -2,7 +2,7 @@ package frame
import (
"encoding/binary"
"io/ioutil"
"io"
"os"
"testing"
"unsafe"
@ -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)
}

@ -3,7 +3,7 @@ package frame
import (
"bytes"
"encoding/binary"
"io/ioutil"
"io"
"os"
"testing"
)
@ -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)
}

@ -7,7 +7,7 @@ import (
"debug/pe"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path/filepath"
@ -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)
}
@ -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)
}
@ -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)
}

@ -8,7 +8,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
@ -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) {

@ -1,7 +1,7 @@
package gobuild
import (
"io/ioutil"
"os"
"runtime"
"github.com/go-delve/delve/pkg/logflags"
@ -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" {

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"os"
@ -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
}

@ -15,7 +15,6 @@ import (
"go/token"
"hash/crc32"
"io"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -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 {
@ -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

@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"go/constant"
"io/ioutil"
"os"
"os/exec"
"path"
@ -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")
}

@ -20,7 +20,7 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"os"
"unicode/utf16"
"unsafe"
@ -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
}

@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -44,7 +43,7 @@ func RecordAsync(cmd []string, wd string, quiet bool, stdin string, stdout proc.
tracedirChan := make(chan string)
go func() {
bs, _ := ioutil.ReadAll(rfd)
bs, _ := io.ReadAll(rfd)
tracedirChan <- strings.TrimSpace(string(bs))
}()
@ -199,7 +198,7 @@ func checkRRAvailable() error {
}
// Check that /proc/sys/kernel/perf_event_paranoid doesn't exist or is <= 1.
buf, err := ioutil.ReadFile("/proc/sys/kernel/perf_event_paranoid")
buf, err := os.ReadFile("/proc/sys/kernel/perf_event_paranoid")
if err == nil {
perfEventParanoid, _ := strconv.Atoi(strings.TrimSpace(string(buf)))
if perfEventParanoid > 1 {

@ -2,7 +2,7 @@ package native
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@ -12,10 +12,10 @@ import (
func (p *nativeProcess) MemoryMap() ([]proc.MemoryMapEntry, error) {
const VmFlagsPrefix = "VmFlags:"
smapsbuf, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/smaps", p.pid))
smapsbuf, err := os.ReadFile(fmt.Sprintf("/proc/%d/smaps", p.pid))
if err != nil {
// Older versions of Linux don't have smaps but have maps which is in a similar format.
smapsbuf, err = ioutil.ReadFile(fmt.Sprintf("/proc/%d/maps", p.pid))
smapsbuf, err = os.ReadFile(fmt.Sprintf("/proc/%d/maps", p.pid))
if err != nil {
return nil, err
}

@ -5,7 +5,7 @@ import (
"debug/elf"
"encoding/binary"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/go-delve/delve/pkg/elfwriter"
@ -46,7 +46,7 @@ func (p *nativeProcess) DumpProcessNotes(notes []elfwriter.Note, threadDone func
copy(prpsinfo.Fname[:], fname)
prpsinfo.Fname[len(fname)] = 0
if cmdline, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", p.pid)); err == nil {
if cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", p.pid)); err == nil {
for len(cmdline) > 0 && cmdline[len(cmdline)-1] == '\n' {
cmdline = cmdline[:len(cmdline)-1]
}
@ -72,7 +72,7 @@ func (p *nativeProcess) DumpProcessNotes(notes []elfwriter.Note, threadDone func
Data: tobytes(prpsinfo),
})
auxvbuf, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/auxv", p.pid))
auxvbuf, err := os.ReadFile(fmt.Sprintf("/proc/%d/auxv", p.pid))
if err == nil {
notes = append(notes, elfwriter.Note{
Type: _NT_AUXV,

@ -6,7 +6,6 @@ import (
"debug/elf"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/signal"
@ -226,14 +225,14 @@ func waitForSearchProcess(pfx string, seen map[int]struct{}) (int, error) {
}
func initialize(dbp *nativeProcess) (string, error) {
comm, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/comm", dbp.pid))
comm, err := os.ReadFile(fmt.Sprintf("/proc/%d/comm", dbp.pid))
if err == nil {
// removes newline character
comm = bytes.TrimSuffix(comm, []byte("\n"))
}
if comm == nil || len(comm) <= 0 {
stat, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", dbp.pid))
stat, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", dbp.pid))
if err != nil {
return "", fmt.Errorf("could not read proc stat: %v", err)
}
@ -869,7 +868,7 @@ func (dbp *nativeProcess) detach(kill bool) error {
// EntryPoint will return the process entry point address, useful for
// debugging PIEs.
func (dbp *nativeProcess) EntryPoint() (uint64, error) {
auxvbuf, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/auxv", dbp.pid))
auxvbuf, err := os.ReadFile(fmt.Sprintf("/proc/%d/auxv", dbp.pid))
if err != nil {
return 0, fmt.Errorf("could not read auxiliary vector: %v", err)
}
@ -986,7 +985,7 @@ func killProcess(pid int) error {
}
func getCmdLine(pid int) string {
buf, _ := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
buf, _ := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
args := strings.SplitN(string(buf), "\x00", -1)
for i := range args {
if strings.Contains(args[i], " ") {

@ -8,7 +8,7 @@ import (
"go/ast"
"go/constant"
"go/token"
"io/ioutil"
"io"
"math/rand"
"net"
"net/http"
@ -2876,7 +2876,7 @@ func TestNextInDeferReturn(t *testing.T) {
func TestAttachDetach(t *testing.T) {
if testBackend == "lldb" && 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
@ -2944,7 +2944,7 @@ func TestAttachDetach(t *testing.T) {
// seems to be a bug with debugserver.
resp, err := http.Get("http://127.0.0.1:9191/nobp")
assertNoError(err, t, "Page request after detach")
bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
assertNoError(err, t, "Reading /nobp page")
defer resp.Body.Close()
if out := string(bs); !strings.Contains(out, "hello, world!") {
@ -5898,10 +5898,10 @@ func TestGnuDebuglink(t *testing.T) {
// build math.go and make a copy of the executable
fixture := protest.BuildFixture("math", 0)
buf, err := ioutil.ReadFile(fixture.Path)
buf, err := os.ReadFile(fixture.Path)
assertNoError(err, t, "ReadFile")
debuglinkPath := fixture.Path + "-gnu_debuglink"
assertNoError(ioutil.WriteFile(debuglinkPath, buf, 0666), t, "WriteFile")
assertNoError(os.WriteFile(debuglinkPath, buf, 0666), t, "WriteFile")
defer os.Remove(debuglinkPath)
run := func(exe string, args ...string) {
@ -6217,7 +6217,7 @@ func TestWaitFor(t *testing.T) {
func TestWaitForAttach(t *testing.T) {
skipOn(t, "flaky", "freebsd")
if testBackend == "lldb" && 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

@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"go/constant"
"io/ioutil"
"os"
"regexp"
"runtime"
"sort"
@ -1331,7 +1331,7 @@ func TestCallFunction(t *testing.T) {
}
func testCallFunctionSetBreakpoint(t *testing.T, p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
buf, err := ioutil.ReadFile(fixture.Source)
buf, err := os.ReadFile(fixture.Source)
assertNoError(err, t, "ReadFile")
for i, line := range strings.Split(string(buf), "\n") {
if strings.Contains(line, "// breakpoint here") {

@ -6,7 +6,6 @@ import (
"go/parser"
"go/token"
"io"
"io/ioutil"
"path/filepath"
"reflect"
"sort"
@ -29,7 +28,7 @@ const (
// Print prints to out a syntax highlighted version of the text read from
// reader, between lines startLine and endLine.
func Print(out io.Writer, path string, reader io.Reader, startLine, endLine, arrowLine int, colorEscapes map[Style]string, altTabStr string) error {
buf, err := ioutil.ReadAll(reader)
buf, err := io.ReadAll(reader)
if err != nil {
return err
}

@ -3,7 +3,6 @@ package colorize_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -50,7 +49,7 @@ var colors = map[colorize.Style]string{
var printed = []byte{27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 49, 58, 9, 27, 91, 51, 51, 109, 112, 97, 99, 107, 97, 103, 101, 27, 91, 57, 55, 109, 32, 109, 97, 105, 110, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 50, 58, 9, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 51, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 50, 109, 47, 47, 32, 86, 101, 104, 105, 99, 108, 101, 32, 100, 101, 102, 105, 110, 101, 115, 32, 116, 104, 101, 32, 118, 101, 104, 105, 99, 97, 108, 32, 98, 101, 104, 97, 118, 105, 111, 114, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 52, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 51, 109, 116, 121, 112, 101, 27, 91, 57, 55, 109, 32, 86, 101, 104, 105, 99, 108, 101, 32, 27, 91, 51, 51, 109, 105, 110, 116, 101, 114, 102, 97, 99, 101, 27, 91, 57, 55, 109, 32, 123, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 53, 58, 9, 27, 91, 57, 55, 109, 9, 27, 91, 51, 50, 109, 47, 47, 32, 82, 117, 110, 32, 118, 101, 104, 105, 99, 97, 108, 32, 99, 97, 110, 32, 114, 117, 110, 32, 105, 110, 32, 97, 32, 115, 112, 101, 101, 100, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 54, 58, 9, 27, 91, 57, 55, 109, 9, 82, 117, 110, 40, 41, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 55, 58, 9, 27, 91, 57, 55, 109, 125, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 56, 58, 9, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 32, 57, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 50, 109, 47, 47, 32, 66, 77, 87, 83, 49, 48, 48, 48, 82, 82, 32, 100, 101, 102, 105, 110, 101, 115, 32, 116, 104, 101, 32, 109, 111, 116, 111, 99, 121, 99, 108, 101, 32, 98, 109, 119, 32, 115, 49, 48, 48, 48, 114, 114, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 61, 62, 27, 91, 57, 55, 109, 32, 32, 49, 48, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 51, 109, 116, 121, 112, 101, 27, 91, 57, 55, 109, 32, 66, 77, 87, 83, 49, 48, 48, 48, 82, 82, 32, 27, 91, 51, 51, 109, 115, 116, 114, 117, 99, 116, 27, 91, 57, 55, 109, 32, 123, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 49, 58, 9, 27, 91, 57, 55, 109, 125, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 50, 58, 9, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 51, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 50, 109, 47, 47, 32, 82, 117, 110, 32, 98, 119, 109, 32, 115, 49, 48, 48, 48, 114, 114, 32, 114, 117, 110, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 52, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 51, 109, 102, 117, 110, 99, 27, 91, 57, 55, 109, 32, 40, 97, 32, 42, 66, 77, 87, 83, 49, 48, 48, 48, 82, 82, 41, 32, 82, 117, 110, 40, 41, 32, 123, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 53, 58, 9, 27, 91, 57, 55, 109, 9, 112, 114, 105, 110, 116, 108, 110, 40, 27, 91, 57, 52, 109, 34, 73, 32, 99, 97, 110, 32, 114, 117, 110, 32, 97, 116, 32, 51, 48, 48, 107, 109, 47, 104, 34, 27, 91, 57, 55, 109, 41, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 54, 58, 9, 27, 91, 57, 55, 109, 125, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 55, 58, 9, 27, 91, 57, 55, 109, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 56, 58, 9, 27, 91, 57, 55, 109, 27, 91, 51, 51, 109, 102, 117, 110, 99, 27, 91, 57, 55, 109, 32, 109, 97, 105, 110, 40, 41, 32, 123, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 49, 57, 58, 9, 27, 91, 57, 55, 109, 9, 27, 91, 51, 51, 109, 118, 97, 114, 27, 91, 57, 55, 109, 32, 118, 101, 104, 105, 99, 108, 101, 32, 86, 101, 104, 105, 99, 108, 101, 32, 61, 32, 38, 66, 77, 87, 83, 49, 48, 48, 48, 82, 82, 123, 125, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 50, 48, 58, 9, 27, 91, 57, 55, 109, 9, 118, 101, 104, 105, 99, 108, 101, 46, 82, 117, 110, 40, 41, 10, 27, 91, 51, 52, 109, 32, 32, 27, 91, 57, 55, 109, 32, 32, 50, 49, 58, 9, 27, 91, 57, 55, 109, 125, 10}
func TestPrint(t *testing.T) {
dat, err := ioutil.ReadFile(filepath.Join(test.FindFixturesDir(), "issue2896.go"))
dat, err := os.ReadFile(filepath.Join(test.FindFixturesDir(), "issue2896.go"))
if err != nil {
t.Fatalf("read test fixture error: %v", err)
}

@ -12,7 +12,6 @@ import (
"go/parser"
"go/scanner"
"io"
"io/ioutil"
"math"
"os"
"os/exec"
@ -3006,7 +3005,7 @@ func (c *Commands) onCmd(t *Term, ctx callContext, argstr string) error {
ctx.Breakpoint = bp
if args[1] == "-edit" {
f, err := ioutil.TempFile("", "dlv-on-cmd-")
f, err := os.CreateTemp("", "dlv-on-cmd-")
if err != nil {
return err
}

@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
@ -1357,16 +1356,16 @@ func TestTranscript(t *testing.T) {
if !strings.HasPrefix(out, "> main.main()") {
t.Fatalf("Wrong output for next: <%s>", out)
}
fh, err := ioutil.TempFile("", "test-transcript-*")
fh, err := os.CreateTemp("", "test-transcript-*")
if err != nil {
t.Fatalf("TempFile: %v", err)
t.Fatalf("CreateTemp: %v", err)
}
name := fh.Name()
fh.Close()
t.Logf("output to %q", name)
slurp := func() string {
b, err := ioutil.ReadFile(name)
b, err := os.ReadFile(name)
if err != nil {
t.Fatalf("could not read transcript file: %v", err)
}

@ -4,7 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"sort"
"strings"
@ -108,7 +108,7 @@ func New(ctx Context, out EchoWriter) *Env {
if !ok {
return nil, decorateError(thread, fmt.Errorf("argument of read_file was not a string"))
}
buf, err := ioutil.ReadFile(string(path))
buf, err := os.ReadFile(string(path))
if err != nil {
return nil, decorateError(thread, err)
}
@ -124,7 +124,7 @@ func New(ctx Context, out EchoWriter) *Env {
if !ok {
return nil, decorateError(thread, fmt.Errorf("first argument of write_file was not a string"))
}
err := ioutil.WriteFile(string(path), []byte(args[1].String()), 0640)
err := os.WriteFile(string(path), []byte(args[1].String()), 0o640)
return starlark.None, decorateError(thread, err)
})
builtindoc(writeFileBuiltinName, "(Path, Text)", "writes text to the specified file.")

@ -7,7 +7,6 @@ import (
"fmt"
"go/format"
"go/types"
"io/ioutil"
"os"
"text/template"
@ -111,7 +110,7 @@ func main() {
fmt.Fprintf(os.Stderr, "Generated invalid go code: %v\n", err)
os.Exit(1)
}
if err := ioutil.WriteFile(*oFlag, formatted, 0644); err != nil {
if err := os.WriteFile(*oFlag, formatted, 0o644); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write: %v\n", err)
os.Exit(1)
}

@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
"net"
@ -5278,7 +5277,7 @@ func TestLaunchDebugRequest(t *testing.T) {
var err []byte
go func() {
err, _ = ioutil.ReadAll(r)
err, _ = io.ReadAll(r)
t.Log(string(err))
close(done)
}()

@ -2,7 +2,6 @@ package debugger
import (
"fmt"
"io/ioutil"
"os"
"syscall"
)
@ -18,7 +17,7 @@ func attachErrorMessageLinux(pid int, err error) error {
if serr, ok := err.(syscall.Errno); ok {
switch serr {
case syscall.EPERM:
bs, err := ioutil.ReadFile("/proc/sys/kernel/yama/ptrace_scope")
bs, err := os.ReadFile("/proc/sys/kernel/yama/ptrace_scope")
if err == nil && len(bs) >= 1 && bs[0] != '0' {
// Yama documentation: https://www.kernel.org/doc/Documentation/security/Yama.txt
return fmt.Errorf("Could not attach to pid %d: this could be caused by a kernel security setting, try writing \"0\" to /proc/sys/kernel/yama/ptrace_scope", pid)

@ -7,7 +7,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"io/ioutil"
"log"
"net"
"os"
@ -19,7 +18,7 @@ import (
// for testing
var (
uid = os.Getuid()
readFile = ioutil.ReadFile
readFile = os.ReadFile
)
type errConnectionNotFound struct {

@ -3,7 +3,6 @@ package service_test
import (
"flag"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/rpc"
@ -246,14 +245,14 @@ func TestRestart_rebuild(t *testing.T) {
fi, err := os.Stat(f.Source)
assertNoError(err, t, "Stat fixture.Source")
originalSource, err := ioutil.ReadFile(f.Source)
originalSource, err := os.ReadFile(f.Source)
assertNoError(err, t, "Reading original source")
// Ensure we write the original source code back after the test exits.
defer ioutil.WriteFile(f.Source, originalSource, fi.Mode())
defer os.WriteFile(f.Source, originalSource, fi.Mode())
// Write modified source code to the fixture file.
err = ioutil.WriteFile(f.Source, []byte(modifiedSource), fi.Mode())
err = os.WriteFile(f.Source, []byte(modifiedSource), fi.Mode())
assertNoError(err, t, "Writing modified source")
// First set our new env var and ensure later that the
@ -2416,7 +2415,7 @@ func TestRedirects(t *testing.T) {
withTestClient2Extended("redirect", t, 0, [3]string{infile, outfile, ""}, nil, func(c service.Client, fixture protest.Fixture) {
outpath := filepath.Join(fixture.BuildDir, outfile)
<-c.Continue()
buf, err := ioutil.ReadFile(outpath)
buf, err := os.ReadFile(outpath)
assertNoError(err, t, "Reading output file")
t.Logf("output %q", buf)
if !strings.HasPrefix(string(buf), "Redirect test") {
@ -2427,7 +2426,7 @@ func TestRedirects(t *testing.T) {
_, err = c.Restart(false)
assertNoError(err, t, "Restart")
<-c.Continue()
buf2, err := ioutil.ReadFile(outpath)
buf2, err := os.ReadFile(outpath)
t.Logf("output %q", buf2)
assertNoError(err, t, "Reading output file (second time)")
if !strings.HasPrefix(string(buf2), "Redirect test") {
@ -2831,10 +2830,10 @@ func TestRestart_PreserveFunctionBreakpoint(t *testing.T) {
dir := protest.FindFixturesDir()
copy := func(inpath string) {
buf, err := ioutil.ReadFile(inpath)
buf, err := os.ReadFile(inpath)
assertNoError(err, t, fmt.Sprintf("Reading %q", inpath))
outpath := filepath.Join(dir, "testfnpos.go")
assertNoError(ioutil.WriteFile(outpath, buf, 0666), t, fmt.Sprintf("Creating %q", outpath))
assertNoError(os.WriteFile(outpath, buf, 0o666), t, fmt.Sprintf("Creating %q", outpath))
}
copy(filepath.Join(dir, "testfnpos1.go"))