diff --git a/adapter/outbound/socks5.go b/adapter/outbound/socks5.go index 1402c618..d9739557 100644 --- a/adapter/outbound/socks5.go +++ b/adapter/outbound/socks5.go @@ -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 diff --git a/adapter/provider/fetcher.go b/adapter/provider/fetcher.go index 777e3aa5..d3c85ab5 100644 --- a/adapter/provider/fetcher.go +++ b/adapter/provider/fetcher.go @@ -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 { diff --git a/adapter/provider/vehicle.go b/adapter/provider/vehicle.go index f556e69c..4f08c317 100644 --- a/adapter/provider/vehicle.go +++ b/adapter/provider/vehicle.go @@ -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 } diff --git a/component/process/process_linux.go b/component/process/process_linux.go index fabe969c..f77c1059 100644 --- a/component/process/process_linux.go +++ b/component/process/process_linux.go @@ -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 } diff --git a/component/profile/cachefile/cache.go b/component/profile/cachefile/cache.go index 28b05ee0..a9d1bc5b 100644 --- a/component/profile/cachefile/cache.go +++ b/component/profile/cachefile/cache.go @@ -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 } diff --git a/dns/doh.go b/dns/doh.go index 53b0fb33..3daa7f22 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -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 } diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 5c002b64..2147906f 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -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 } diff --git a/listener/socks/tcp.go b/listener/socks/tcp.go index 49d0a1e3..29016f5b 100644 --- a/listener/socks/tcp.go +++ b/listener/socks/tcp.go @@ -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)