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

Remove deprecated package 'ioutil' #541

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions changelogutils/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -508,7 +507,7 @@ func createSubdirs(dir string, names ...string) error {
}

func mustWriteTestDir() string {
tmpDir, err := ioutil.TempDir("", "changelog-test-")
tmpDir, err := os.MkdirTemp("", "changelog-test-")
Expect(err).NotTo(HaveOccurred())
return tmpDir
}
Expand Down
4 changes: 2 additions & 2 deletions cliutils/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cliutils
import (
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -71,7 +71,7 @@ func PortForwardGet(ctx context.Context, namespace string, resource string, loca
time.Sleep(retryInterval)
continue
}
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
errs <- err
time.Sleep(retryInterval)
Expand Down
2 changes: 0 additions & 2 deletions contextutils/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ type exponentialBackoff struct {
MaxRetries uint
MaxDuration *time.Duration
MaxDelay time.Duration

start *time.Duration
}

func (e *exponentialBackoff) Backoff(ctx context.Context, f func(ctx context.Context) error) error {
Expand Down
6 changes: 3 additions & 3 deletions docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package docker_test

import (
"context"
"io/ioutil"
"os"
"os/exec"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -50,14 +50,14 @@ var _ = Describe("Docker", func() {
Context("Save", func() {
It("can save a valid, present container", func() {
pullValidImage()
file, err := ioutil.TempFile("", "docker_test")
file, err := os.CreateTemp("", "docker_test")
Expect(err).NotTo(HaveOccurred())
err = docker.Save(validImage, file.Name())
Expect(err).NotTo(HaveOccurred())
})

It("cannot save an invalid container", func() {
file, err := ioutil.TempFile("", "docker_test")
file, err := os.CreateTemp("", "docker_test")
Expect(err).NotTo(HaveOccurred())
err = docker.Save(invalidImage, file.Name())
Expect(err).To(HaveOccurred())
Expand Down
5 changes: 2 additions & 3 deletions fileutils/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"io/ioutil"
"os"

"github.com/gogo/protobuf/types"
Expand All @@ -14,7 +13,7 @@ import (
var _ = Describe("Messages", func() {
var filename string
BeforeEach(func() {
f, err := ioutil.TempFile("", "messages_test")
f, err := os.CreateTemp("", "messages_test")
Expect(err).NotTo(HaveOccurred())
filename = f.Name()
})
Expand All @@ -32,7 +31,7 @@ var _ = Describe("Messages", func() {
err := WriteToFile(filename, input)
Expect(err).NotTo(HaveOccurred())

b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
Expect(err).NotTo(HaveOccurred())

Expect(string(b)).To(Equal("foo: bar\n"))
Expand Down
5 changes: 2 additions & 3 deletions gcloudutils/builders/storage_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -104,7 +103,7 @@ func (sb *StorageBuilder) copyArchiveToStorage(ctx context.Context, builderCtx B
return nil, err
}

tmpf, err := ioutil.TempFile("", "*.tar.gz")
tmpf, err := os.CreateTemp("", "*.tar.gz")
if err != nil {
logger.Error().Err(err).Msg("can't create temp file")
return nil, err
Expand Down Expand Up @@ -169,7 +168,7 @@ func (sb *StorageBuilder) copyToBucket(ctx context.Context, builderCtx BuildCont
func removeGHPrefix(ctx context.Context, archiveFile string) (*os.File, error) {
logger := zerolog.Ctx(ctx)

tmpf, err := ioutil.TempFile("", "*.tar.gz")
tmpf, err := os.CreateTemp("", "*.tar.gz")
if err != nil {
logger.Error().Err(err).Msg("can't create temp file")
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions gcloudutils/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gcloudutils
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -41,7 +40,7 @@ func credsFromProjectId(ctx context.Context, projectId string) (*google.Credenti
contextutils.LoggerFrom(ctx).Debugw("Looking for creds for project",
zap.String("projectId", projectId),
zap.String("credsFile", pathToCredsFile))
credByt, err := ioutil.ReadFile(pathToCredsFile)
credByt, err := os.ReadFile(pathToCredsFile)
if err != nil {
contextutils.LoggerFrom(ctx).Errorw("Error reading creds file",
zap.Error(err),
Expand Down
5 changes: 2 additions & 3 deletions githubutils/githubutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package githubutils

import (
"context"
"io/ioutil"
"os"

"github.com/google/go-github/v32/github"
Expand Down Expand Up @@ -72,9 +71,9 @@ var _ = Describe("github utils", func() {
})

func mustSetupTempFiles() (file *os.File, dir string) {
tmpf, err := ioutil.TempFile("", "tar-file-")
tmpf, err := os.CreateTemp("", "tar-file-")
Expect(err).NotTo(HaveOccurred())
tmpd, err := ioutil.TempDir("", "tar-dir-")
tmpd, err := os.MkdirTemp("", "tar-dir-")
Expect(err).NotTo(HaveOccurred())
return tmpf, tmpd
}
3 changes: 1 addition & 2 deletions githubutils/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -139,7 +138,7 @@ func GetRawGitFile(ctx context.Context, client *github.Client, content *github.R
}
defer r.Close()

byt, err := ioutil.ReadAll(r)
byt, err := io.ReadAll(r)
return byt, err
}

Expand Down
3 changes: 1 addition & 2 deletions githubutils/upload_release_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/sha256"
"encoding/hex"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -121,7 +120,7 @@ func writeSha256OrExit(ctx context.Context, file *os.File, outputPath string) {
contextutils.LoggerFrom(ctx).Fatal(err)
}
sha256String := hex.EncodeToString(h.Sum(nil)) + " " + filepath.Base(file.Name()) + "\n"
err := ioutil.WriteFile(outputPath, []byte(sha256String), 0700)
err := os.WriteFile(outputPath, []byte(sha256String), 0700)
if err != nil {
contextutils.LoggerFrom(ctx).Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions osutils/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package osutils

import (
"io/ioutil"
"os"
)

Expand All @@ -18,7 +17,7 @@ func (*osClient) Getenv(key string) string {
}

func (*osClient) ReadFile(path string) ([]byte, error) {
return ioutil.ReadFile(path)
return os.ReadFile(path)
}

func NewOsClient() OsClient {
Expand Down
7 changes: 3 additions & 4 deletions pkgmgmtutils/internal/local_clone_change_pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -33,7 +32,7 @@ func (l *localCloneChangePusher) UpdateAndPush(
formulaOptions *formula_updater_types.FormulaOptions,
) error {
// create temp dir for local git clone
dirTemp, err := ioutil.TempDir("", formulaOptions.RepoName)
dirTemp, err := os.MkdirTemp("", formulaOptions.RepoName)
if err != nil {
return err
}
Expand Down Expand Up @@ -86,7 +85,7 @@ func (l *localCloneChangePusher) UpdateAndPush(

formulaPath := filepath.Join(dirTemp, formulaOptions.Path)

byt, err := ioutil.ReadFile(formulaPath)
byt, err := os.ReadFile(formulaPath)
if err != nil {
return err
}
Expand All @@ -98,7 +97,7 @@ func (l *localCloneChangePusher) UpdateAndPush(
}

// Write Updated file to git clone directory
err = ioutil.WriteFile(formulaPath, byt, 0644)
err = os.WriteFile(formulaPath, byt, 0644)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkgmgmtutils/internal/remote_sha_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package internal

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand All @@ -25,7 +25,7 @@ func (*remoteShaGetter) GetShaFromUrl(url string) (sha string, err error) {
}
defer resp.Body.Close()

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions securityscanutils/commands/format_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/gob"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -208,7 +208,7 @@ func GetSecurityScanReport(url string) (string, error) {

var report string
if resp.StatusCode == http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(resp.Body)
bodyBytes, _ := io.ReadAll(resp.Body)
report = string(bodyBytes)
} else if resp.StatusCode == http.StatusNotFound {
// Older releases may be missing scan results
Expand Down
5 changes: 2 additions & 3 deletions securityscanutils/securityscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package securityscanutils_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"sort"
Expand All @@ -28,7 +27,7 @@ var _ = Describe("Security Scan Suite", func() {

BeforeEach(func() {
var err error
outputDir, err = ioutil.TempDir("", "")
outputDir, err = os.MkdirTemp("", "")
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -215,7 +214,7 @@ var _ = Describe("Security Scan Suite", func() {
// Accepts a list of file names and passes all tests only if the directory path passed in
// as dir includes all fileNames passed in.
func ExpectDirToHaveFiles(dir string, fileNames ...string) {
dirResults, err := ioutil.ReadDir(dir)
dirResults, err := os.ReadDir(dir)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
ExpectWithOffset(1, dirResults).To(HaveLen(len(fileNames)))
var dirFiles []string
Expand Down
3 changes: 1 addition & 2 deletions securityscanutils/trivy_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package securityscanutils_test

import (
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -28,7 +27,7 @@ var _ = Describe("Trivy Scanner", func() {
t = NewTrivyScanner(executils.CombinedOutputWithStatus)
inputMarkdownTemplateFile, err = GetTemplateFile(MarkdownTrivyTemplate)
Expect(err).NotTo(HaveOccurred())
outputDir, err := ioutil.TempDir("", "")
outputDir, err := os.MkdirTemp("", "")
Expect(err).NotTo(HaveOccurred())
outputFile = filepath.Join(outputDir, "test_report.docgen")
inputImage = "quay.io/solo-io/gloo:1.11.1"
Expand Down
4 changes: 2 additions & 2 deletions securityscanutils/trivy_templates.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package securityscanutils

import (
"io/ioutil"
"os"

"github.com/rotisserie/eris"
)
Expand Down Expand Up @@ -30,7 +30,7 @@ Trivy Returned Empty Report
// Create tempoarary file that contains the trivy template
// Trivy CLI only accepts files as input for a template, so this is a workaround
func GetTemplateFile(trivyTemplate string) (string, error) {
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return "", eris.Wrap(err, "Unable to create temporary file to write template to")
}
Expand Down
4 changes: 2 additions & 2 deletions test/checks/checks_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package checks

import (
"io/ioutil"
"os"
"os/exec"
"strings"

Expand All @@ -19,7 +19,7 @@ var _ = Describe("Checks", func() {
gomod, err := exec.Command("go", "env", "GOMOD").CombinedOutput()
Expect(err).NotTo(HaveOccurred())
gomodfile := strings.TrimSpace(string(gomod))
data, err := ioutil.ReadFile(gomodfile)
data, err := os.ReadFile(gomodfile)
Expect(err).NotTo(HaveOccurred())

modFile, err := modfile.Parse(gomodfile, data, nil)
Expand Down
8 changes: 3 additions & 5 deletions testutils/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os/exec"
"path/filepath"

"io/ioutil"

"time"

"github.com/onsi/ginkgo/v2"
Expand All @@ -30,7 +28,7 @@ func NewConsulFactory() (*ConsulFactory, error) {
}

// try to grab one form docker...
tmpdir, err := ioutil.TempDir(os.Getenv("HELPER_TMP"), "consul")
tmpdir, err := os.MkdirTemp(os.Getenv("HELPER_TMP"), "consul")
if err != nil {
return nil, err
}
Expand All @@ -48,7 +46,7 @@ docker rm -f $CID
`, defaultConsulDockerImage, defaultConsulDockerImage)
scriptfile := filepath.Join(tmpdir, "getconsul.sh")

ioutil.WriteFile(scriptfile, []byte(bash), 0755)
os.WriteFile(scriptfile, []byte(bash), 0755)

cmd := exec.Command("bash", scriptfile)
cmd.Dir = tmpdir
Expand Down Expand Up @@ -83,7 +81,7 @@ type ConsulInstance struct {

func (ef *ConsulFactory) NewConsulInstance() (*ConsulInstance, error) {
// try to grab one form docker...
tmpdir, err := ioutil.TempDir(os.Getenv("HELPER_TMP"), "consul")
tmpdir, err := os.MkdirTemp(os.Getenv("HELPER_TMP"), "consul")
if err != nil {
return nil, err
}
Expand Down
Loading