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

V2: Replace deprecated ioutil. #451

Open
wants to merge 3 commits into
base: v2
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 client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -182,7 +181,7 @@ func (c *Client) get(ctx context.Context, req *Request, g Getter) (*GetResult, *
if decompressor != nil {
// Create a temporary directory to store our archive. We delete
// this at the end of everything.
td, err := ioutil.TempDir("", "getter")
td, err := os.MkdirTemp("", "getter")
if err != nil {
return nil, &getError{true, fmt.Errorf(
"Error creating temporary directory for archive: %s", err)}
Expand Down
4 changes: 2 additions & 2 deletions common.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package getter

import (
"io/ioutil"
"os"
)

func tmpFile(dir, pattern string) (string, error) {
f, err := ioutil.TempFile(dir, pattern)
f, err := os.CreateTemp(dir, pattern)
if err != nil {
return "", err
}
Expand Down
15 changes: 4 additions & 11 deletions decompress_tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package getter
import (
"archive/tar"
"bytes"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -79,14 +78,11 @@ func TestTarLimits(t *testing.T) {
t.Fatal(err)
}

td, err := ioutil.TempDir("", "getter")
if err != nil {
t.Fatalf("err: %s", err)
}
td := t.TempDir()

tarFilePath := filepath.Join(td, "input.tar")

err = ioutil.WriteFile(tarFilePath, b.Bytes(), 0666)
err := os.WriteFile(tarFilePath, b.Bytes(), 0666)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down Expand Up @@ -130,15 +126,12 @@ func TestTarLimits(t *testing.T) {

// testDecompressPermissions decompresses a directory and checks the permissions of the expanded files
func testDecompressorPermissions(t *testing.T, d Decompressor, input string, expected map[string]int, umask os.FileMode) {
td, err := ioutil.TempDir("", "getter")
if err != nil {
t.Fatalf("err: %s", err)
}
td := t.TempDir()

// Destination is always joining result so that we have a new path
dst := filepath.Join(td, "subdir", "result")

err = d.Decompress(dst, input, true, umask)
err := d.Decompress(dst, input, true, umask)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions decompress_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/md5"
"encoding/hex"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -34,7 +33,7 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
t.Logf("Testing: %s", tc.Input)

// Temporary dir to store stuff
td, err := ioutil.TempDir("", "getter")
td, err := os.MkdirTemp("", "getter")
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
8 changes: 2 additions & 6 deletions decompress_zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package getter
import (
"archive/zip"
"bytes"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -166,14 +165,11 @@ func TestDecompressZipBomb(t *testing.T) {
}
}

td, err := ioutil.TempDir("", "go-getter-zip")
if err != nil {
t.Fatalf("err: %s", err)
}
td := t.TempDir()

zipFilePath := filepath.Join(td, "input.zip")

err = ioutil.WriteFile(zipFilePath, buf.Bytes(), 0666)
err := os.WriteFile(zipFilePath, buf.Bytes(), 0666)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
8 changes: 2 additions & 6 deletions get_file_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package getter

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -13,16 +12,13 @@ import (
// If a relative symlink is passed in as the pwd to Detect, the resulting URL
// can have an invalid path.
func TestFileDetector_relativeSymlink(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "go-getter")
if err != nil {
t.Fatal(err)
}
tmpDir := t.TempDir()

defer os.RemoveAll(tmpDir)

// We may have a symlinked tmp dir,
// e.g. OSX uses /var -> /private/var
tmpDir, err = filepath.EvalSymlinks(tmpDir)
tmpDir, err := filepath.EvalSymlinks(tmpDir)
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions get_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/base64"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -96,7 +95,7 @@ func (g *GitGetter) Get(ctx context.Context, req *Request) error {
}

// Create a temp file for the key and ensure it is removed.
fh, err := ioutil.TempFile("", "go-getter")
fh, err := os.CreateTemp("", "go-getter")
if err != nil {
return err
}
Expand Down
15 changes: 4 additions & 11 deletions get_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -323,14 +322,11 @@ func TestGitGetter_gitVersion(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping on windows since the test requires sh")
}
dir, err := ioutil.TempDir("", "go-getter")
if err != nil {
t.Fatal(err)
}
dir := t.TempDir()
defer os.RemoveAll(dir)

script := filepath.Join(dir, "git")
err = ioutil.WriteFile(
err := os.WriteFile(
script,
[]byte("#!/bin/sh\necho \"git version 2.0 (Some Metadata Here)\n\""),
0700)
Expand Down Expand Up @@ -999,10 +995,7 @@ type gitRepo struct {

// testGitRepo creates a new test git repository.
func testGitRepo(t *testing.T, name string) *gitRepo {
dir, err := ioutil.TempDir("", "go-getter")
if err != nil {
t.Fatal(err)
}
dir := t.TempDir()
dir = filepath.Join(dir, name)
if err := os.Mkdir(dir, 0700); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1041,7 +1034,7 @@ func (r *gitRepo) git(args ...string) {
// commitFile writes and commits a text file to the repo.
func (r *gitRepo) commitFile(file, content string) {
path := filepath.Join(r.dir, file)
if err := ioutil.WriteFile(path, []byte(content), 0600); err != nil {
if err := os.WriteFile(path, []byte(content), 0600); err != nil {
r.t.Fatal(err)
}
r.git("add", file)
Expand Down
12 changes: 4 additions & 8 deletions get_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -305,7 +304,7 @@ func TestHttpGetter_resume(t *testing.T) {
t.Fatalf("finishing download should not error: %v", err)
}

b, err := ioutil.ReadFile(dst)
b, err := os.ReadFile(dst)
if err != nil {
t.Fatalf("readfile failed: %v", err)
}
Expand Down Expand Up @@ -362,7 +361,7 @@ func TestHttpGetter_resumeNoRange(t *testing.T) {
t.Fatalf("finishing download should not error: %v", err)
}

b, err := ioutil.ReadFile(dst)
b, err := os.ReadFile(dst)
if err != nil {
t.Fatalf("readfile failed: %v", err)
}
Expand Down Expand Up @@ -804,10 +803,7 @@ func TestHttpGetter_subdirLink(t *testing.T) {
ln := testHttpServerSubDir(t)
defer ln.Close()

dst, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
dst := t.TempDir()

t.Logf("dst: %q", dst)

Expand All @@ -829,7 +825,7 @@ func TestHttpGetter_subdirLink(t *testing.T) {
GetMode: ModeAny,
}

_, err = client.Get(ctx, &req)
_, err := client.Get(ctx, &req)
if err != nil {
t.Fatalf("get err: %v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions helper/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testing

import (
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand All @@ -11,7 +10,7 @@ import (
)

func TempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "tf")
dir, err := os.MkdirTemp("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -28,7 +27,7 @@ func TempTestFile(t *testing.T) string {
}

func AssertContents(t *testing.T, path string, contents string) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("err: %s", err)
}
Expand All @@ -41,7 +40,7 @@ func AssertContents(t *testing.T, path string, contents string) {
// TempFileWithContent writes a temporary file and returns the path and a function
// to clean it up.
func TempFileWithContent(t *testing.T, contents string) (string, func()) {
tf, err := ioutil.TempFile("", "getter")
tf, err := os.CreateTemp("", "getter")
if err != nil {
t.Fatalf("err: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion s3/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hashicorp/go-getter/s3/v2

go 1.18
go 1.19

replace github.com/hashicorp/go-getter/v2 => ../

Expand Down
6 changes: 1 addition & 5 deletions source_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package getter

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -54,10 +53,7 @@ func TestSourceDirSubdir(t *testing.T) {
}

func TestSourceSubdirGlob(t *testing.T) {
td, err := ioutil.TempDir("", "subdir-glob")
if err != nil {
t.Fatal(err)
}
td := t.TempDir()
defer os.RemoveAll(td)

if err := os.Mkdir(filepath.Join(td, "subdir"), 0755); err != nil {
Expand Down
Loading