Chore: remove deprecated ioutil

This commit is contained in:
gVisor bot 2021-10-09 20:35:06 +08:00
parent 90e2f5cb53
commit 0ebd7b6949
8 changed files with 21 additions and 21 deletions

View File

@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"strconv"
@ -116,7 +115,7 @@ func (ss *Socks5) DialUDP(metadata *C.Metadata) (_ C.PacketConn, err error) {
}
go func() {
io.Copy(ioutil.Discard, c)
io.Copy(io.Discard, c)
c.Close()
// A UDP association terminates when the TCP connection that the UDP
// ASSOCIATE request arrived on terminates. RFC1928

View File

@ -3,7 +3,6 @@ package provider
import (
"bytes"
"crypto/md5"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -45,7 +44,7 @@ func (f *fetcher) Initial() (interface{}, error) {
isLocal bool
)
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil {
buf, err = ioutil.ReadFile(f.vehicle.Path())
buf, err = os.ReadFile(f.vehicle.Path())
modTime := stat.ModTime()
f.updatedAt = &modTime
isLocal = true
@ -165,7 +164,7 @@ func safeWrite(path string, buf []byte) error {
}
}
return ioutil.WriteFile(path, buf, fileMode)
return os.WriteFile(path, buf, fileMode)
}
func newFetcher(name string, interval time.Duration, vehicle types.Vehicle, parser parser, onUpdate func(interface{})) *fetcher {

View File

@ -2,10 +2,11 @@ package provider
import (
"context"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
"os"
"time"
"github.com/Dreamacro/clash/component/dialer"
@ -25,7 +26,7 @@ func (f *FileVehicle) Path() string {
}
func (f *FileVehicle) Read() ([]byte, error) {
return ioutil.ReadFile(f.path)
return os.ReadFile(f.path)
}
func NewFileVehicle(path string) *FileVehicle {
@ -84,7 +85,7 @@ func (h *HTTPVehicle) Read() ([]byte, error) {
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View File

@ -5,8 +5,8 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path"
"path/filepath"
"syscall"
@ -167,7 +167,7 @@ func unpackSocketDiagResponse(msg *syscall.NetlinkMessage) (inode, uid uint32) {
}
func resolveProcessNameByProcSearch(inode, uid int) (string, error) {
files, err := ioutil.ReadDir(pathProc)
files, err := os.ReadDir(pathProc)
if err != nil {
return "", err
}
@ -180,14 +180,18 @@ func resolveProcessNameByProcSearch(inode, uid int) (string, error) {
continue
}
if f.Sys().(*syscall.Stat_t).Uid != uint32(uid) {
info, err := f.Info()
if err != nil {
return "", err
}
if info.Sys().(*syscall.Stat_t).Uid != uint32(uid) {
continue
}
processPath := path.Join(pathProc, f.Name())
fdPath := path.Join(processPath, "fd")
fds, err := ioutil.ReadDir(fdPath)
fds, err := os.ReadDir(fdPath)
if err != nil {
continue
}
@ -199,7 +203,7 @@ func resolveProcessNameByProcSearch(inode, uid int) (string, error) {
}
if bytes.Equal(buffer[:n], socket) {
cmdline, err := ioutil.ReadFile(path.Join(processPath, "cmdline"))
cmdline, err := os.ReadFile(path.Join(processPath, "cmdline"))
if err != nil {
return "", err
}

View File

@ -3,7 +3,6 @@ package cachefile
import (
"bytes"
"encoding/gob"
"io/ioutil"
"os"
"sync"
"time"
@ -88,7 +87,7 @@ func migrateCache() {
}
}()
buf, err := ioutil.ReadFile(C.Path.OldCache())
buf, err := os.ReadFile(C.Path.OldCache())
if err != nil {
return
}

View File

@ -3,7 +3,7 @@ package dns
import (
"bytes"
"context"
"io/ioutil"
"io"
"net"
"net/http"
@ -68,7 +68,7 @@ func (dc *dohClient) doRequest(req *http.Request) (msg *D.Msg, err error) {
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

View File

@ -2,7 +2,6 @@ package executor
import (
"fmt"
"io/ioutil"
"os"
"sync"
@ -33,7 +32,7 @@ func readConfig(path string) ([]byte, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, err
}
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}

View File

@ -2,7 +2,6 @@ package socks
import (
"io"
"io/ioutil"
"net"
"github.com/Dreamacro/clash/adapter/inbound"
@ -102,7 +101,7 @@ func HandleSocks5(conn net.Conn, in chan<- C.ConnContext) {
}
if command == socks5.CmdUDPAssociate {
defer conn.Close()
io.Copy(ioutil.Discard, conn)
io.Copy(io.Discard, conn)
return
}
in <- inbound.NewSocket(target, conn, C.SOCKS5)