Skip to content

Commit

Permalink
Merge pull request #1331 from testwill/ioutil
Browse files Browse the repository at this point in the history
chore: remove refs to deprecated io/ioutil
  • Loading branch information
tomkennedy513 authored Sep 27, 2023
2 parents 4d30b2a + ebd0a71 commit 2a98bed
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 124 deletions.
3 changes: 1 addition & 2 deletions cmd/rebase/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -134,7 +133,7 @@ func rebase(tags []string, logger *log.Logger) error {
return err
}

return ioutil.WriteFile(*reportFilePath, buf.Bytes(), 0777)
return os.WriteFile(*reportFilePath, buf.Bytes(), 0777)
}

func logLoadingSecrets(logger *log.Logger, secretsSlices ...[]string) {
Expand Down
5 changes: 2 additions & 3 deletions hack/lifecycle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -193,7 +192,7 @@ func lifecycleLayer(url, os string) (v1.Layer, error) {
return nil, err
}

buf, err := ioutil.ReadAll(tr)
buf, err := io.ReadAll(tr)
if err != nil {
return nil, err
}
Expand All @@ -210,7 +209,7 @@ func lifecycleLayer(url, os string) (v1.Layer, error) {
}

func lifecycleReader(url string) (io.ReadCloser, error) {
dir, err := ioutil.TempDir("", "lifecycle")
dir, err := os.MkdirTemp("", "lifecycle")
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/blob/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blob

import (
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -74,7 +73,7 @@ func downloadBlob(blobURL string) (*os.File, error) {
return nil, errors.Errorf("failed to get blob %s", blobURL)
}

file, err := ioutil.TempFile("", "")
file, err := os.CreateTemp("", "")
if err != nil {
return nil, err
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/blob/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blob_test
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -35,7 +34,7 @@ func testBlobFetcher(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dir, err = ioutil.TempDir("", "fetch_test")
dir, err = os.MkdirTemp("", "fetch_test")
require.NoError(t, err)
})

Expand All @@ -49,21 +48,21 @@ func testBlobFetcher(t *testing.T, when spec.G, it spec.S) {
err := fetcher.Fetch(dir, fmt.Sprintf("%s/%s", server.URL, testFile), 0)
require.NoError(t, err)

files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err)
require.Len(t, files, 1)
testDir := files[0]
require.Equal(t, "testdir", testDir.Name())
require.True(t, testDir.IsDir())

files, err = ioutil.ReadDir(filepath.Join(dir, testDir.Name()))
files, err = os.ReadDir(filepath.Join(dir, testDir.Name()))
require.NoError(t, err)
require.Len(t, files, 1)

testFile := files[0]
require.Equal(t, "testfile", testFile.Name())
require.False(t, testFile.IsDir())
file, err := ioutil.ReadFile(filepath.Join(dir, testDir.Name(), testFile.Name()))
file, err := os.ReadFile(filepath.Join(dir, testDir.Name(), testFile.Name()))
require.NoError(t, err)
require.Equal(t, "test file contents", string(file))

Expand All @@ -78,14 +77,15 @@ func testBlobFetcher(t *testing.T, when spec.G, it spec.S) {
err := fetcher.Fetch(dir, fmt.Sprintf("%s/%s", server.URL, "fat-zip.zip"), 0)
require.NoError(t, err)

files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err)
require.Len(t, files, 1)

testFile := files[0]
require.Equal(t, "some-file.txt", testFile.Name())

require.Equal(t, os.FileMode(0777).String(), testFile.Mode().String())
info, err := testFile.Info()
require.NoError(t, err)
require.Equal(t, os.FileMode(0777).String(), info.Mode().String())

require.Contains(t, output.String(), "Successfully downloaded")
})
Expand All @@ -94,15 +94,15 @@ func testBlobFetcher(t *testing.T, when spec.G, it spec.S) {
err := fetcher.Fetch(dir, fmt.Sprintf("%s/%s", server.URL, "test-exe.tar"), 0)
require.NoError(t, err)

files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err)
require.Len(t, files, 1)

testDir := files[0]
require.Equal(t, "test-exe", testDir.Name())
require.True(t, testDir.IsDir())

files, err = ioutil.ReadDir(filepath.Join(dir, testDir.Name()))
files, err = os.ReadDir(filepath.Join(dir, testDir.Name()))
require.NoError(t, err)
require.Len(t, files, 1)

Expand All @@ -120,7 +120,7 @@ func testBlobFetcher(t *testing.T, when spec.G, it spec.S) {
err := fetcher.Fetch(dir, fmt.Sprintf("%s/%s", server.URL, archiveFile), 1)
require.NoError(t, err)

files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
require.NoError(t, err)
require.Len(t, files, 1)

Expand Down
4 changes: 2 additions & 2 deletions pkg/cnb/build_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"encoding/base64"
"encoding/json"
"io/ioutil"
"io"

lifecyclebuildpack "github.com/buildpacks/lifecycle/buildpack"
"github.com/buildpacks/lifecycle/platform"
Expand Down Expand Up @@ -176,7 +176,7 @@ func DecompressBuildMetadata(compressedMetadata string) (*BuildMetadata, error)
return nil, err
}
defer zr.Close()
data, err := ioutil.ReadAll(zr)
data, err := io.ReadAll(zr)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cnb/env_vars.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cnb

import (
"io/ioutil"
"os"
"path"

Expand All @@ -17,7 +16,7 @@ func serializeEnvVars(envVars []envVariable, platformDir string) error {
}

for _, envVar := range envVars {
err = ioutil.WriteFile(path.Join(folder, envVar.Name), []byte(envVar.Value), os.ModePerm)
err = os.WriteFile(path.Join(folder, envVar.Name), []byte(envVar.Value), os.ModePerm)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cnb/platform_env_vars_setup_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cnb_test

import (
"io/ioutil"
"os"
"path"
"testing"
Expand All @@ -25,7 +24,7 @@ func testPlatformEnvVarsSetup(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
testVolume, err = ioutil.TempDir("", "permission")
testVolume, err = os.MkdirTemp("", "permission")
require.NoError(t, err)

platformEnv = map[string]string{
Expand Down Expand Up @@ -61,7 +60,7 @@ func testPlatformEnvVarsSetup(t *testing.T, when spec.G, it spec.S) {

func checkEnvVar(t *testing.T, testVolume, key, value string) {
require.FileExists(t, path.Join(testVolume, "env", key))
buf, err := ioutil.ReadFile(path.Join(testVolume, "env", key))
buf, err := os.ReadFile(path.Join(testVolume, "env", key))
require.NoError(t, err)
require.Equal(t, value, string(buf))
}
Loading

0 comments on commit 2a98bed

Please sign in to comment.