refactor: move from io/ioutil to io and os package

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun 2021-09-10 20:28:11 +08:00
parent c16be1a5e2
commit 50da673592
No known key found for this signature in database
GPG Key ID: DAEBBD2E34C111E6
126 changed files with 291 additions and 399 deletions

View File

@ -21,7 +21,6 @@ import (
"compress/gzip"
"context"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -80,7 +79,7 @@ func testCompressDecompress(t *testing.T, size int, compression Compression) Dec
if err != nil {
t.Fatal(err)
}
decompressed, err := ioutil.ReadAll(decompressor)
decompressed, err := io.ReadAll(decompressor)
if err != nil {
t.Fatal(err)
}
@ -123,7 +122,7 @@ func TestCompressDecompressUncompressed(t *testing.T) {
func TestDetectPigz(t *testing.T) {
// Create fake PATH with unpigz executable, make sure detectPigz can find it
tempPath, err := ioutil.TempDir("", "containerd_temp_")
tempPath, err := os.MkdirTemp("", "containerd_temp_")
if err != nil {
t.Fatal(err)
}
@ -135,7 +134,7 @@ func TestDetectPigz(t *testing.T) {
fullPath := filepath.Join(tempPath, filename)
if err := ioutil.WriteFile(fullPath, []byte(""), 0111); err != nil {
if err := os.WriteFile(fullPath, []byte(""), 0111); err != nil {
t.Fatal(err)
}
@ -165,7 +164,7 @@ func TestCmdStream(t *testing.T) {
t.Fatal(err)
}
buf, err := ioutil.ReadAll(out)
buf, err := io.ReadAll(out)
if err != nil {
t.Fatalf("failed to read from stdout: %s", err)
}
@ -181,7 +180,7 @@ func TestCmdStreamBad(t *testing.T) {
t.Fatalf("failed to start command: %v", err)
}
if buf, err := ioutil.ReadAll(out); err == nil {
if buf, err := io.ReadAll(out); err == nil {
t.Fatal("command should have failed")
} else if err.Error() != "exit status 1: bad result\n" {
t.Fatalf("wrong error: %s", err.Error())

View File

@ -19,7 +19,6 @@ package archive
import (
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -37,7 +36,7 @@ func TestPrefixHeaderReadable(t *testing.T) {
// https://gist.github.com/stevvooe/e2a790ad4e97425896206c0816e1a882#file-out-go
var testFile = []byte("\x1f\x8b\x08\x08\x44\x21\x68\x59\x00\x03\x74\x2e\x74\x61\x72\x00\x4b\xcb\xcf\x67\xa0\x35\x30\x80\x00\x86\x06\x10\x47\x01\xc1\x37\x40\x00\x54\xb6\xb1\xa1\xa9\x99\x09\x48\x25\x1d\x40\x69\x71\x49\x62\x91\x02\xe5\x76\xa1\x79\x84\x21\x91\xd6\x80\x72\xaf\x8f\x82\x51\x30\x0a\x46\x36\x00\x00\xf0\x1c\x1e\x95\x00\x06\x00\x00")
tmpDir, err := ioutil.TempDir("", "prefix-test")
tmpDir, err := os.MkdirTemp("", "prefix-test")
if err != nil {
t.Fatal(err)
}

View File

@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"testing"
@ -38,7 +37,7 @@ import (
func TestOverlayApply(t *testing.T) {
testutil.RequiresRoot(t)
base, err := ioutil.TempDir("", "test-ovl-diff-apply-")
base, err := os.MkdirTemp("", "test-ovl-diff-apply-")
if err != nil {
t.Fatalf("unable to create temp dir: %+v", err)
}
@ -57,7 +56,7 @@ func TestOverlayApply(t *testing.T) {
func TestOverlayApplyNoParents(t *testing.T) {
testutil.RequiresRoot(t)
base, err := ioutil.TempDir("", "test-ovl-diff-apply-")
base, err := os.MkdirTemp("", "test-ovl-diff-apply-")
if err != nil {
t.Fatalf("unable to create temp dir: %+v", err)
}
@ -96,7 +95,7 @@ type overlayContext struct {
type contextKey struct{}
func (d overlayDiffApplier) TestContext(ctx context.Context) (context.Context, func(), error) {
merged, err := ioutil.TempDir(d.tmp, "merged")
merged, err := os.MkdirTemp(d.tmp, "merged")
if err != nil {
return ctx, nil, errors.Wrap(err, "failed to make merged dir")
}
@ -117,7 +116,7 @@ func (d overlayDiffApplier) TestContext(ctx context.Context) (context.Context, f
func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string, func(), error) {
oc := ctx.Value(contextKey{}).(*overlayContext)
applyCopy, err := ioutil.TempDir(d.tmp, "apply-copy-")
applyCopy, err := os.MkdirTemp(d.tmp, "apply-copy-")
if err != nil {
return "", nil, errors.Wrap(err, "failed to create temp dir")
}
@ -149,7 +148,7 @@ func (d overlayDiffApplier) Apply(ctx context.Context, a fstest.Applier) (string
oc.mounted = false
}
next, err := ioutil.TempDir(d.tmp, "lower-")
next, err := os.MkdirTemp(d.tmp, "lower-")
if err != nil {
return "", nil, errors.Wrap(err, "failed to create temp dir")
}

View File

@ -25,7 +25,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -234,7 +233,7 @@ func TestBreakouts(t *testing.T) {
tc := tartest.TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
expected := "unbroken"
unbrokenCheck := func(root string) error {
b, err := ioutil.ReadFile(filepath.Join(root, "etc", "unbroken"))
b, err := os.ReadFile(filepath.Join(root, "etc", "unbroken"))
if err != nil {
return errors.Wrap(err, "failed to read unbroken")
}
@ -244,7 +243,7 @@ func TestBreakouts(t *testing.T) {
return nil
}
errFileDiff := errors.New("files differ")
td, err := ioutil.TempDir("", "test-breakouts-")
td, err := os.MkdirTemp("", "test-breakouts-")
if err != nil {
t.Fatal(err)
}
@ -331,7 +330,7 @@ func TestBreakouts(t *testing.T) {
}
fileValue := func(f1 string, content []byte) func(string) error {
return func(root string) error {
b, err := ioutil.ReadFile(filepath.Join(root, f1))
b, err := os.ReadFile(filepath.Join(root, f1))
if err != nil {
return err
}
@ -421,7 +420,7 @@ func TestBreakouts(t *testing.T) {
tc.File("/localetc/emptied", []byte{}, 0644),
),
validator: func(root string) error {
b, err := ioutil.ReadFile(filepath.Join(root, "etc", "emptied"))
b, err := os.ReadFile(filepath.Join(root, "etc", "emptied"))
if err != nil {
return errors.Wrap(err, "failed to read unbroken")
}
@ -755,11 +754,11 @@ func TestBreakouts(t *testing.T) {
name: "HardlinkSymlinkChmod",
w: func() tartest.WriterToTar {
p := filepath.Join(td, "perm400")
if err := ioutil.WriteFile(p, []byte("..."), 0400); err != nil {
if err := os.WriteFile(p, []byte("..."), 0400); err != nil {
t.Fatal(err)
}
ep := filepath.Join(td, "also-exists-outside-root")
if err := ioutil.WriteFile(ep, []byte("..."), 0640); err != nil {
if err := os.WriteFile(ep, []byte("..."), 0640); err != nil {
t.Fatal(err)
}
@ -843,12 +842,12 @@ func TestApplyTar(t *testing.T) {
}
func testApply(a fstest.Applier) error {
td, err := ioutil.TempDir("", "test-apply-")
td, err := os.MkdirTemp("", "test-apply-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
defer os.RemoveAll(td)
dest, err := ioutil.TempDir("", "test-apply-dest-")
dest, err := os.MkdirTemp("", "test-apply-dest-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
@ -884,12 +883,12 @@ func testApply(a fstest.Applier) error {
}
func testBaseDiff(a fstest.Applier) error {
td, err := ioutil.TempDir("", "test-base-diff-")
td, err := os.MkdirTemp("", "test-base-diff-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
defer os.RemoveAll(td)
dest, err := ioutil.TempDir("", "test-base-diff-dest-")
dest, err := os.MkdirTemp("", "test-base-diff-dest-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
@ -911,12 +910,12 @@ func testBaseDiff(a fstest.Applier) error {
}
func testDiffApply(appliers ...fstest.Applier) error {
td, err := ioutil.TempDir("", "test-diff-apply-")
td, err := os.MkdirTemp("", "test-diff-apply-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
defer os.RemoveAll(td)
dest, err := ioutil.TempDir("", "test-diff-apply-dest-")
dest, err := os.MkdirTemp("", "test-diff-apply-dest-")
if err != nil {
return errors.Wrap(err, "failed to create temp dir")
}
@ -937,7 +936,7 @@ func testDiffApply(appliers ...fstest.Applier) error {
}
}
diffBytes, err := ioutil.ReadAll(Diff(context.Background(), dest, td))
diffBytes, err := io.ReadAll(Diff(context.Background(), dest, td))
if err != nil {
return errors.Wrap(err, "failed to create diff")
}
@ -951,7 +950,7 @@ func testDiffApply(appliers ...fstest.Applier) error {
func makeWriterToTarTest(wt tartest.WriterToTar, a fstest.Applier, validate func(string) error, applyErr error) func(*testing.T) {
return func(t *testing.T) {
td, err := ioutil.TempDir("", "test-writer-to-tar-")
td, err := os.MkdirTemp("", "test-writer-to-tar-")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
@ -1255,7 +1254,7 @@ func whiteoutEntry(name string) tarEntryValidator {
func makeDiffTarTest(validators []tarEntryValidator, a, b fstest.Applier) func(*testing.T) {
return func(t *testing.T) {
ad, err := ioutil.TempDir("", "test-make-diff-tar-")
ad, err := os.MkdirTemp("", "test-make-diff-tar-")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
@ -1264,7 +1263,7 @@ func makeDiffTarTest(validators []tarEntryValidator, a, b fstest.Applier) func(*
t.Fatalf("failed to apply a: %v", err)
}
bd, err := ioutil.TempDir("", "test-make-diff-tar-")
bd, err := os.MkdirTemp("", "test-make-diff-tar-")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
}
@ -1290,7 +1289,7 @@ func makeDiffTarTest(validators []tarEntryValidator, a, b fstest.Applier) func(*
}
var b []byte
if hdr.Typeflag == tar.TypeReg && hdr.Size > 0 {
b, err = ioutil.ReadAll(tr)
b, err = io.ReadAll(tr)
if err != nil {
t.Fatalf("tar read file error: %v", err)
}
@ -1308,7 +1307,7 @@ func makeDiffTarTest(validators []tarEntryValidator, a, b fstest.Applier) func(*
type diffApplier struct{}
func (d diffApplier) TestContext(ctx context.Context) (context.Context, func(), error) {
base, err := ioutil.TempDir("", "test-diff-apply-")
base, err := os.MkdirTemp("", "test-diff-apply-")
if err != nil {
return ctx, nil, errors.Wrap(err, "failed to create temp dir")
}
@ -1320,7 +1319,7 @@ func (d diffApplier) TestContext(ctx context.Context) (context.Context, func(),
func (d diffApplier) Apply(ctx context.Context, a fstest.Applier) (string, func(), error) {
base := ctx.Value(d).(string)
applyCopy, err := ioutil.TempDir("", "test-diffapply-apply-copy-")
applyCopy, err := os.MkdirTemp("", "test-diffapply-apply-copy-")
if err != nil {
return "", nil, errors.Wrap(err, "failed to create temp dir")
}
@ -1332,7 +1331,7 @@ func (d diffApplier) Apply(ctx context.Context, a fstest.Applier) (string, func(
return "", nil, errors.Wrap(err, "failed to apply changes to copy of base")
}
diffBytes, err := ioutil.ReadAll(Diff(ctx, base, applyCopy))
diffBytes, err := io.ReadAll(Diff(ctx, base, applyCopy))
if err != nil {
return "", nil, errors.Wrap(err, "failed to create diff")
}
@ -1345,7 +1344,7 @@ func (d diffApplier) Apply(ctx context.Context, a fstest.Applier) (string, func(
}
func readDirNames(p string) ([]string, error) {
fis, err := ioutil.ReadDir(p)
fis, err := os.ReadDir(p)
if err != nil {
return nil, err
}

View File

@ -23,7 +23,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@ -50,7 +49,7 @@ func TestNewFIFOSetInDir(t *testing.T) {
t.Skip("NewFIFOSetInDir has different behaviour on windows")
}
root, err := ioutil.TempDir("", "test-new-fifo-set")
root, err := os.MkdirTemp("", "test-new-fifo-set")
assert.NilError(t, err)
defer os.RemoveAll(root)
@ -69,12 +68,12 @@ func TestNewFIFOSetInDir(t *testing.T) {
}
assert.Assert(t, is.DeepEqual(fifos, expected, cmpFIFOSet))
files, err := ioutil.ReadDir(root)
files, err := os.ReadDir(root)
assert.NilError(t, err)
assert.Check(t, is.Len(files, 1))
assert.NilError(t, fifos.Close())
files, err = ioutil.ReadDir(root)
files, err = os.ReadDir(root)
assert.NilError(t, err)
assert.Check(t, is.Len(files, 0))
}
@ -102,19 +101,19 @@ func TestNewAttach(t *testing.T) {
fifos, err := NewFIFOSetInDir("", "theid", false)
assert.NilError(t, err)
io, err := attacher(fifos)
attachedFifos, err := attacher(fifos)
assert.NilError(t, err)
defer io.Close()
defer attachedFifos.Close()
producers := setupFIFOProducers(t, io.Config())
producers := setupFIFOProducers(t, attachedFifos.Config())
initProducers(t, producers, expectedStdout, expectedStderr)
actualStdin, err := ioutil.ReadAll(producers.Stdin)
actualStdin, err := io.ReadAll(producers.Stdin)
assert.NilError(t, err)
io.Wait()
io.Cancel()
assert.NilError(t, io.Close())
attachedFifos.Wait()
attachedFifos.Cancel()
assert.NilError(t, attachedFifos.Close())
assert.Check(t, is.Equal(expectedStdout, stdout.String()))
assert.Check(t, is.Equal(expectedStderr, stderr.String()))

View File

@ -22,7 +22,6 @@ package cio
import (
"context"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -39,7 +38,7 @@ func NewFIFOSetInDir(root, id string, terminal bool) (*FIFOSet, error) {
return nil, err
}
}
dir, err := ioutil.TempDir(root, "")
dir, err := os.MkdirTemp(root, "")
if err != nil {
return nil, err
}

View File

@ -22,7 +22,6 @@ package cio
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -66,7 +65,7 @@ func TestOpenFifosWithTerminal(t *testing.T) {
var ctx, cancel = context.WithCancel(context.Background())
defer cancel()
ioFifoDir, err := ioutil.TempDir("", fmt.Sprintf("cio-%s", t.Name()))
ioFifoDir, err := os.MkdirTemp("", fmt.Sprintf("cio-%s", t.Name()))
if err != nil {
t.Fatalf("unexpected error during creating temp dir: %v", err)
}

View File

@ -21,7 +21,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
@ -172,7 +171,7 @@ func getMaps(pid int) (map[string]int, error) {
}
func getppid(pid int) (int, error) {
bytes, err := ioutil.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
bytes, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(pid), "stat"))
if err != nil {
return 0, err
}

View File

@ -19,7 +19,7 @@ package command
import (
gocontext "context"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"os/signal"
@ -56,7 +56,7 @@ high performance container runtime
func init() {
// Discard grpc logs so that they don't mess with our stdio
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
cli.VersionPrinter = func(c *cli.Context) {
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)

View File

@ -19,7 +19,6 @@ package command
import (
gocontext "context"
"io"
"io/ioutil"
"net"
"os"
"time"
@ -73,7 +72,7 @@ var publishCommand = cli.Command{
}
func getEventPayload(r io.Reader) (*types.Any, error) {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}

View File

@ -18,7 +18,7 @@ package command
import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
@ -249,7 +249,7 @@ func registerUnregisterService(root string) (bool, error) {
return true, err
}
logOutput := ioutil.Discard
logOutput := io.Discard
if logFileFlag != "" {
f, err := os.OpenFile(logFileFlag, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {

View File

@ -18,7 +18,7 @@ package app
import (
"fmt"
"io/ioutil"
"io"
"github.com/containerd/containerd/cmd/ctr/commands/containers"
"github.com/containerd/containerd/cmd/ctr/commands/content"
@ -46,7 +46,7 @@ var extraCmds = []cli.Command{}
func init() {
// Discard grpc logs so that they don't mess with our stdio
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard))
cli.VersionPrinter = func(c *cli.Context) {
fmt.Println(c.App.Name, version.Package, c.App.Version)

View File

@ -19,7 +19,6 @@ package content
import (
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"text/tabwriter"
@ -519,7 +518,7 @@ func edit(context *cli.Context, rd io.Reader) (io.ReadCloser, error) {
return nil, fmt.Errorf("editor is required")
}
tmp, err := ioutil.TempFile(os.Getenv("XDG_RUNTIME_DIR"), "edit-")
tmp, err := os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), "edit-")
if err != nil {
return nil, err
}

View File

@ -23,10 +23,10 @@ import (
"crypto/x509"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptrace"
"net/http/httputil"
"os"
"strings"
"github.com/containerd/console"
@ -124,7 +124,7 @@ func resolverDefaultTLS(clicontext *cli.Context) (*tls.Config, error) {
}
if tlsRootPath := clicontext.String("tlscacert"); tlsRootPath != "" {
tlsRootData, err := ioutil.ReadFile(tlsRootPath)
tlsRootData, err := os.ReadFile(tlsRootPath)
if err != nil {
return nil, errors.Wrapf(err, "failed to read %q", tlsRootPath)
}

View File

@ -22,8 +22,8 @@ package shim
import (
gocontext "context"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"strings"
@ -174,7 +174,7 @@ var execCommand = cli.Command{
}
// read spec file and extract Any object
spec, err := ioutil.ReadFile(context.String("spec"))
spec, err := os.ReadFile(context.String("spec"))
if err != nil {
return err
}

View File

@ -19,7 +19,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -62,7 +61,7 @@ func run() error {
return err
}
_ = os.MkdirAll(dir, os.ModePerm)
if err := ioutil.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.%s", name, section)), []byte(data), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.%s", name, section)), []byte(data), 0644); err != nil {
return err
}
return nil

View File

@ -19,7 +19,6 @@ package content
import (
"context"
"io"
"io/ioutil"
"math/rand"
"sync"
"time"
@ -230,7 +229,7 @@ func seekReader(r io.Reader, offset, size int64) (io.Reader, error) {
}
// well then, let's just discard up to the offset
n, err := copyWithBuffer(ioutil.Discard, io.LimitReader(r, offset))
n, err := copyWithBuffer(io.Discard, io.LimitReader(r, offset))
if err != nil {
return nil, errors.Wrap(err, "failed to discard to offset")
}

View File

@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -568,7 +567,7 @@ func (s *store) writer(ctx context.Context, ref string, total int64, expected di
// the ingest is new, we need to setup the target location.
// write the ref to a file for later use
if err := ioutil.WriteFile(refp, []byte(ref), 0666); err != nil {
if err := os.WriteFile(refp, []byte(ref), 0666); err != nil {
return nil, err
}
@ -581,7 +580,7 @@ func (s *store) writer(ctx context.Context, ref string, total int64, expected di
}
if total > 0 {
if err := ioutil.WriteFile(filepath.Join(path, "total"), []byte(fmt.Sprint(total)), 0666); err != nil {
if err := os.WriteFile(filepath.Join(path, "total"), []byte(fmt.Sprint(total)), 0666); err != nil {
return nil, err
}
}
@ -656,13 +655,13 @@ func (s *store) ingestPaths(ref string) (string, string, string) {
}
func readFileString(path string) (string, error) {
p, err := ioutil.ReadFile(path)
p, err := os.ReadFile(path)
return string(p), err
}
// readFileTimestamp reads a file with just a timestamp present.
func readFileTimestamp(p string) (time.Time, error) {
b, err := ioutil.ReadFile(p)
b, err := os.ReadFile(p)
if err != nil {
if os.IsNotExist(err) {
err = errors.Wrap(errdefs.ErrNotFound, err.Error())

View File

@ -23,7 +23,6 @@ import (
_ "crypto/sha256" // required for digest package
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -158,7 +157,7 @@ func TestContentWriter(t *testing.T) {
}
expected := digest.FromBytes(p)
checkCopy(t, int64(len(p)), cw, bufio.NewReader(ioutil.NopCloser(bytes.NewReader(p))))
checkCopy(t, int64(len(p)), cw, bufio.NewReader(io.NopCloser(bytes.NewReader(p))))
if err := cw.Commit(ctx, int64(len(p)), expected); err != nil {
t.Fatal(err)
@ -174,7 +173,7 @@ func TestContentWriter(t *testing.T) {
}
// now, attempt to write the same data again
checkCopy(t, int64(len(p)), cw, bufio.NewReader(ioutil.NopCloser(bytes.NewReader(p))))
checkCopy(t, int64(len(p)), cw, bufio.NewReader(io.NopCloser(bytes.NewReader(p))))
if err := cw.Commit(ctx, int64(len(p)), expected); err == nil {
t.Fatal("expected already exists error")
} else if !errdefs.IsAlreadyExists(err) {
@ -184,7 +183,7 @@ func TestContentWriter(t *testing.T) {
path := checkBlobPath(t, cs, expected)
// read the data back, make sure its the same
pp, err := ioutil.ReadFile(path)
pp, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
@ -299,7 +298,7 @@ func contentStoreEnv(t checker) (context.Context, string, content.Store, func())
}
fn := runtime.FuncForPC(pc)
tmpdir, err := ioutil.TempDir("", filepath.Base(fn.Name())+"-")
tmpdir, err := os.MkdirTemp("", filepath.Base(fn.Name())+"-")
if err != nil {
t.Fatal(err)
}
@ -362,7 +361,7 @@ func checkWrite(ctx context.Context, t checker, cs content.Store, dgst digest.Di
}
func TestWriterTruncateRecoversFromIncompleteWrite(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "test-local-content-store-recover")
tmpdir, err := os.MkdirTemp("", "test-local-content-store-recover")
assert.NilError(t, err)
defer os.RemoveAll(tmpdir)
@ -401,7 +400,7 @@ func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, r
}
func TestWriteReadEmptyFileTimestamp(t *testing.T) {
root, err := ioutil.TempDir("", "test-write-read-file-timestamp")
root, err := os.MkdirTemp("", "test-write-read-file-timestamp")
if err != nil {
t.Errorf("failed to create a tmp dir: %v", err)
}

View File

@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"runtime"
@ -104,7 +103,7 @@ func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root
ctx := context.WithValue(context.Background(), nameKey{}, name)
ctx = logtest.WithT(ctx, t)
tmpDir, err := ioutil.TempDir("", "content-suite-"+name+"-")
tmpDir, err := os.MkdirTemp("", "content-suite-"+name+"-")
if err != nil {
t.Fatal(err)
}
@ -782,7 +781,7 @@ func checkSmallBlob(ctx context.Context, t *testing.T, store content.Store) {
}
defer ra.Close()
r := io.NewSectionReader(ra, 0, readSize)
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
@ -1080,7 +1079,7 @@ func createContent(size int64) ([]byte, digest.Digest) {
// test runs. An atomic integer works just good enough for this.
seed := atomic.AddInt64(&contentSeed, 1)
b, err := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size))
b, err := io.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size))
if err != nil {
panic(err)
}

View File

@ -22,7 +22,6 @@ package apparmor
import (
"bytes"
"context"
"io/ioutil"
"os"
"github.com/containerd/containerd/containers"
@ -65,7 +64,7 @@ func LoadDefaultProfile(name string) error {
if err != nil {
return err
}
f, err := ioutil.TempFile(os.Getenv("XDG_RUNTIME_DIR"), p.Name)
f, err := os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), p.Name)
if err != nil {
return err
}

View File

@ -25,7 +25,6 @@ import (
"bufio"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strconv"
@ -131,7 +130,7 @@ func loadData(name string) (*data, error) {
p.Version = ver
// Figure out the daemon profile.
currentProfile, err := ioutil.ReadFile("/proc/self/attr/current")
currentProfile, err := os.ReadFile("/proc/self/attr/current")
if err != nil {
// If we couldn't get the daemon profile, assume we are running
// unconfined which is generally the default.

View File

@ -18,7 +18,6 @@ package fuzz
import (
"bytes"
"context"
"io/ioutil"
"os"
fuzz "github.com/AdaLogics/go-fuzz-headers"
@ -37,7 +36,7 @@ func FuzzApply(data []byte) int {
return 0
}
maxIters := 20
tmpDir, err := ioutil.TempDir("", "prefix-test")
tmpDir, err := os.MkdirTemp("", "prefix-test")
if err != nil {
return 0
}
@ -63,7 +62,7 @@ func FuzzImportIndex(data []byte) int {
}
ctx := context.Background()
r := bytes.NewReader(tarBytes)
tmpdir, err := ioutil.TempDir("", "fuzzing-")
tmpdir, err := os.MkdirTemp("", "fuzzing-")
if err != nil {
return 0
}

View File

@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
@ -148,7 +147,7 @@ func checkIfShouldRestart(err error) {
// startDaemon() starts the daemon.
func startDaemon(ctx context.Context, shouldTearDown bool) {
buf := bytes.NewBuffer(nil)
stdioFile, err := ioutil.TempFile("", "")
stdioFile, err := os.CreateTemp("", "")
if err != nil {
// We panic here as it is a fuzz-blocker that
// may need fixing

View File

@ -21,7 +21,6 @@ import (
"context"
_ "crypto/sha256" // required by go-digest
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -101,7 +100,7 @@ func FuzzCSWalk(data []byte) int {
ctx := context.Background()
expected := map[digest.Digest]struct{}{}
found := map[digest.Digest]struct{}{}
tmpdir, err := ioutil.TempDir("", "fuzzing-")
tmpdir, err := os.MkdirTemp("", "fuzzing-")
if err != nil {
return 0
}
@ -145,7 +144,7 @@ func FuzzArchiveExport(data []byte) int {
return 0
}
ctx := context.Background()
tmpdir, err := ioutil.TempDir("", "fuzzing-")
tmpdir, err := os.MkdirTemp("", "fuzzing-")
if err != nil {
return 0
}

View File

@ -25,7 +25,7 @@ package docker
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -67,7 +67,7 @@ func FuzzFetcher(data []byte) int {
if err != nil {
return 0
}
b, err := ioutil.ReadAll(rc)
b, err := io.ReadAll(rc)
if err != nil {
return 0
}

View File

@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/oci"
@ -33,7 +33,7 @@ import (
func WithProfile(profile string) oci.SpecOpts {
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
s.Linux.Seccomp = &specs.LinuxSeccomp{}
f, err := ioutil.ReadFile(profile)
f, err := os.ReadFile(profile)
if err != nil {
return fmt.Errorf("cannot load seccomp profile %q: %v", profile, err)
}

View File

@ -19,7 +19,6 @@ package apply
import (
"context"
"io"
"io/ioutil"
"time"
"github.com/containerd/containerd/content"
@ -99,7 +98,7 @@ func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts [
}
// Read any trailing data
if _, err := io.Copy(ioutil.Discard, rc); err != nil {
if _, err := io.Copy(io.Discard, rc); err != nil {
return emptyDesc, err
}

View File

@ -21,7 +21,6 @@ package lcow
import (
"context"
"io"
"io/ioutil"
"os"
"path"
"runtime"
@ -166,7 +165,7 @@ func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mou
outFile.Close()
// Read any trailing data
if _, err := io.Copy(ioutil.Discard, rc); err != nil {
if _, err := io.Copy(io.Discard, rc); err != nil {
return emptyDesc, err
}

View File

@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -155,7 +154,7 @@ func (c *binaryProcessor) Close() error {
}
func getUiqPath() (string, error) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
if err != nil {
return "", err
}

View File

@ -24,7 +24,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"time"
winio "github.com/Microsoft/go-winio"
@ -150,7 +149,7 @@ func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
}
// Read any trailing data
if _, err := io.Copy(ioutil.Discard, rc); err != nil {
if _, err := io.Copy(io.Discard, rc); err != nil {
return emptyDesc, err
}

View File

@ -24,7 +24,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"path"
"github.com/containerd/containerd/archive/compression"
@ -223,7 +222,7 @@ func ImportIndex(ctx context.Context, store content.Store, reader io.Reader, opt
}
func onUntarJSON(r io.Reader, j interface{}) error {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}

View File

@ -20,7 +20,6 @@
package integration
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -32,7 +31,7 @@ import (
)
func TestAdditionalGids(t *testing.T) {
testPodLogDir, err := ioutil.TempDir("/tmp", "additional-gids")
testPodLogDir, err := os.MkdirTemp("/tmp", "additional-gids")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
@ -74,7 +73,7 @@ func TestAdditionalGids(t *testing.T) {
}, time.Second, 30*time.Second))
t.Log("Search additional groups in container log")
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
assert.Contains(t, string(content), "groups=1(daemon),10(wheel),1234")
}

View File

@ -22,7 +22,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"testing"
"time"
@ -90,7 +89,7 @@ func TestMain(m *testing.M) {
if !noDaemon {
sys.ForceRemoveAll(defaultRoot)
stdioFile, err := ioutil.TempFile("", "")
stdioFile, err := os.CreateTemp("", "")
if err != nil {
fmt.Fprintf(os.Stderr, "could not create a new stdio temp file: %s\n", err)
os.Exit(1)
@ -497,7 +496,7 @@ func TestClientReconnect(t *testing.T) {
}
func createShimDebugConfig() string {
f, err := ioutil.TempFile("", "containerd-config-")
f, err := os.CreateTemp("", "containerd-config-")
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create config file: %s\n", err)
os.Exit(1)

View File

@ -22,7 +22,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -455,7 +454,7 @@ func TestCheckpointRestoreWithImagePath(t *testing.T) {
}
// create image path store criu image files
crDir, err := ioutil.TempDir("", "test-cr")
crDir, err := os.MkdirTemp("", "test-cr")
if err != nil {
t.Fatal(err)
}
@ -473,7 +472,7 @@ func TestCheckpointRestoreWithImagePath(t *testing.T) {
task.Delete(ctx)
// check image files have been dumped into image path
if files, err := ioutil.ReadDir(imagePath); err != nil || len(files) == 0 {
if files, err := os.ReadDir(imagePath); err != nil || len(files) == 0 {
t.Fatal("failed to checkpoint with image path set")
}

View File

@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -573,7 +572,7 @@ func TestDaemonReconnectsToShimIOPipesOnRestart(t *testing.T) {
<-statusC
stdioContents, err := ioutil.ReadFile(ctrdStdioFilePath)
stdioContents, err := os.ReadFile(ctrdStdioFilePath)
if err != nil {
t.Fatal(err)
}
@ -1963,7 +1962,7 @@ func TestContainerNoSTDIN(t *testing.T) {
}
defer container.Delete(ctx, WithSnapshotCleanup)
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStreams(nil, ioutil.Discard, ioutil.Discard)))
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStreams(nil, io.Discard, io.Discard)))
if err != nil {
t.Fatal(err)
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"os"
"path"
"runtime"
@ -231,7 +230,7 @@ func TestContainerOutput(t *testing.T) {
}
func withByteBuffers(stdout io.Writer) cio.Opt {
// TODO: could this use ioutil.Discard?
// TODO: could this use io.Discard?
return func(streams *cio.Streams) {
streams.Stdin = new(bytes.Buffer)
streams.Stdout = stdout
@ -515,7 +514,7 @@ func TestContainerCloseIO(t *testing.T) {
t.Fatal(err)
}
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStreams(r, stdout, ioutil.Discard)))
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStreams(r, stdout, io.Discard)))
if err != nil {
t.Fatal(err)
}

View File

@ -21,7 +21,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -52,7 +51,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
buf = bytes.NewBuffer(nil)
)
tempDir, err := ioutil.TempDir("", "containerd-test-new-daemon-with-config")
tempDir, err := os.MkdirTemp("", "containerd-test-new-daemon-with-config")
if err != nil {
t.Fatal(err)
}
@ -63,7 +62,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
}()
configTOMLFile := filepath.Join(tempDir, "config.toml")
if err = ioutil.WriteFile(configTOMLFile, []byte(configTOML), 0600); err != nil {
if err = os.WriteFile(configTOMLFile, []byte(configTOML), 0600); err != nil {
t.Fatal(err)
}
@ -119,7 +118,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
// TestDaemonRuntimeRoot ensures plugin.linux.runtime_root is not ignored
func TestDaemonRuntimeRoot(t *testing.T) {
runtimeRoot, err := ioutil.TempDir("", "containerd-test-runtime-root")
runtimeRoot, err := os.MkdirTemp("", "containerd-test-runtime-root")
if err != nil {
t.Fatal(err)
}

View File

@ -22,7 +22,6 @@ import (
"encoding/json"
"io"
"io/ioutil"
"math/rand"
"reflect"
"testing"
@ -285,7 +284,7 @@ func checkImages(t *testing.T, target digest.Digest, actual []images.Image, name
}
func createContent(size int64, seed int64) ([]byte, digest.Digest) {
b, err := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size))
b, err := io.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size))
if err != nil {
panic(err)
}

View File

@ -18,7 +18,7 @@ package integration
import (
"fmt"
"io/ioutil"
"os"
"testing"
cri "github.com/containerd/containerd/integration/cri-api/pkg/apis"
@ -56,7 +56,7 @@ func initImages(imageListFile string) {
}
if imageListFile != "" {
fileContent, err := ioutil.ReadFile(imageListFile)
fileContent, err := os.ReadFile(imageListFile)
if err != nil {
panic(fmt.Errorf("Error reading '%v' file contents: %v", imageList, err))
}

View File

@ -18,7 +18,6 @@ package integration
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -31,7 +30,7 @@ import (
)
func TestContainerLogWithoutTailingNewLine(t *testing.T) {
testPodLogDir, err := ioutil.TempDir("/tmp", "container-log-without-tailing-newline")
testPodLogDir, err := os.MkdirTemp("/tmp", "container-log-without-tailing-newline")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
@ -73,7 +72,7 @@ func TestContainerLogWithoutTailingNewLine(t *testing.T) {
}, time.Second, 30*time.Second))
t.Log("Check container log")
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
checkContainerLog(t, string(content), []string{
fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagPartial, "abcd"),
@ -81,7 +80,7 @@ func TestContainerLogWithoutTailingNewLine(t *testing.T) {
}
func TestLongContainerLog(t *testing.T) {
testPodLogDir, err := ioutil.TempDir("/tmp", "long-container-log")
testPodLogDir, err := os.MkdirTemp("/tmp", "long-container-log")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
@ -130,7 +129,7 @@ func TestLongContainerLog(t *testing.T) {
}, time.Second, 30*time.Second))
t.Log("Check container log")
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
checkContainerLog(t, string(content), []string{
fmt.Sprintf("%s %s %s", runtime.Stdout, runtime.LogTagFull, strings.Repeat("a", maxSize-1)),

View File

@ -17,7 +17,6 @@
package integration
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -36,7 +35,7 @@ func createRegularFile(basePath, content string) (string, error) {
}
newFile := filepath.Join(newFolder, "foo.txt")
err = ioutil.WriteFile(newFile, []byte(content), 0644)
err = os.WriteFile(newFile, []byte(content), 0644)
return filepath.Join("regular", "foo.txt"), err
}
@ -83,11 +82,11 @@ func TestContainerSymlinkVolumes(t *testing.T) {
} {
testCase := testCase // capture range variable
t.Run(name, func(t *testing.T) {
testPodLogDir, err := ioutil.TempDir("", "symlink-test")
testPodLogDir, err := os.MkdirTemp("", "symlink-test")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
testVolDir, err := ioutil.TempDir("", "symlink-test-vol")
testVolDir, err := os.MkdirTemp("", "symlink-test-vol")
require.NoError(t, err)
defer os.RemoveAll(testVolDir)
@ -137,7 +136,7 @@ func TestContainerSymlinkVolumes(t *testing.T) {
return false, nil
}, time.Second, 30*time.Second))
output, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
output, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
assert.Contains(t, string(output), content)

View File

@ -17,7 +17,6 @@
package integration
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -40,8 +39,8 @@ func TestImageLoad(t *testing.T) {
t.Logf("docker save image into tarball")
output, err := exec.Command("docker", "pull", testImage).CombinedOutput()
require.NoError(t, err, "output: %q", output)
// ioutil.TempFile also opens a file, which might prevent us from overwriting that file with docker save.
tarDir, err := ioutil.TempDir("", "image-load")
// os.CreateTemp also opens a file, which might prevent us from overwriting that file with docker save.
tarDir, err := os.MkdirTemp("", "image-load")
tar := filepath.Join(tarDir, "image.tar")
require.NoError(t, err)
defer func() {

View File

@ -17,7 +17,6 @@
package integration
import (
"io/ioutil"
"net"
"os"
"path/filepath"
@ -32,7 +31,7 @@ import (
)
func TestPodDualStack(t *testing.T) {
testPodLogDir, err := ioutil.TempDir("/tmp", "dualstack")
testPodLogDir, err := os.MkdirTemp("/tmp", "dualstack")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
@ -77,7 +76,7 @@ func TestPodDualStack(t *testing.T) {
return false, nil
}, time.Second, 30*time.Second))
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
status, err := runtimeService.PodSandboxStatus(sb)
require.NoError(t, err)

View File

@ -17,7 +17,6 @@
package integration
import (
"io/ioutil"
"os"
"path/filepath"
goruntime "runtime"
@ -65,7 +64,7 @@ func TestPodHostname(t *testing.T) {
if test.needsHostNetwork && goruntime.GOOS == "windows" {
t.Skip("Skipped on Windows.")
}
testPodLogDir, err := ioutil.TempDir("/tmp", "hostname")
testPodLogDir, err := os.MkdirTemp("/tmp", "hostname")
require.NoError(t, err)
defer os.RemoveAll(testPodLogDir)
@ -121,7 +120,7 @@ func TestPodHostname(t *testing.T) {
return false, nil
}, time.Second, 30*time.Second))
content, err := ioutil.ReadFile(filepath.Join(testPodLogDir, containerName))
content, err := os.ReadFile(filepath.Join(testPodLogDir, containerName))
assert.NoError(t, err)
t.Log("Search hostname env in container log")

View File

@ -38,7 +38,6 @@ package util
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
@ -73,7 +72,7 @@ func CreateListener(endpoint string) (net.Listener, error) {
}
// Create the socket on a tempfile and move it to the destination socket to handle improprer cleanup
file, err := ioutil.TempFile(filepath.Dir(addr), "")
file, err := os.CreateTemp(filepath.Dir(addr), "")
if err != nil {
return nil, fmt.Errorf("failed to create temporary file: %v", err)
}

View File

@ -20,7 +20,6 @@
package integration
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -40,11 +39,11 @@ func TestSandboxRemoveWithoutIPLeakage(t *testing.T) {
t.Logf("Make sure host-local ipam is in use")
config, err := CRIConfig()
require.NoError(t, err)
fs, err := ioutil.ReadDir(config.NetworkPluginConfDir)
fs, err := os.ReadDir(config.NetworkPluginConfDir)
require.NoError(t, err)
require.NotEmpty(t, fs)
f := filepath.Join(config.NetworkPluginConfDir, fs[0].Name())
cniConfig, err := ioutil.ReadFile(f)
cniConfig, err := os.ReadFile(f)
require.NoError(t, err)
if !strings.Contains(string(cniConfig), "host-local") {
t.Skip("host-local ipam is not in use")

View File

@ -38,7 +38,6 @@ package util
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
@ -73,7 +72,7 @@ func CreateListener(endpoint string) (net.Listener, error) {
}
// Create the socket on a tempfile and move it to the destination socket to handle improprer cleanup
file, err := ioutil.TempFile(filepath.Dir(addr), "")
file, err := os.CreateTemp(filepath.Dir(addr), "")
if err != nil {
return nil, fmt.Errorf("failed to create temporary file: %v", err)
}

View File

@ -19,7 +19,7 @@ package logtest
import (
"context"
"fmt"
"io/ioutil"
"io"
"path/filepath"
"runtime"
"testing"
@ -37,7 +37,7 @@ func WithT(ctx context.Context, t testing.TB) context.Context {
// Increase debug level for tests
l.SetLevel(logrus.DebugLevel)
l.SetOutput(ioutil.Discard)
l.SetOutput(io.Discard)
l.SetReportCaller(true)
// Add testing hook

View File

@ -17,7 +17,7 @@
package metadata
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -28,7 +28,7 @@ import (
)
func TestHasSharedLabel(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "bucket-testing-")
tmpdir, err := os.MkdirTemp("", "bucket-testing-")
if err != nil {
t.Error(err)
}
@ -64,7 +64,7 @@ func TestHasSharedLabel(t *testing.T) {
}
func TestGetShareableBucket(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "bucket-testing-")
tmpdir, err := os.MkdirTemp("", "bucket-testing-")
if err != nil {
t.Error(err)
}

View File

@ -19,7 +19,6 @@ package metadata
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -715,7 +714,7 @@ func testEnv(t *testing.T) (context.Context, *bolt.DB, func()) {
ctx = namespaces.WithNamespace(ctx, "testing")
ctx = logtest.WithT(ctx, t)
dirname, err := ioutil.TempDir("", strings.Replace(t.Name(), "/", "_", -1)+"-")
dirname, err := os.MkdirTemp("", strings.Replace(t.Name(), "/", "_", -1)+"-")
if err != nil {
t.Fatal(err)
}

View File

@ -21,7 +21,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -74,7 +73,7 @@ func testDB(t *testing.T, opt ...testOpt) (context.Context, *DB, func()) {
o(&topts)
}
dirname, err := ioutil.TempDir("", strings.Replace(t.Name(), "/", "_", -1)+"-")
dirname, err := os.MkdirTemp("", strings.Replace(t.Name(), "/", "_", -1)+"-")
if err != nil {
t.Fatal(err)
}
@ -765,7 +764,7 @@ type testLease struct {
}
func newStores(t testing.TB) (*DB, content.Store, snapshots.Snapshotter, func()) {
td, err := ioutil.TempDir("", "gc-test-")
td, err := os.MkdirTemp("", "gc-test-")
if err != nil {
t.Fatal(err)
}

View File

@ -19,7 +19,6 @@ package metadata
import (
"context"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
@ -389,7 +388,7 @@ func TestGCRefs(t *testing.T) {
}
func newDatabase() (*bolt.DB, func(), error) {
td, err := ioutil.TempDir("", "gc-roots-")
td, err := os.MkdirTemp("", "gc-roots-")
if err != nil {
return nil, nil, err
}

View File

@ -17,7 +17,6 @@
package mount
import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
@ -46,7 +45,7 @@ func makeTestForFMountat(fn fMountatCaseFunc) func(t *testing.T) {
return func(t *testing.T) {
t.Parallel()
suiteDir, err := ioutil.TempDir("", "fmountat-test-")
suiteDir, err := os.MkdirTemp("", "fmountat-test-")
if err != nil {
t.Fatal(err)
}
@ -94,7 +93,7 @@ func testFMountatNormal(t *testing.T, root string) {
defer umount(t, fsdir)
// check hi file
content, err := ioutil.ReadFile(filepath.Join(fsdir, "hi"))
content, err := os.ReadFile(filepath.Join(fsdir, "hi"))
if err != nil {
t.Fatalf("failed to read file: %+v", err)
}

View File

@ -18,7 +18,6 @@ package mount
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -42,7 +41,7 @@ func checkLookup(t *testing.T, fsType, mntPoint, dir string) {
func testLookup(t *testing.T, fsType string) {
testutil.RequiresRoot(t)
mnt, err := ioutil.TempDir("", "containerd-mountinfo-test-lookup")
mnt, err := os.MkdirTemp("", "containerd-mountinfo-test-lookup")
if err != nil {
t.Fatal(err)
}
@ -69,7 +68,7 @@ func testLookup(t *testing.T, fsType string) {
assert.Check(t, strings.HasPrefix(loop.Device, "/dev/loop"))
checkLookup(t, fsType, mnt, mnt)
newMnt, err := ioutil.TempDir("", "containerd-mountinfo-test-newMnt")
newMnt, err := os.MkdirTemp("", "containerd-mountinfo-test-newMnt")
if err != nil {
t.Fatal(err)
}
@ -100,19 +99,19 @@ func TestLookupWithXFS(t *testing.T) {
}
func TestLookupWithOverlay(t *testing.T) {
lower, err := ioutil.TempDir("", "containerd-mountinfo-test-lower")
lower, err := os.MkdirTemp("", "containerd-mountinfo-test-lower")
assert.NilError(t, err)
defer os.RemoveAll(lower)
upper, err := ioutil.TempDir("", "containerd-mountinfo-test-upper")
upper, err := os.MkdirTemp("", "containerd-mountinfo-test-upper")
assert.NilError(t, err)
defer os.RemoveAll(upper)
work, err := ioutil.TempDir("", "containerd-mountinfo-test-work")
work, err := os.MkdirTemp("", "containerd-mountinfo-test-work")
assert.NilError(t, err)
defer os.RemoveAll(work)
overlay, err := ioutil.TempDir("", "containerd-mountinfo-test-overlay")
overlay, err := os.MkdirTemp("", "containerd-mountinfo-test-overlay")
assert.NilError(t, err)
defer os.RemoveAll(overlay)

View File

@ -17,7 +17,6 @@
package mount
import (
"io/ioutil"
"os"
"testing"
@ -29,7 +28,7 @@ var randomData = []byte("randomdata")
func createTempFile(t *testing.T) string {
t.Helper()
f, err := ioutil.TempFile("", "losetup")
f, err := os.CreateTemp("", "losetup")
if err != nil {
t.Fatal(err)
}

View File

@ -18,7 +18,6 @@ package mount
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@ -105,7 +104,7 @@ func TestFUSEHelper(t *testing.T) {
if err != nil {
t.Skip("fuse-overlayfs not installed")
}
td, err := ioutil.TempDir("", "fuse")
td, err := os.MkdirTemp("", "fuse")
if err != nil {
t.Fatal(err)
}

View File

@ -18,7 +18,6 @@ package mount
import (
"context"
"io/ioutil"
"os"
"github.com/containerd/containerd/log"
@ -31,7 +30,7 @@ var tempMountLocation = getTempDir()
// The mounts are valid during the call to the f.
// Finally we will unmount and remove the temp dir regardless of the result of f.
func WithTempMount(ctx context.Context, mounts []Mount, f func(root string) error) (err error) {
root, uerr := ioutil.TempDir(tempMountLocation, "containerd-mount")
root, uerr := os.MkdirTemp(tempMountLocation, "containerd-mount")
if uerr != nil {
return errors.Wrapf(uerr, "failed to create temp dir")
}

View File

@ -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")
}

View 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"))

View File

@ -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)
}

View File

@ -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
}

View File

@ -17,7 +17,6 @@
package apparmor
import (
"io/ioutil"
"os"
"sync"
)
@ -36,7 +35,7 @@ func hostSupports() bool {
checkAppArmor.Do(func() {
// see https://github.com/opencontainers/runc/blob/0d49470392206f40eaab3b2190a57fe7bb3df458/libcontainer/apparmor/apparmor_linux.go
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
buf, err := os.ReadFile("/sys/module/apparmor/parameters/enabled")
appArmorSupported = err == nil && len(buf) > 1 && buf[0] == 'Y'
}
})

View File

@ -21,7 +21,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"time"
"github.com/sirupsen/logrus"
@ -43,7 +42,7 @@ const (
// NewDiscardLogger creates logger which discards all the input.
func NewDiscardLogger() io.WriteCloser {
return cioutil.NewNopWriteCloser(ioutil.Discard)
return cioutil.NewNopWriteCloser(io.Discard)
}
// NewCRILogger returns a write closer which redirect container log into

View File

@ -18,7 +18,7 @@ package io
import (
"bytes"
"io/ioutil"
"io"
"strings"
"testing"
"time"
@ -237,7 +237,7 @@ func TestRedirectLogs(t *testing.T) {
},
} {
t.Logf("TestCase %q", desc)
rc := ioutil.NopCloser(strings.NewReader(test.input))
rc := io.NopCloser(strings.NewReader(test.input))
buf := bytes.NewBuffer(nil)
wc := cioutil.NewNopWriteCloser(buf)
redirectLogs("test-path", rc, wc, test.stream, test.maxLen)

View File

@ -18,7 +18,6 @@ package opts
import (
"context"
"io/ioutil"
"os"
"path/filepath"
@ -67,7 +66,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
if err != nil {
return err
}
root, err := ioutil.TempDir("", "ctd-volume")
root, err := os.MkdirTemp("", "ctd-volume")
if err != nil {
return err
}
@ -108,7 +107,7 @@ func WithVolumes(volumeMounts map[string]string) containerd.NewContainerOpts {
// copyExistingContents copies from the source to the destination and
// ensures the ownership is appropriately set.
func copyExistingContents(source, destination string) error {
dstList, err := ioutil.ReadDir(destination)
dstList, err := os.ReadDir(destination)
if err != nil {
return err
}

View File

@ -19,7 +19,6 @@ package opts
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -533,7 +532,7 @@ var (
// cgroup v1.
func cgroupv1HasHugetlb() (bool, error) {
_cgroupv1HasHugetlbOnce.Do(func() {
if _, err := ioutil.ReadDir("/sys/fs/cgroup/hugetlb"); err != nil {
if _, err := os.ReadDir("/sys/fs/cgroup/hugetlb"); err != nil {
_cgroupv1HasHugetlbErr = errors.Wrap(err, "readdir /sys/fs/cgroup/hugetlb")
_cgroupv1HasHugetlb = false
} else {
@ -548,7 +547,7 @@ func cgroupv1HasHugetlb() (bool, error) {
// cgroup v2.
func cgroupv2HasHugetlb() (bool, error) {
_cgroupv2HasHugetlbOnce.Do(func() {
controllers, err := ioutil.ReadFile("/sys/fs/cgroup/cgroup.controllers")
controllers, err := os.ReadFile("/sys/fs/cgroup/cgroup.controllers")
if err != nil {
_cgroupv2HasHugetlbErr = errors.Wrap(err, "read /sys/fs/cgroup/cgroup.controllers")
return
@ -696,7 +695,7 @@ func nullOpt(_ context.Context, _ oci.Client, _ *containers.Container, _ *runtim
}
func getCurrentOOMScoreAdj() (int, error) {
b, err := ioutil.ReadFile("/proc/self/oom_score_adj")
b, err := os.ReadFile("/proc/self/oom_score_adj")
if err != nil {
return 0, errors.Wrap(err, "could not get the daemon oom_score_adj")
}

View File

@ -17,7 +17,6 @@
package server
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -66,11 +65,11 @@ func TestEnsureRemoveAllWithMount(t *testing.T) {
t.Skip("skipping test that requires root")
}
dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1")
dir1, err := os.MkdirTemp("", "test-ensure-removeall-with-dir1")
if err != nil {
t.Fatal(err)
}
dir2, err := ioutil.TempDir("", "test-ensure-removeall-with-dir2")
dir2, err := os.MkdirTemp("", "test-ensure-removeall-with-dir2")
if err != nil {
t.Fatal(err)
}

View File

@ -18,7 +18,7 @@ package server
import (
"context"
"io/ioutil"
"os"
"testing"
"time"
@ -489,7 +489,7 @@ func TestEnsureRemoveAllNotExist(t *testing.T) {
}
func TestEnsureRemoveAllWithDir(t *testing.T) {
dir, err := ioutil.TempDir("", "test-ensure-removeall-with-dir")
dir, err := os.MkdirTemp("", "test-ensure-removeall-with-dir")
if err != nil {
t.Fatal(err)
}
@ -499,7 +499,7 @@ func TestEnsureRemoveAllWithDir(t *testing.T) {
}
func TestEnsureRemoveAllWithFile(t *testing.T) {
tmp, err := ioutil.TempFile("", "test-ensure-removeall-with-dir")
tmp, err := os.CreateTemp("", "test-ensure-removeall-with-dir")
if err != nil {
t.Fatal(err)
}

View File

@ -21,10 +21,10 @@ import (
"crypto/x509"
"encoding/base64"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
"time"
@ -301,7 +301,7 @@ func (c *criService) getTLSConfig(registryTLSConfig criconfig.TLSConfig) (*tls.C
if err != nil {
return nil, errors.Wrap(err, "failed to get system cert pool")
}
caCert, err := ioutil.ReadFile(registryTLSConfig.CAFile)
caCert, err := os.ReadFile(registryTLSConfig.CAFile)
if err != nil {
return nil, errors.Wrap(err, "failed to load CA file")
}

View File

@ -17,7 +17,6 @@
package server
import (
"io/ioutil"
"os"
"path/filepath"
goruntime "runtime"
@ -458,7 +457,7 @@ func (c *criService) loadImages(ctx context.Context, cImages []containerd.Image)
func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, base string) error {
// Cleanup orphaned id directories.
dirs, err := ioutil.ReadDir(base)
dirs, err := os.ReadDir(base)
if err != nil && !os.IsNotExist(err) {
return errors.Wrap(err, "failed to read base directory")
}

View File

@ -18,7 +18,6 @@ package server
import (
"encoding/json"
"io/ioutil"
"os"
"testing"
@ -73,7 +72,7 @@ func newTestCRIService() *criService {
func TestLoadBaseOCISpec(t *testing.T) {
spec := oci.Spec{Version: "1.0.2", Hostname: "default"}
file, err := ioutil.TempFile("", "spec-test-")
file, err := os.CreateTemp("", "spec-test-")
require.NoError(t, err)
defer func() {

View File

@ -17,7 +17,6 @@
package server
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -94,11 +93,11 @@ func TestUpdateRuntimeConfig(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
testDir, err := ioutil.TempDir(os.TempDir(), "test-runtime-config")
testDir, err := os.MkdirTemp(os.TempDir(), "test-runtime-config")
require.NoError(t, err)
defer os.RemoveAll(testDir)
templateName := filepath.Join(testDir, "template")
err = ioutil.WriteFile(templateName, []byte(testTemplate), 0666)
err = os.WriteFile(templateName, []byte(testTemplate), 0666)
require.NoError(t, err)
confDir := filepath.Join(testDir, "net.d")
confName := filepath.Join(confDir, cniConfigFileName)
@ -131,7 +130,7 @@ func TestUpdateRuntimeConfig(t *testing.T) {
_, err := os.Stat(confName)
assert.Error(t, err)
} else {
got, err := ioutil.ReadFile(confName)
got, err := os.ReadFile(confName)
assert.NoError(t, err)
assert.Equal(t, expected, string(got))
}

View File

@ -18,7 +18,6 @@ package container
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -182,7 +181,7 @@ func StoreStatus(root, id string, status Status) (StatusStorage, error) {
// writing to the file during loading.
func LoadStatus(root, id string) (Status, error) {
path := filepath.Join(root, "status")
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return Status{}, errors.Wrapf(err, "failed to read status from %q", path)
}

View File

@ -19,7 +19,6 @@ package container
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -115,7 +114,7 @@ func TestStatus(t *testing.T) {
assert := assertlib.New(t)
require := requirelib.New(t)
tempDir, err := ioutil.TempDir(os.TempDir(), "status-test")
tempDir, err := os.MkdirTemp(os.TempDir(), "status-test")
require.NoError(err)
defer os.RemoveAll(tempDir)
statusFile := filepath.Join(tempDir, "status")

View File

@ -18,7 +18,6 @@ package image
import (
"io"
"io/ioutil"
"math/rand"
"testing"
@ -27,7 +26,7 @@ import (
func TestReferenceSorting(t *testing.T) {
digested := func(seed int64) string {
b, err := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), 64))
b, err := io.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), 64))
if err != nil {
panic(err)
}

View File

@ -17,7 +17,6 @@
package ioutil
import (
"io/ioutil"
"os"
"sort"
"strconv"
@ -69,7 +68,7 @@ func TestSerialWriteCloser(t *testing.T) {
testData[i] = []byte(repeatNumber(i, dataLen) + "\n")
}
f, err := ioutil.TempFile("", "serial-write-closer")
f, err := os.CreateTemp("", "serial-write-closer")
require.NoError(t, err)
defer os.RemoveAll(f.Name())
defer f.Close()
@ -91,7 +90,7 @@ func TestSerialWriteCloser(t *testing.T) {
wc.Close()
// Check test result
content, err := ioutil.ReadFile(f.Name())
content, err := os.ReadFile(f.Name())
require.NoError(t, err)
resultData := strings.Split(strings.TrimSpace(string(content)), "\n")
require.Len(t, resultData, goroutine)

View File

@ -18,7 +18,6 @@ package os
import (
"io"
"io/ioutil"
"os"
"github.com/moby/sys/symlink"
@ -78,9 +77,9 @@ func (RealOS) CopyFile(src, dest string, perm os.FileMode) error {
return err
}
// WriteFile will call ioutil.WriteFile to write data into a file.
// WriteFile will call os.WriteFile to write data into a file.
func (RealOS) WriteFile(filename string, data []byte, perm os.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
return os.WriteFile(filename, data, perm)
}
// Hostname will call os.Hostname to get the hostname of the host.

View File

@ -19,7 +19,6 @@ package os
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@ -162,7 +161,7 @@ func setupVHDVolume(t *testing.T, vhdPath string) string {
}
func writeFile(t *testing.T, path string, content []byte) {
if err := ioutil.WriteFile(path, content, 0644); err != nil {
if err := os.WriteFile(path, content, 0644); err != nil {
t.Fatal(err)
}
}

View File

@ -21,8 +21,8 @@ package process
import (
"context"
"io/ioutil"
"net/url"
"os"
"testing"
"github.com/containerd/containerd/namespaces"
@ -68,6 +68,6 @@ func TestNewBinaryIOCleanup(t *testing.T) {
func descriptorCount(t *testing.T) int {
t.Helper()
files, _ := ioutil.ReadDir("/proc/self/fd")
files, _ := os.ReadDir("/proc/self/fd")
return len(files)
}

View File

@ -19,7 +19,6 @@ package testutil
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@ -53,7 +52,7 @@ func DumpDir(t *testing.T, root string) {
}
t.Log(fi.Mode(), fmt.Sprintf("%10s", ""), path, "->", target)
} else if fi.Mode().IsRegular() {
p, err := ioutil.ReadFile(path)
p, err := os.ReadFile(path)
if err != nil {
t.Logf("error reading file: %v", err)
return nil

View File

@ -20,7 +20,6 @@ package config
import (
"context"
"crypto/tls"
"io/ioutil"
"net"
"net/http"
"net/url"
@ -170,7 +169,7 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
tlsConfig.RootCAs = rootPool
}
for _, f := range host.caCerts {
data, err := ioutil.ReadFile(f)
data, err := os.ReadFile(f)
if err != nil {
return nil, errors.Wrapf(err, "unable to read CA cert %q", f)
}
@ -182,13 +181,13 @@ func ConfigureHosts(ctx context.Context, options HostOptions) docker.RegistryHos
if host.clientPairs != nil {
for _, pair := range host.clientPairs {
certPEMBlock, err := ioutil.ReadFile(pair[0])
certPEMBlock, err := os.ReadFile(pair[0])
if err != nil {
return nil, errors.Wrapf(err, "unable to read CERT file %q", pair[0])
}
var keyPEMBlock []byte
if pair[1] != "" {
keyPEMBlock, err = ioutil.ReadFile(pair[1])
keyPEMBlock, err = os.ReadFile(pair[1])
if err != nil {
return nil, errors.Wrapf(err, "unable to read CERT file %q", pair[1])
}
@ -251,7 +250,7 @@ func hostDirectory(host string) string {
}
func loadHostDir(ctx context.Context, hostsDir string) ([]hostConfig, error) {
b, err := ioutil.ReadFile(filepath.Join(hostsDir, "hosts.toml"))
b, err := os.ReadFile(filepath.Join(hostsDir, "hosts.toml"))
if err != nil && !os.IsNotExist(err) {
return nil, err
}
@ -536,7 +535,7 @@ func makeAbsPath(p string, base string) string {
// the ".cert", which may contain the private key. If the ".cert" file
// does not contain the private key, the caller should detect and error.
func loadCertFiles(ctx context.Context, certsDir string) ([]hostConfig, error) {
fs, err := ioutil.ReadDir(certsDir)
fs, err := os.ReadDir(certsDir)
if err != nil && !os.IsNotExist(err) {
return nil, err
}

View File

@ -20,7 +20,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -209,7 +208,7 @@ ca = "/etc/path/default"
}
func TestLoadCertFiles(t *testing.T) {
dir, err := ioutil.TempDir("", t.Name())
dir, err := os.MkdirTemp("", t.Name())
if err != nil {
t.Fatal(err)
}
@ -257,16 +256,16 @@ func TestLoadCertFiles(t *testing.T) {
defer os.RemoveAll(hostDir)
for _, f := range tc.input.caCerts {
if err := ioutil.WriteFile(f, testKey, 0600); err != nil {
if err := os.WriteFile(f, testKey, 0600); err != nil {
t.Fatal(err)
}
}
for _, pair := range tc.input.clientPairs {
if err := ioutil.WriteFile(pair[0], testKey, 0600); err != nil {
if err := os.WriteFile(pair[0], testKey, 0600); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(pair[1], testKey, 0600); err != nil {
if err := os.WriteFile(pair[1], testKey, 0600); err != nil {
t.Fatal(err)
}
}

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@ -197,7 +196,7 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,
// Discard up to offset
// Could use buffer pool here but this case should be rare
n, err := io.Copy(ioutil.Discard, io.LimitReader(resp.Body, offset))
n, err := io.Copy(io.Discard, io.LimitReader(resp.Body, offset))
if err != nil {
return nil, errors.Wrap(err, "failed to discard to offset")
}

View File

@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
@ -73,7 +72,7 @@ func TestFetcherOpen(t *testing.T) {
if err != nil {
t.Fatalf("failed to open: %+v", err)
}
b, err := ioutil.ReadAll(rc)
b, err := io.ReadAll(rc)
if err != nil {
t.Fatal(err)
}

View File

@ -19,7 +19,6 @@ package docker
import (
"bytes"
"io"
"io/ioutil"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
@ -162,7 +161,7 @@ func (hrs *httpReadSeeker) reader() (io.Reader, error) {
// as the length is already satisfied but we just return the empty
// reader instead.
hrs.rc = ioutil.NopCloser(bytes.NewReader([]byte{}))
hrs.rc = io.NopCloser(bytes.NewReader([]byte{}))
}
return hrs.rc, nil

View File

@ -19,7 +19,6 @@ package docker
import (
"context"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@ -263,7 +262,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
pr, pw := io.Pipe()
respC := make(chan response, 1)
body := ioutil.NopCloser(pr)
body := io.NopCloser(pr)
req.body = func() (io.ReadCloser, error) {
if body == nil {

View File

@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
@ -359,7 +358,7 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
return "", ocispec.Descriptor{}, err
}
}
} else if _, err := io.Copy(ioutil.Discard, &bodyReader); err != nil {
} else if _, err := io.Copy(io.Discard, &bodyReader); err != nil {
return "", ocispec.Descriptor{}, err
}
size = bodyReader.bytesRead

View File

@ -23,7 +23,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
@ -574,7 +573,7 @@ func testocimanifest(ctx context.Context, f remotes.Fetcher, desc ocispec.Descri
if err != nil {
return nil, errors.Wrapf(err, "failed to fetch %s", desc.Digest)
}
p, err := ioutil.ReadAll(r)
p, err := io.ReadAll(r)
if err != nil {
return nil, err
}

View File

@ -23,7 +23,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
"sync"
@ -230,7 +229,7 @@ func (c *Converter) Convert(ctx context.Context, opts ...ConvertOpt) (ocispec.De
// ReadStripSignature reads in a schema1 manifest and returns a byte array
// with the "signatures" field stripped
func ReadStripSignature(schema1Blob io.Reader) ([]byte, error) {
b, err := ioutil.ReadAll(io.LimitReader(schema1Blob, manifestSizeLimit)) // limit to 8MB
b, err := io.ReadAll(io.LimitReader(schema1Blob, manifestSizeLimit)) // limit to 8MB
if err != nil {
return nil, err
}

View File

@ -19,7 +19,6 @@ package errors
import (
"fmt"
"io"
"io/ioutil"
"net/http"
)
@ -41,7 +40,7 @@ func (e ErrUnexpectedStatus) Error() string {
func NewUnexpectedStatusErr(resp *http.Response) error {
var b []byte
if resp.Body != nil {
b, _ = ioutil.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB
b, _ = io.ReadAll(io.LimitReader(resp.Body, 64000)) // 64KB
}
err := ErrUnexpectedStatus{
Body: b,

View File

@ -19,7 +19,6 @@ package rootfs
import (
"context"
"fmt"
"io/ioutil"
"os"
"github.com/containerd/containerd/log"
@ -75,7 +74,7 @@ func createInitLayer(ctx context.Context, parent, initName string, initFn func(s
// TODO: ensure not exist error once added to snapshot package
// Create tempdir
td, err := ioutil.TempDir(os.Getenv("XDG_RUNTIME_DIR"), "create-init-")
td, err := os.MkdirTemp(os.Getenv("XDG_RUNTIME_DIR"), "create-init-")
if err != nil {
return "", err
}

View File

@ -23,7 +23,6 @@ import (
"context"
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -70,7 +69,7 @@ func newBundle(id, path, workDir string, spec []byte) (b *bundle, err error) {
if err := os.MkdirAll(rootfs, 0711); err != nil {
return nil, err
}
err = ioutil.WriteFile(filepath.Join(path, configFilename), spec, 0666)
err = os.WriteFile(filepath.Join(path, configFilename), spec, 0666)
return &bundle{
id: id,
path: path,
@ -148,7 +147,7 @@ func (b *bundle) shimAddress(namespace, socketPath string) string {
func (b *bundle) loadAddress() (string, error) {
addressPath := filepath.Join(b.path, "address")
data, err := ioutil.ReadFile(addressPath)
data, err := os.ReadFile(addressPath)
if err != nil {
return "", err
}

View File

@ -23,7 +23,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -288,7 +287,7 @@ func (r *Runtime) Tasks(ctx context.Context, all bool) ([]runtime.Task, error) {
}
func (r *Runtime) restoreTasks(ctx context.Context) ([]*Task, error) {
dir, err := ioutil.ReadDir(r.state)
dir, err := os.ReadDir(r.state)
if err != nil {
return nil, err
}
@ -340,7 +339,7 @@ func (r *Runtime) Delete(ctx context.Context, id string) (*runtime.Exit, error)
}
func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
dir, err := ioutil.ReadDir(filepath.Join(r.state, ns))
dir, err := os.ReadDir(filepath.Join(r.state, ns))
if err != nil {
return nil, err
}
@ -413,7 +412,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
if r.config.ShimDebug {
go copyAndClose(os.Stdout, shimStdoutLog)
} else {
go copyAndClose(ioutil.Discard, shimStdoutLog)
go copyAndClose(io.Discard, shimStdoutLog)
}
shimStderrLog, err := v1.OpenShimStderrLog(ctx, logDirPath)
@ -428,7 +427,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
if r.config.ShimDebug {
go copyAndClose(os.Stderr, shimStderrLog)
} else {
go copyAndClose(ioutil.Discard, shimStderrLog)
go copyAndClose(io.Discard, shimStderrLog)
}
t, err := newTask(id, ns, pid, s, r.events, r.tasks, bundle)

View File

@ -23,7 +23,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -75,8 +74,8 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
}
defer f.Close()
stdoutCopy := ioutil.Discard
stderrCopy := ioutil.Discard
stdoutCopy := io.Discard
stderrCopy := io.Discard
stdoutLog, err := v1.OpenShimStdoutLog(ctx, config.WorkDir)
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to create stdout log")

View File

@ -23,7 +23,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -543,7 +542,7 @@ func (s *Service) checkProcesses(e runc.Exit) {
func shouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
var bundleSpec specs.Spec
bundleConfigContents, err := ioutil.ReadFile(filepath.Join(bundlePath, "config.json"))
bundleConfigContents, err := os.ReadFile(filepath.Join(bundlePath, "config.json"))
if err != nil {
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json")
return true

View File

@ -19,7 +19,6 @@ package v2
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -100,7 +99,7 @@ func NewBundle(ctx context.Context, root, state, id string, spec []byte) (b *Bun
return nil, err
}
// write the spec to the bundle
err = ioutil.WriteFile(filepath.Join(b.Path, configFilename), spec, 0666)
err = os.WriteFile(filepath.Join(b.Path, configFilename), spec, 0666)
return b, err
}

View File

@ -19,7 +19,6 @@ package v2
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -234,7 +233,7 @@ func (m *TaskManager) Tasks(ctx context.Context, all bool) ([]runtime.Task, erro
}
func (m *TaskManager) loadExistingTasks(ctx context.Context) error {
nsDirs, err := ioutil.ReadDir(m.state)
nsDirs, err := os.ReadDir(m.state)
if err != nil {
return err
}
@ -265,7 +264,7 @@ func (m *TaskManager) loadTasks(ctx context.Context) error {
if err != nil {
return err
}
shimDirs, err := ioutil.ReadDir(filepath.Join(m.state, ns))
shimDirs, err := os.ReadDir(filepath.Join(m.state, ns))
if err != nil {
return err
}
@ -285,7 +284,7 @@ func (m *TaskManager) loadTasks(ctx context.Context) error {
return err
}
// fast path
bf, err := ioutil.ReadDir(bundle.Path)
bf, err := os.ReadDir(bundle.Path)
if err != nil {
bundle.Delete()
log.G(ctx).WithError(err).Errorf("fast path read bundle path for %s", bundle.Path)
@ -334,7 +333,7 @@ func (m *TaskManager) cleanupWorkDirs(ctx context.Context) error {
if err != nil {
return err
}
dirs, err := ioutil.ReadDir(filepath.Join(m.root, ns))
dirs, err := os.ReadDir(filepath.Join(m.root, ns))
if err != nil {
return err
}

View File

@ -22,7 +22,6 @@ package runc
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -175,7 +174,7 @@ func ReadOptions(path string) (*options.Options, error) {
return nil, err
}
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
@ -192,12 +191,12 @@ func WriteOptions(path string, opts options.Options) error {
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(path, optionsFilename), data, 0600)
return os.WriteFile(filepath.Join(path, optionsFilename), data, 0600)
}
// ReadRuntime reads the runtime information from the path
func ReadRuntime(path string) (string, error) {
data, err := ioutil.ReadFile(filepath.Join(path, "runtime"))
data, err := os.ReadFile(filepath.Join(path, "runtime"))
if err != nil {
return "", err
}
@ -206,7 +205,7 @@ func ReadRuntime(path string) (string, error) {
// WriteRuntime writes the runtime information into the path
func WriteRuntime(path, runtime string) error {
return ioutil.WriteFile(filepath.Join(path, "runtime"), []byte(runtime), 0600)
return os.WriteFile(filepath.Join(path, "runtime"), []byte(runtime), 0600)
}
func newInit(ctx context.Context, path, workDir, namespace string, platform stdio.Platform,

View File

@ -22,7 +22,7 @@ package runc
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/containerd/containerd/api/events"
@ -66,7 +66,7 @@ func GetTopic(e interface{}) string {
// there is an error reading the spec or if the container has a private PID namespace
func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
var bundleSpec specs.Spec
bundleConfigContents, err := ioutil.ReadFile(filepath.Join(bundlePath, "config.json"))
bundleConfigContents, err := os.ReadFile(filepath.Join(bundlePath, "config.json"))
if err != nil {
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json")
return true

Some files were not shown because too many files have changed in this diff Show More