Skip to content

Commit 7021321

Browse files
authored
Merge pull request #180 from marquiz/devel/ioutil
chore: stop using deprecated io/ioutil package
2 parents 57c92f8 + 1beff81 commit 7021321

File tree

7 files changed

+13
-17
lines changed

7 files changed

+13
-17
lines changed

cmd/cdi/cmd/inject.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package cmd
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"os"
2323

2424
oci "github.com/opencontainers/runtime-spec/specs-go"
@@ -66,9 +66,9 @@ func readOCISpec(path string) (*oci.Spec, error) {
6666
)
6767

6868
if path == "-" {
69-
data, err = ioutil.ReadAll(os.Stdin)
69+
data, err = io.ReadAll(os.Stdin)
7070
} else {
71-
data, err = ioutil.ReadFile(path)
71+
data, err = os.ReadFile(path)
7272
}
7373

7474
if err != nil {

cmd/validate/validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package main
2222
import (
2323
"flag"
2424
"fmt"
25-
"io/ioutil"
25+
"io"
2626
"os"
2727

2828
"tags.cncf.io/container-device-interface/schema"
@@ -80,7 +80,7 @@ func main() {
8080
for _, docFile = range docs {
8181
if docFile == "" || docFile == "-" {
8282
docFile = "<stdin>"
83-
docData, err = ioutil.ReadAll(os.Stdin)
83+
docData, err = io.ReadAll(os.Stdin)
8484
if err != nil {
8585
fmt.Fprintf(os.Stderr, "failed to read document data from stdin: %v\n", err)
8686
os.Exit(1)

pkg/cdi/spec-dirs_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package cdi
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"testing"
@@ -212,7 +211,7 @@ devices:
212211

213212
// Create an automatically cleaned up temporary directory, with optional content.
214213
func mkTestDir(t *testing.T, dirs map[string]map[string]string) (string, error) {
215-
tmp, err := ioutil.TempDir("", ".cache-test*")
214+
tmp, err := os.MkdirTemp("", ".cache-test*")
216215
if err != nil {
217216
return "", fmt.Errorf("failed to create test directory: %w", err)
218217
}
@@ -237,7 +236,7 @@ func updateTestDir(t *testing.T, tmp string, dirs map[string]map[string]string)
237236
for file, data := range content {
238237
file := filepath.Join(dir, file)
239238
tmp := file + ".tmp"
240-
if err := ioutil.WriteFile(tmp, []byte(data), 0644); err != nil {
239+
if err := os.WriteFile(tmp, []byte(data), 0644); err != nil {
241240
return fmt.Errorf("failed to write file %q: %w", tmp, err)
242241
}
243242
if err := os.Rename(tmp, file); err != nil {

pkg/cdi/spec.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package cdi
1919
import (
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524
"strings"
@@ -62,7 +61,7 @@ type Spec struct {
6261
// assigned the given priority. If reading or parsing the Spec
6362
// data fails ReadSpec returns a nil Spec and an error.
6463
func ReadSpec(path string, priority int) (*Spec, error) {
65-
data, err := ioutil.ReadFile(path)
64+
data, err := os.ReadFile(path)
6665
switch {
6766
case os.IsNotExist(err):
6867
return nil, err

pkg/cdi/spec_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package cdi
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"strings"
@@ -496,7 +495,7 @@ devices:
496495

497496
// Create an automatically cleaned up temporary file for a test.
498497
func mkTestSpec(t *testing.T, data []byte) (string, error) {
499-
tmp, err := ioutil.TempFile("", ".cdi-test.*."+specType(data))
498+
tmp, err := os.CreateTemp("", ".cdi-test.*."+specType(data))
500499
if err != nil {
501500
return "", fmt.Errorf("failed to create test file: %w", err)
502501
}

schema/schema.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
26+
"os"
2727
"path/filepath"
2828
"strings"
2929

@@ -158,7 +158,7 @@ func Load(source string) (*Schema, error) {
158158
// ReadAndValidate all data from the given reader, using the schema for validation.
159159
func (s *Schema) ReadAndValidate(r io.Reader) ([]byte, error) {
160160
loader, reader := schema.NewReaderLoader(r)
161-
data, err := ioutil.ReadAll(reader)
161+
data, err := io.ReadAll(reader)
162162
if err != nil {
163163
return nil, fmt.Errorf("failed to read data for validation: %w", err)
164164
}
@@ -202,7 +202,7 @@ func (s *Schema) ValidateFile(path string) error {
202202
return s.validate(schema.NewReferenceLoader("file://" + path))
203203
}
204204

205-
data, err := ioutil.ReadFile(path)
205+
data, err := os.ReadFile(path)
206206
if err != nil {
207207
return err
208208
}

schema/schema_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"io"
2222
"io/fs"
23-
"io/ioutil"
2423
"os"
2524
"path/filepath"
2625
"testing"
@@ -269,7 +268,7 @@ func validateFile(t *testing.T, scm *schema.Schema, path string, shouldLoad, isV
269268
}
270269

271270
func validateData(t *testing.T, scm *schema.Schema, path string, shouldLoad, isValid bool) {
272-
data, err := ioutil.ReadFile(path)
271+
data, err := os.ReadFile(path)
273272
require.NoError(t, err)
274273

275274
if scm != nil {

0 commit comments

Comments
 (0)