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

Replace deprecated ioutil usage with the equivalent replacements #198

Merged
merged 2 commits into from
Apr 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions build/git_revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package build
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"time"
Expand All @@ -23,7 +23,7 @@ var (
defaultCloneTimeout = 5 * time.Minute
defaultBuildTimeout = 25 * time.Minute

discardLogger = log.New(ioutil.Discard, "", 0)
discardLogger = log.New(io.Discard, "", 0)
)

// GitRevision installs a particular git revision by cloning
Expand Down Expand Up @@ -101,7 +101,7 @@ func (gr *GitRevision) Build(ctx context.Context) (string, error) {
gr.pathsToRemove = make([]string, 0)
}

repoDir, err := ioutil.TempDir("",
repoDir, err := os.MkdirTemp("",
fmt.Sprintf("hc-install-build-%s", gr.Product.Name))
if err != nil {
return "", err
Expand Down Expand Up @@ -160,7 +160,7 @@ func (gr *GitRevision) Build(ctx context.Context) (string, error) {
}
installDir := gr.InstallDir
if installDir == "" {
tmpDir, err := ioutil.TempDir("",
tmpDir, err := os.MkdirTemp("",
fmt.Sprintf("hc-install-%s-%s", gr.Product.Name, head.Hash()))
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions checkpoint/latest_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package checkpoint
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -24,7 +24,7 @@ import (

var (
defaultTimeout = 30 * time.Second
discardLogger = log.New(ioutil.Discard, "", 0)
discardLogger = log.New(io.Discard, "", 0)
)

// LatestVersion installs the latest version known to Checkpoint
Expand Down Expand Up @@ -101,7 +101,7 @@ func (lv *LatestVersion) Install(ctx context.Context) (string, error) {
if dstDir == "" {
var err error
dirName := fmt.Sprintf("%s_*", lv.Product.Name)
dstDir, err = ioutil.TempDir("", dirName)
dstDir, err = os.MkdirTemp("", dirName)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package fs

import (
"io/ioutil"
"io"
"log"
"time"
)

var (
defaultTimeout = 10 * time.Second
discardLogger = log.New(ioutil.Discard, "", 0)
discardLogger = log.New(io.Discard, "", 0)
)

type fileCheckFunc func(path string) error
4 changes: 2 additions & 2 deletions installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package install
import (
"context"
"fmt"
"io/ioutil"
"io"
"log"

"github.com/hashicorp/go-multierror"
Expand All @@ -23,7 +23,7 @@ type Installer struct {
type RemoveFunc func(ctx context.Context) error

func NewInstaller() *Installer {
discardLogger := log.New(ioutil.Discard, "", 0)
discardLogger := log.New(io.Discard, "", 0)
return &Installer{
logger: discardLogger,
}
Expand Down
8 changes: 4 additions & 4 deletions internal/build/go_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"os/exec"
Expand All @@ -17,7 +17,7 @@ import (
"golang.org/x/mod/modfile"
)

var discardLogger = log.New(ioutil.Discard, "", 0)
var discardLogger = log.New(io.Discard, "", 0)

// GoBuild represents a Go builder (to run "go build")
type GoBuild struct {
Expand Down Expand Up @@ -161,7 +161,7 @@ type CleanupFunc func(context.Context)
func guessRequiredGoVersion(repoDir string) (*version.Version, bool) {
goEnvFile := filepath.Join(repoDir, ".go-version")
if fi, err := os.Stat(goEnvFile); err == nil && !fi.IsDir() {
b, err := ioutil.ReadFile(goEnvFile)
b, err := os.ReadFile(goEnvFile)
if err != nil {
return nil, false
}
Expand All @@ -174,7 +174,7 @@ func guessRequiredGoVersion(repoDir string) (*version.Version, bool) {

goModFile := filepath.Join(repoDir, "go.mod")
if fi, err := os.Stat(goModFile); err == nil && !fi.IsDir() {
b, err := ioutil.ReadFile(goModFile)
b, err := os.ReadFile(goModFile)
if err != nil {
return nil, false
}
Expand Down
3 changes: 1 addition & 2 deletions internal/releasesjson/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -106,7 +105,7 @@ func (d *Downloader) DownloadAndUnpack(ctx context.Context, pv *ProductVersion,

expectedSize := resp.ContentLength

pkgFile, err := ioutil.TempFile("", pb.Filename)
pkgFile, err := os.CreateTemp("", pb.Filename)
if err != nil {
return "", err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/releasesjson/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -55,7 +55,7 @@ type Releases struct {

func NewReleases() *Releases {
return &Releases{
logger: log.New(ioutil.Discard, "", 0),
logger: log.New(io.Discard, "", 0),
BaseURL: defaultBaseURL,
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (r *Releases) ListProductVersions(ctx context.Context, productName string)

r.logger.Printf("received %s", resp.Status)

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func (r *Releases) GetProductVersion(ctx context.Context, product string, versio

r.logger.Printf("received %s", resp.Status)

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/testutil/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package testutil

import (
"io/ioutil"
"io"
"log"
"os"
"testing"
Expand All @@ -14,5 +14,5 @@ func TestLogger() *log.Logger {
if testing.Verbose() {
return log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile)
}
return log.New(ioutil.Discard, "", 0)
return log.New(io.Discard, "", 0)
}
3 changes: 1 addition & 2 deletions releases/exact_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package releases
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -93,7 +92,7 @@ func (ev *ExactVersion) Install(ctx context.Context) (string, error) {
if dstDir == "" {
var err error
dirName := fmt.Sprintf("%s_*", ev.Product.Name)
dstDir, err = ioutil.TempDir("", dirName)
dstDir, err = os.MkdirTemp("", dirName)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions releases/latest_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package releases
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (lv *LatestVersion) Install(ctx context.Context) (string, error) {
if dstDir == "" {
var err error
dirName := fmt.Sprintf("%s_*", lv.Product.Name)
dstDir, err = ioutil.TempDir("", dirName)
dstDir, err = os.MkdirTemp("", dirName)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions releases/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
package releases

import (
"io/ioutil"
"io"
"log"
"time"
)

var (
defaultInstallTimeout = 30 * time.Second
defaultListTimeout = 10 * time.Second
discardLogger = log.New(ioutil.Discard, "", 0)
discardLogger = log.New(io.Discard, "", 0)
)
6 changes: 3 additions & 3 deletions releases/releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package releases
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -158,7 +158,7 @@ func BenchmarkExactVersion(b *testing.B) {
mockApiRoot := filepath.Join("testdata", "mock_api_tf_0_14_with_prereleases")

for i := 0; i < b.N; i++ {
installDir, err := ioutil.TempDir("", fmt.Sprintf("%s_%d", "terraform", i))
installDir, err := os.MkdirTemp("", fmt.Sprintf("%s_%d", "terraform", i))
if err != nil {
b.Fatal(err)
}
Expand All @@ -183,7 +183,7 @@ func BenchmarkExactVersion(b *testing.B) {

func getTestPubKey(t testing.TB) string {
f, err := os.Open(filepath.Join("testdata", "2FCA0A85.pub"))
b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions releases/testdata/terraform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *VersionCommand) Run(args []string) int {

func defaultFlagSet(name string) *flag.FlagSet {
f := flag.NewFlagSet(name, flag.ContinueOnError)
f.SetOutput(ioutil.Discard)
f.SetOutput(io.Discard)
f.Usage = func() {}
return f
}
Expand Down