Merge pull request #11015 from zchee:remove-deprecated

PiperOrigin-RevId: 684610109
This commit is contained in:
gVisor bot
2024-10-10 16:10:29 -07:00
76 changed files with 256 additions and 314 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ package coretag
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"golang.org/x/sys/unix"
@@ -77,7 +77,7 @@ func GetAllCoreTags(pid int) ([]uint64, error) {
// getTids returns set of tids as reported by /proc/<pid>/task.
func getTids(pid int) (map[int]struct{}, error) {
tids := make(map[int]struct{})
files, err := ioutil.ReadDir("/proc/" + strconv.Itoa(pid) + "/task")
files, err := os.ReadDir("/proc/" + strconv.Itoa(pid) + "/task")
if err != nil {
return nil, err
}
+1 -2
View File
@@ -15,7 +15,6 @@
package cpuid
import (
"io/ioutil"
"os"
"regexp"
"strings"
@@ -38,7 +37,7 @@ func TestHostFeatureFlags(t *testing.T) {
}
// Extract all cpuinfo flags.
cpuinfoBytes, _ := ioutil.ReadFile("/proc/cpuinfo")
cpuinfoBytes, _ := os.ReadFile("/proc/cpuinfo")
cpuinfo := string(cpuinfoBytes)
re := regexp.MustCompile(`(?m)^flags\s+: (.*)$`)
m := re.FindStringSubmatch(cpuinfo)
+2 -2
View File
@@ -18,7 +18,7 @@
package cpuid
import (
"io/ioutil"
"os"
"strconv"
"strings"
@@ -180,7 +180,7 @@ var (
// filter installation. This value is used to create the fake /proc/cpuinfo
// from a FeatureSet.
func readMaxCPUFreq() {
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
cpuinfob, err := os.ReadFile("/proc/cpuinfo")
if err != nil {
// Leave it as 0... the VDSO bails out in the same way.
log.Warningf("Could not read /proc/cpuinfo: %v", err)
+2 -2
View File
@@ -18,7 +18,7 @@
package cpuid
import (
"io/ioutil"
"os"
"runtime"
"strconv"
"strings"
@@ -51,7 +51,7 @@ func initCPUInfo() {
// warn about them not existing.
return
}
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
cpuinfob, err := os.ReadFile("/proc/cpuinfo")
if err != nil {
// Leave everything at 0, nothing can be done.
log.Warningf("Could not read /proc/cpuinfo: %v", err)
+3 -4
View File
@@ -15,7 +15,6 @@
package fdchannel
import (
"io/ioutil"
"os"
"syscall"
"testing"
@@ -26,7 +25,7 @@ import (
)
func TestSendRecvFD(t *testing.T) {
sendFile, err := ioutil.TempFile("", "fdchannel_test_")
sendFile, err := os.CreateTemp("", "fdchannel_test_")
if err != nil {
t.Fatalf("failed to create temporary file: %v", err)
}
@@ -82,7 +81,7 @@ func TestSendRecvFD(t *testing.T) {
}
func TestShutdownThenRecvFD(t *testing.T) {
sendFile, err := ioutil.TempFile("", "fdchannel_test_")
sendFile, err := os.CreateTemp("", "fdchannel_test_")
if err != nil {
t.Fatalf("failed to create temporary file: %v", err)
}
@@ -104,7 +103,7 @@ func TestShutdownThenRecvFD(t *testing.T) {
}
func TestRecvFDThenShutdown(t *testing.T) {
sendFile, err := ioutil.TempFile("", "fdchannel_test_")
sendFile, err := os.CreateTemp("", "fdchannel_test_")
if err != nil {
t.Fatalf("failed to create temporary file: %v", err)
}
+1 -2
View File
@@ -15,7 +15,6 @@
package gohacks
import (
"io/ioutil"
"math/rand"
"os"
"runtime"
@@ -75,7 +74,7 @@ func TestSigbusOnMemmove(t *testing.T) {
// Test that SIGBUS received by runtime.memmove when *not* doing
// CopyIn or CopyOut work gets propagated to the runtime.
const bufLen = pageSize
f, err := ioutil.TempFile("", "sigbus_test")
f, err := os.CreateTemp("", "sigbus_test")
if err != nil {
t.Fatalf("TempFile failed: %v", err)
}
+1 -2
View File
@@ -19,7 +19,6 @@ package testsuite
import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
@@ -54,7 +53,7 @@ type Tester interface {
// RunAllLocalFSTests runs all local FS tests as subtests.
func RunAllLocalFSTests(t *testing.T, tester Tester) {
for name, testFn := range localFSTests {
mountPath, err := ioutil.TempDir(os.Getenv("TEST_TMPDIR"), "")
mountPath, err := os.MkdirTemp(os.Getenv("TEST_TMPDIR"), "")
if err != nil {
t.Fatalf("creation of temporary mountpoint failed: %v", err)
}
+2 -3
View File
@@ -18,7 +18,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/fd"
@@ -223,7 +222,7 @@ func recv(s *unet.Socket, msize uint32, lookup lookupTagAndType) (Tag, message,
if err != nil {
// Throw away the contents of this message.
if remaining > 0 {
io.Copy(ioutil.Discard, &io.LimitedReader{R: s, N: int64(remaining)})
io.Copy(io.Discard, &io.LimitedReader{R: s, N: int64(remaining)})
}
return tag, nil, err
}
@@ -260,7 +259,7 @@ func recv(s *unet.Socket, msize uint32, lookup lookupTagAndType) (Tag, message,
if fixedSize > remaining {
// This is not a valid message.
if remaining > 0 {
io.Copy(ioutil.Discard, &io.LimitedReader{R: s, N: int64(remaining)})
io.Copy(io.Discard, &io.LimitedReader{R: s, N: int64(remaining)})
}
return NoTag, nil, ErrNoValidMessage
}
+1 -2
View File
@@ -15,7 +15,6 @@
package p9
import (
"io/ioutil"
"os"
"testing"
@@ -113,7 +112,7 @@ func TestSendRecvWithFile(t *testing.T) {
defer client.Close()
// Create a tempfile.
osf, err := ioutil.TempFile("", "p9")
osf, err := os.CreateTemp("", "p9")
if err != nil {
t.Fatalf("tempfile got err %v expected nil", err)
}
+2 -2
View File
@@ -17,8 +17,8 @@ package safecopy
import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
"unsafe"
@@ -239,7 +239,7 @@ func withSegvErrorTestMapping(t *testing.T, fn func(m []byte)) {
// withBusErrorTestMapping calls fn with a two-page mapping. The first page
// contains random data, and the second page generates SIGBUS when accessed.
func withBusErrorTestMapping(t *testing.T, fn func(m []byte)) {
f, err := ioutil.TempFile("", "sigbus_test")
f, err := os.CreateTemp("", "sigbus_test")
if err != nil {
t.Fatalf("TempFile failed: %v", err)
}
+1 -4
View File
@@ -19,7 +19,6 @@ import (
_ "embed"
"fmt"
"io"
"io/ioutil"
"math"
"math/rand"
"os"
@@ -27,7 +26,6 @@ import (
"reflect"
"strings"
"testing"
"time"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/abi/linux"
@@ -39,7 +37,7 @@ var victimData []byte
// newVictim makes a victim binary.
func newVictim() (string, error) {
f, err := ioutil.TempFile("", "victim")
f, err := os.CreateTemp("", "victim")
if err != nil {
return "", err
}
@@ -1078,7 +1076,6 @@ func TestBasic(t *testing.T) {
// TestRandom tests that randomly generated rules are encoded correctly.
func TestRandom(t *testing.T) {
rand.Seed(time.Now().UnixNano())
size := rand.Intn(50) + 1
syscallRules := NewSyscallRules()
for syscallRules.Size() < size {
+3 -4
View File
@@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"math"
"testing"
)
@@ -63,7 +62,7 @@ func newBufferString(s string) *buffer {
func TestOffsetReader(t *testing.T) {
buf := newBufferString("foobar")
r := NewOffsetReader(buf, 3)
dst, err := ioutil.ReadAll(r)
dst, err := io.ReadAll(r)
if want := []byte("bar"); !bytes.Equal(dst, want) || err != nil {
t.Errorf("ReadAll: got (%q, %v), wanted (%q, nil)", dst, err, want)
}
@@ -72,7 +71,7 @@ func TestOffsetReader(t *testing.T) {
func TestSectionReader(t *testing.T) {
buf := newBufferString("foobarbaz")
r := NewSectionReader(buf, 3, 3)
dst, err := ioutil.ReadAll(r)
dst, err := io.ReadAll(r)
if want, wantErr := []byte("bar"), ErrReachedLimit; !bytes.Equal(dst, want) || err != wantErr {
t.Errorf("ReadAll: got (%q, %v), wanted (%q, %v)", dst, err, want, wantErr)
}
@@ -82,7 +81,7 @@ func TestSectionReaderLimitOverflow(t *testing.T) {
// SectionReader behaves like OffsetReader when limit overflows int64.
buf := newBufferString("foobar")
r := NewSectionReader(buf, 3, math.MaxInt64)
dst, err := ioutil.ReadAll(r)
dst, err := io.ReadAll(r)
if want := []byte("bar"); !bytes.Equal(dst, want) || err != nil {
t.Errorf("ReadAll: got (%q, %v), wanted (%q, nil)", dst, err, want)
}
+2 -2
View File
@@ -18,7 +18,7 @@ package hostcpu
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"unicode"
@@ -33,7 +33,7 @@ func GetCPU() uint32
// not to change for the lifetime of the host kernel.
func MaxPossibleCPU() (uint32, error) {
const path = "/sys/devices/system/cpu/possible"
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return 0, err
}
+2 -2
View File
@@ -16,7 +16,7 @@ package platform
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@@ -47,7 +47,7 @@ func (*MMapMinAddr) MinUserAddress() hostarch.Addr {
func init() {
// Open the source file.
b, err := ioutil.ReadFile(systemMMapMinAddrSource)
b, err := os.ReadFile(systemMMapMinAddrSource)
if err != nil {
panic(fmt.Sprintf("couldn't open %s: %v", systemMMapMinAddrSource, err))
}
@@ -16,7 +16,6 @@
package test
import (
"io/ioutil"
"os"
"path/filepath"
@@ -53,7 +52,7 @@ type Message struct {
// NewServer creates a new server that listens to a UDS that it creates under
// os.TempDir.
func NewServer() (*Server, error) {
dir, err := ioutil.TempDir(os.TempDir(), "remote")
dir, err := os.MkdirTemp(os.TempDir(), "remote")
if err != nil {
return nil, err
}
+2 -3
View File
@@ -17,7 +17,6 @@ package hostinet
import (
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
"strconv"
@@ -93,7 +92,7 @@ func (s *Stack) Configure(allowRawSockets bool) error {
// SACK is important for performance and even compatibility, assume it's
// enabled if we can't find the actual value.
s.tcpSACKEnabled = true
if sack, err := ioutil.ReadFile("/proc/sys/net/ipv4/tcp_sack"); err == nil {
if sack, err := os.ReadFile("/proc/sys/net/ipv4/tcp_sack"); err == nil {
s.tcpSACKEnabled = strings.TrimSpace(string(sack)) != "0"
} else {
log.Warningf("Failed to read if TCP SACK if enabled, setting to true")
@@ -120,7 +119,7 @@ func (s *Stack) Configure(allowRawSockets bool) error {
}
func readTCPBufferSizeFile(filename string) (inet.TCPBufferSize, error) {
contents, err := ioutil.ReadFile(filename)
contents, err := os.ReadFile(filename)
if err != nil {
return inet.TCPBufferSize{}, fmt.Errorf("failed to read %s: %v", filename, err)
}
+1 -2
View File
@@ -29,7 +29,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"math"
"reflect"
"time"
@@ -2745,7 +2744,7 @@ func (s *sock) nonBlockingRead(ctx context.Context, dst usermem.IOSequence, peek
if !isPacket && trunc {
w = &tcpip.LimitedWriter{
W: ioutil.Discard,
W: io.Discard,
N: dst.NumBytes(),
}
res, err = s.Endpoint.Read(w, readOptions)
+3 -3
View File
@@ -16,7 +16,7 @@ package runsc
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)
@@ -32,7 +32,7 @@ type state struct {
}
func (s state) load(path string) error {
data, err := ioutil.ReadFile(filepath.Join(path, filename))
data, err := os.ReadFile(filepath.Join(path, filename))
if err != nil {
return err
}
@@ -44,5 +44,5 @@ func (s state) save(path string) error {
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(path, filename), data, 0644)
return os.WriteFile(filepath.Join(path, filename), data, 0644)
}
+1 -2
View File
@@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -319,7 +318,7 @@ func (o *ExecOpts) args() (out []string, err error) {
// Exec executes an additional process inside the container based on a full OCI
// Process specification.
func (r *Runsc) Exec(context context.Context, id string, spec specs.Process, opts *ExecOpts) error {
f, err := ioutil.TempFile(os.Getenv("XDG_RUNTIME_DIR"), "runsc-process")
f, err := os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), "runsc-process")
if err != nil {
return err
}
+3 -3
View File
@@ -17,7 +17,7 @@ package utils
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -27,7 +27,7 @@ const configFilename = "config.json"
// ReadSpec reads OCI spec from the bundle directory.
func ReadSpec(bundle string) (*specs.Spec, error) {
b, err := ioutil.ReadFile(filepath.Join(bundle, configFilename))
b, err := os.ReadFile(filepath.Join(bundle, configFilename))
if err != nil {
return nil, err
}
@@ -44,7 +44,7 @@ func WriteSpec(bundle string, spec *specs.Spec) error {
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(bundle, configFilename), b, 0666)
return os.WriteFile(filepath.Join(bundle, configFilename), b, 0666)
}
// IsSandbox checks whether a container is a sandbox container.

Some files were not shown because too many files have changed in this diff Show More