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

View file

@ -3,7 +3,6 @@ package provider
import ( import (
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -45,7 +44,7 @@ func (f *fetcher) Initial() (interface{}, error) {
isLocal bool isLocal bool
) )
if stat, fErr := os.Stat(f.vehicle.Path()); fErr == nil { 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() modTime := stat.ModTime()
f.updatedAt = &modTime f.updatedAt = &modTime
isLocal = true 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 { 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 ( import (
"context" "context"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"os"
"time" "time"
"github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/dialer"
@ -25,7 +26,7 @@ func (f *FileVehicle) Path() string {
} }
func (f *FileVehicle) Read() ([]byte, error) { func (f *FileVehicle) Read() ([]byte, error) {
return ioutil.ReadFile(f.path) return os.ReadFile(f.path)
} }
func NewFileVehicle(path string) *FileVehicle { func NewFileVehicle(path string) *FileVehicle {
@ -84,7 +85,7 @@ func (h *HTTPVehicle) Read() ([]byte, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body) buf, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

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

View file

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

View file

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

View file

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

View file

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