1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

chore: remove refs to deprecated io/ioutil (#2717)

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guangwu 2023-10-16 10:23:50 +08:00 committed by GitHub
parent b617c97342
commit 39d2f293c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"io" "io"
"io/ioutil"
"os" "os"
"testing" "testing"
@ -120,7 +119,7 @@ func TestMultiBufferReadAllToByte(t *testing.T) {
common.Must(err) common.Must(err)
f.Close() f.Close()
cnt, err := ioutil.ReadFile(dat) cnt, err := os.ReadFile(dat)
common.Must(err) common.Must(err)
if d := cmp.Diff(buf2, cnt); d != "" { if d := cmp.Diff(buf2, cnt); d != "" {

View File

@ -3,7 +3,7 @@ package cmdarg
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil" "os"
) )
// LoadArg loads one arg, maybe an remote url, or local file path // LoadArg loads one arg, maybe an remote url, or local file path
@ -18,7 +18,7 @@ func LoadArg(arg string) (out io.Reader, err error) {
// LoadArgToBytes loads one arg to []byte, maybe an remote url, or local file path // LoadArgToBytes loads one arg to []byte, maybe an remote url, or local file path
func LoadArgToBytes(arg string) (out []byte, err error) { func LoadArgToBytes(arg string) (out []byte, err error) {
out, err = ioutil.ReadFile(arg) out, err = os.ReadFile(arg)
if err != nil { if err != nil {
return return
} }

View File

@ -1,7 +1,6 @@
package log_test package log_test
import ( import (
"io/ioutil"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -13,7 +12,7 @@ import (
) )
func TestFileLogger(t *testing.T) { func TestFileLogger(t *testing.T) {
f, err := ioutil.TempFile("", "vtest") f, err := os.CreateTemp("", "vtest")
common.Must(err) common.Must(err)
path := f.Name() path := f.Name()
common.Must(f.Close()) common.Must(f.Close())

View File

@ -1,7 +1,7 @@
package memconservative package memconservative
import ( import (
"io/ioutil" "os"
"strings" "strings"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -53,7 +53,7 @@ func (g GeoIPCache) Unmarshal(filename, code string) (*routercommon.GeoIP, error
case errFailedToReadBytes, errFailedToReadExpectedLenBytes, case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength: errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method") newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geoipBytes, err = ioutil.ReadFile(asset) geoipBytes, err = os.ReadFile(asset)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -118,7 +118,7 @@ func (g GeoSiteCache) Unmarshal(filename, code string) (*routercommon.GeoSite, e
case errFailedToReadBytes, errFailedToReadExpectedLenBytes, case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength: errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method") newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geositeBytes, err = ioutil.ReadFile(asset) geositeBytes, err = os.ReadFile(asset)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"go/build" "go/build"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -48,7 +47,7 @@ func GetRuntimeEnv(key string) (string, error) {
} }
var data []byte var data []byte
var runtimeEnv string var runtimeEnv string
data, readErr := ioutil.ReadFile(file) data, readErr := os.ReadFile(file)
if readErr != nil { if readErr != nil {
return "", readErr return "", readErr
} }

View File

@ -2,7 +2,6 @@ package helpers
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -10,7 +9,7 @@ import (
// ReadDir finds files according to extensions in the dir // ReadDir finds files according to extensions in the dir
func ReadDir(dir string, extensions []string) ([]string, error) { func ReadDir(dir string, extensions []string) ([]string, error) {
confs, err := ioutil.ReadDir(dir) confs, err := os.ReadDir(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -2,7 +2,6 @@ package commands
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -113,7 +112,7 @@ func dirExists(file string) bool {
} }
func readConfDir(dirPath string, extension []string) cmdarg.Arg { func readConfDir(dirPath string, extension []string) cmdarg.Arg {
confs, err := ioutil.ReadDir(dirPath) confs, err := os.ReadDir(dirPath)
if err != nil { if err != nil {
base.Fatalf("failed to read dir %s: %s", dirPath, err) base.Fatalf("failed to read dir %s: %s", dirPath, err)
} }