Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #411

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/kbld/kbld.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package main

import (
"io/ioutil"
"io"
"log"
"math/rand"
"os"
Expand All @@ -18,7 +18,7 @@ import (
func main() {
rand.Seed(time.Now().UTC().UnixNano())

log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)

// TODO logs
// TODO log flags used
Expand Down
3 changes: 1 addition & 2 deletions pkg/kbld/cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -235,7 +234,7 @@ func (o *ResolveOptions) withImageMapConf(conf ctlconf.Conf) (ctlconf.Conf, erro
return conf, nil
}

bs, err := ioutil.ReadFile(o.ImageMapFile)
bs, err := os.ReadFile(o.ImageMapFile)
if err != nil {
return ctlconf.Conf{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kbld/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package config

import (
"fmt"
"io/ioutil"
"os"

semver "github.com/hashicorp/go-version"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/lockconfig"
Expand Down Expand Up @@ -328,7 +328,7 @@ func (d Config) WriteToFile(path string) error {
return err
}

err = ioutil.WriteFile(path, bs, 0600)
err = os.WriteFile(path, bs, 0600)
if err != nil {
return fmt.Errorf("Writing lock config: %s", err)
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/kbld/image/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package image_test
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -59,7 +58,7 @@ func TestGitRepoValidNonEmptyRepo(t *testing.T) {
}

func TestGitRepoValidNoCommit(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -91,7 +90,7 @@ func TestGitRepoValidNoCommit(t *testing.T) {
}

func TestGitRepoValidNotOnBranch(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -126,7 +125,7 @@ func TestGitRepoValidNotOnBranch(t *testing.T) {
}

func TestGitRepoValidSubDir(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -165,7 +164,7 @@ func TestGitRepoValidSubDir(t *testing.T) {
}

func TestGitRepoValidNonGit(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -195,7 +194,7 @@ func TestGitRepoValidNonGit(t *testing.T) {
}

func TestGitRepoRemoteURL(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -226,7 +225,7 @@ func TestGitRepoRemoteURL(t *testing.T) {
}

func TestGitRepoHeadSHA(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down Expand Up @@ -258,7 +257,7 @@ func TestGitRepoHeadSHA(t *testing.T) {
}

func TestGitRepoIsDirty(t *testing.T) {
dir, err := ioutil.TempDir("", "kbld-git-repo")
dir, err := os.MkdirTemp("", "kbld-git-repo")
if err != nil {
t.Fatalf("Making tmp dir: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kbld/imagetar/tar_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package imagetar

import (
"io/ioutil"
"io"

"github.com/vmware-tanzu/carvel-kbld/pkg/kbld/imagedesc"
)
Expand All @@ -25,7 +25,7 @@ func (r TarReader) Read() ([]imagedesc.ImageOrIndex, error) {
return nil, err
}

manifestBytes, err := ioutil.ReadAll(manifestFile)
manifestBytes, err := io.ReadAll(manifestFile)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kbld/imageutils/and/and_closer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package and

import (
"bytes"
"io/ioutil"
"io"
"testing"
)

Expand All @@ -38,7 +38,7 @@ func TestRead(t *testing.T) {
},
}

data, err := ioutil.ReadAll(rac)
data, err := io.ReadAll(rac)
if err != nil {
t.Errorf("ReadAll(rac) = %v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/kbld/imageutils/gzip/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ package gzip
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"strings"
"testing"
)

func TestReader(t *testing.T) {
want := "This is the input string."
buf := bytes.NewBufferString(want)
zipped := ReadCloser(ioutil.NopCloser(buf))
zipped := ReadCloser(io.NopCloser(buf))
unzipped, err := UnzipReadCloser(zipped)
if err != nil {
t.Error("UnzipReadCloser() =", err)
}

b, err := ioutil.ReadAll(unzipped)
b, err := io.ReadAll(unzipped)
if err != nil {
t.Error("ReadAll() =", err)
}
Expand Down Expand Up @@ -86,17 +86,17 @@ func TestReadErrors(t *testing.T) {
t.Error("Is: expected errRead, got", err)
}

frc := ioutil.NopCloser(fr)
frc := io.NopCloser(fr)
if _, err := UnzipReadCloser(frc); err != errRead {
t.Error("UnzipReadCloser: expected errRead, got", err)
}

zr := ReadCloser(ioutil.NopCloser(fr))
zr := ReadCloser(io.NopCloser(fr))
if _, err := zr.Read(nil); err != errRead {
t.Error("ReadCloser: expected errRead, got", err)
}

zr = ReadCloserLevel(ioutil.NopCloser(strings.NewReader("zip me")), -10)
zr = ReadCloserLevel(io.NopCloser(strings.NewReader("zip me")), -10)
if _, err := zr.Read(nil); err == nil {
t.Error("Expected invalid level error, got:", err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/kbld/imageutils/verify/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package verify

import (
"bytes"
"io/ioutil"
"io"
"strings"
"testing"

Expand All @@ -40,11 +40,11 @@ func TestVerificationFailure(t *testing.T) {
want := "This is the input string."
buf := bytes.NewBufferString(want)

verified, err := ReadCloser(ioutil.NopCloser(buf), mustHash("not the same", t))
verified, err := ReadCloser(io.NopCloser(buf), mustHash("not the same", t))
if err != nil {
t.Fatal("ReadCloser() =", err)
}
if b, err := ioutil.ReadAll(verified); err == nil {
if b, err := io.ReadAll(verified); err == nil {
t.Errorf("ReadAll() = %q; want verification error", string(b))
}
}
Expand All @@ -53,11 +53,11 @@ func TestVerification(t *testing.T) {
want := "This is the input string."
buf := bytes.NewBufferString(want)

verified, err := ReadCloser(ioutil.NopCloser(buf), mustHash(want, t))
verified, err := ReadCloser(io.NopCloser(buf), mustHash(want, t))
if err != nil {
t.Fatal("ReadCloser() =", err)
}
if _, err := ioutil.ReadAll(verified); err != nil {
if _, err := io.ReadAll(verified); err != nil {
t.Error("ReadAll() =", err)
}
}
Expand All @@ -67,7 +67,7 @@ func TestBadHash(t *testing.T) {
Algorithm: "fake256",
Hex: "whatever",
}
_, err := ReadCloser(ioutil.NopCloser(strings.NewReader("hi")), h)
_, err := ReadCloser(io.NopCloser(strings.NewReader("hi")), h)
if err == nil {
t.Errorf("ReadCloser() = %v, wanted err", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kbld/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
"time"

regauthn "github.com/google/go-containerregistry/pkg/authn"
Expand Down Expand Up @@ -158,7 +158,7 @@ func newHTTPTransport(opts Opts) (*http.Transport, error) {

if len(opts.CACertPaths) > 0 {
for _, path := range opts.CACertPaths {
if certs, err := ioutil.ReadFile(path); err != nil {
if certs, err := os.ReadFile(path); err != nil {
return nil, fmt.Errorf("Reading CA certificates from '%s': %s", path, err)
} else if ok := pool.AppendCertsFromPEM(certs); !ok {
return nil, fmt.Errorf("Adding CA certificates from '%s': failed", path)
Expand Down
8 changes: 4 additions & 4 deletions pkg/kbld/resources/file_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package resources

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
)
Expand All @@ -24,7 +24,7 @@ func NewStdinSource() StdinSource { return StdinSource{} }
func (s StdinSource) Description() string { return "stdin" }

func (s StdinSource) Bytes() ([]byte, error) {
return ioutil.ReadAll(os.Stdin)
return io.ReadAll(os.Stdin)
sethiyash marked this conversation as resolved.
Show resolved Hide resolved
}

type LocalFileSource struct {
Expand All @@ -40,7 +40,7 @@ func (s LocalFileSource) Description() string {
}

func (s LocalFileSource) Bytes() ([]byte, error) {
return ioutil.ReadFile(s.path)
return os.ReadFile(s.path)
}

type HTTPFileSource struct {
Expand All @@ -63,7 +63,7 @@ func (s HTTPFileSource) Bytes() ([]byte, error) {

defer resp.Body.Close()

result, err := ioutil.ReadAll(resp.Body)
result, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Reading URL '%s': %s", s.url, err)
}
Expand Down
Loading