Merge pull request #5973 from Juneezee/deprecate-ioutil
refactor: move from io/ioutil to io and os package
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -147,7 +146,7 @@ func WithSpecFromBytes(p []byte) SpecOpts {
|
||||
// WithSpecFromFile loads the specification from the provided filename.
|
||||
func WithSpecFromFile(filename string) SpecOpts {
|
||||
return func(ctx context.Context, c Client, container *containers.Container, s *Spec) error {
|
||||
p, err := ioutil.ReadFile(filename)
|
||||
p, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "cannot load spec config file")
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package oci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -115,14 +114,14 @@ func TestDropCaps(t *testing.T) {
|
||||
func TestGetDevices(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
|
||||
dir, err := ioutil.TempDir("/dev", t.Name())
|
||||
dir, err := os.MkdirTemp("/dev", t.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
zero := filepath.Join(dir, "zero")
|
||||
if err := ioutil.WriteFile(zero, nil, 0600); err != nil {
|
||||
if err := os.WriteFile(zero, nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -162,7 +161,7 @@ func TestGetDevices(t *testing.T) {
|
||||
})
|
||||
t.Run("two devices", func(t *testing.T) {
|
||||
nullDev := filepath.Join(dir, "null")
|
||||
if err := ioutil.WriteFile(nullDev, nil, 0600); err != nil {
|
||||
if err := os.WriteFile(nullDev, nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -237,7 +236,7 @@ func TestGetDevices(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("regular file in dir", func(t *testing.T) {
|
||||
if err := ioutil.WriteFile(filepath.Join(dir, "somefile"), []byte("hello"), 0600); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dir, "somefile"), []byte("hello"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(filepath.Join(dir, "somefile"))
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -327,7 +326,7 @@ func TestWithSpecFromFile(t *testing.T) {
|
||||
ctx = namespaces.WithNamespace(context.Background(), "test")
|
||||
)
|
||||
|
||||
fp, err := ioutil.TempFile("", "testwithdefaultspec.json")
|
||||
fp, err := os.CreateTemp("", "testwithdefaultspec.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package oci
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -53,7 +52,7 @@ func getDevices(path, containerPath string) ([]specs.LinuxDevice, error) {
|
||||
return []specs.LinuxDevice{*dev}, nil
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user