Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
stop using the deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
web3-bot committed Aug 29, 2022
1 parent 19d8184 commit ed81b81
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
fp "path/filepath"
"strings"
Expand Down Expand Up @@ -283,7 +282,7 @@ func (te *Extractor) extractFile(path string, r *tar.Reader) error {
// Create a temporary file in the target directory and then rename the temporary file to the target to better deal
// with races on the file system.
base := fp.Dir(path)
tmpfile, err := ioutil.TempFile(base, "")
tmpfile, err := os.CreateTemp(base, "")
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
fp "path/filepath"
"runtime"
Expand All @@ -23,7 +22,7 @@ func init() {
// check if the platform supports symlinks
// inspired by https://github.com/golang/go/blob/770f1de8c54256d5b17447028e47b201ba8e62c8/src/internal/testenv/testenv_windows.go#L17

tmpdir, err := ioutil.TempDir("", "platformsymtest")
tmpdir, err := os.MkdirTemp("", "platformsymtest")
if err != nil {
panic("failed to create temp directory: " + err.Error())
}
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestSingleFile(t *testing.T) {
func(t *testing.T, extractDir string) {
f, err := os.Open(fp.Join(extractDir, fileName))
assert.NoError(t, err)
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
assert.NoError(t, err)
assert.Equal(t, fileData, string(data))
assert.NoError(t, f.Close())
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestDirectoryFollowSymlinkToFile(t *testing.T) {
testTarExtraction(t, func(t *testing.T, rootDir string) {
target := fp.Join(rootDir, tarOutRoot)
symlinkTarget := fp.Join(target, "foo")
if err := ioutil.WriteFile(symlinkTarget, []byte("original data"), os.ModePerm); err != nil {
if err := os.WriteFile(symlinkTarget, []byte("original data"), os.ModePerm); err != nil {
t.Fatal(err)
}
if err := os.Symlink(symlinkTarget, fp.Join(target, childName)); err != nil {
Expand Down Expand Up @@ -318,7 +317,7 @@ func testTarExtraction(t *testing.T, setup func(t *testing.T, rootDir string), t
// Directory structure.
// FIXME: We can't easily work on a MemFS since we would need to replace
// all the `os` calls in the extractor so using a temporary dir.
rootDir, err := ioutil.TempDir("", "tar-extraction-test")
rootDir, err := os.MkdirTemp("", "tar-extraction-test")
assert.NoError(t, err)
extractDir := fp.Join(rootDir, tarOutRoot)
err = os.MkdirAll(extractDir, 0755)
Expand Down
2 changes: 1 addition & 1 deletion sanitize_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
)

//https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
var reservedNames = [...]string{"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"}

const reservedCharsStr = `[<>:"\|?*]` + "\x00" //NOTE: `/` is not included as it is our standard path separator
Expand Down

0 comments on commit ed81b81

Please sign in to comment.