Merge pull request #5973 from Juneezee/deprecate-ioutil
refactor: move from io/ioutil to io and os package
This commit is contained in:
@@ -18,7 +18,6 @@ package introspection
|
||||
|
||||
import (
|
||||
context "context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
@@ -114,7 +113,7 @@ func (l *Local) getUUID() (string, error) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
|
||||
data, err := ioutil.ReadFile(l.uuidPath())
|
||||
data, err := os.ReadFile(l.uuidPath())
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return l.generateUUID()
|
||||
@@ -138,7 +137,7 @@ func (l *Local) generateUUID() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
uu := u.String()
|
||||
if err := ioutil.WriteFile(path, []byte(uu), 0666); err != nil {
|
||||
if err := os.WriteFile(path, []byte(uu), 0666); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return uu, nil
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -62,12 +61,12 @@ func TestMergeConfigs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResolveImports(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
for _, filename := range []string{"config_1.toml", "config_2.toml", "test.toml"} {
|
||||
err = ioutil.WriteFile(filepath.Join(tempDir, filename), []byte(""), 0600)
|
||||
err = os.WriteFile(filepath.Join(tempDir, filename), []byte(""), 0600)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@@ -96,12 +95,12 @@ root = "/var/lib/containerd"
|
||||
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
|
||||
path = "unpigz"
|
||||
`
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
path := filepath.Join(tempDir, "config.toml")
|
||||
err = ioutil.WriteFile(path, []byte(data), 0600)
|
||||
err = os.WriteFile(path, []byte(data), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
var out Config
|
||||
@@ -128,14 +127,14 @@ imports = ["data2.toml"]
|
||||
disabled_plugins = ["io.containerd.v1.xyz"]
|
||||
`
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
||||
err = os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
||||
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
var out Config
|
||||
@@ -158,14 +157,14 @@ imports = ["data2.toml", "data1.toml"]
|
||||
disabled_plugins = ["io.containerd.v1.xyz"]
|
||||
imports = ["data1.toml", "data2.toml"]
|
||||
`
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
||||
err = os.WriteFile(filepath.Join(tempDir, "data1.toml"), []byte(data1), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
||||
err = os.WriteFile(filepath.Join(tempDir, "data2.toml"), []byte(data2), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
var out Config
|
||||
@@ -190,12 +189,12 @@ version = 2
|
||||
shim_debug = true
|
||||
`
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
path := filepath.Join(tempDir, "config.toml")
|
||||
err = ioutil.WriteFile(path, []byte(data), 0600)
|
||||
err = os.WriteFile(path, []byte(data), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
var out Config
|
||||
@@ -216,12 +215,12 @@ func TestDecodePluginInV1Config(t *testing.T) {
|
||||
shim_debug = true
|
||||
`
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
tempDir, err := os.MkdirTemp("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
path := filepath.Join(tempDir, "config.toml")
|
||||
err = ioutil.WriteFile(path, []byte(data), 0600)
|
||||
err = os.WriteFile(path, []byte(data), 0600)
|
||||
assert.NilError(t, err)
|
||||
|
||||
var out Config
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"crypto/x509"
|
||||
"expvar"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
@@ -131,7 +130,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
||||
|
||||
if config.GRPC.TCPTLSCA != "" {
|
||||
caCertPool := x509.NewCertPool()
|
||||
caCert, err := ioutil.ReadFile(config.GRPC.TCPTLSCA)
|
||||
caCert, err := os.ReadFile(config.GRPC.TCPTLSCA)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to load CA file")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -154,7 +153,7 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
|
||||
}
|
||||
// jump get checkpointPath from checkpoint image
|
||||
if checkpointPath == "" && r.Checkpoint != nil {
|
||||
checkpointPath, err = ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "ctrd-checkpoint")
|
||||
checkpointPath, err = os.MkdirTemp(os.Getenv("XDG_RUNTIME_DIR"), "ctrd-checkpoint")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -538,7 +537,7 @@ func (l *local) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest, _
|
||||
checkpointImageExists := false
|
||||
if image == "" {
|
||||
checkpointImageExists = true
|
||||
image, err = ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "ctd-checkpoint")
|
||||
image, err = os.MkdirTemp(os.Getenv("XDG_RUNTIME_DIR"), "ctd-checkpoint")
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user