diff --git a/cmd/cpp/functions_framework/main_test.go b/cmd/cpp/functions_framework/main_test.go index 18f2159cf..feebefb87 100644 --- a/cmd/cpp/functions_framework/main_test.go +++ b/cmd/cpp/functions_framework/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -191,7 +190,7 @@ func TestPopulateMainLayer(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tc.name) + tmpDir, err := os.MkdirTemp("", tc.name) if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -213,20 +212,20 @@ func TestPopulateMainLayer(t *testing.T) { for _, name := range []string{"CMakeLists.txt", "vcpkg.json"} { path := filepath.Join(converter, name) - if ioutil.WriteFile(path, []byte(converterFileContents), 0644); err != nil { + if os.WriteFile(path, []byte(converterFileContents), 0644); err != nil { t.Fatalf("writing fake C++ support file (path=%s): %v", path, err) } } for _, name := range tc.sourceFiles { path := filepath.Join(fakeApp, name) - if ioutil.WriteFile(path, []byte(generatedFileContents), 0644); err != nil { + if os.WriteFile(path, []byte(generatedFileContents), 0644); err != nil { t.Fatalf("writing test C++ build file (name=%s): %v", name, err) } } if err := createMainCppSupportFiles(ctx, fakeMain, fakeBuildpackRoot); err != nil { t.Fatalf("creating support files in main layer: %v", err) } - vcpkgContents, err := ioutil.ReadFile(filepath.Join(fakeMain, "vcpkg.json")) + vcpkgContents, err := os.ReadFile(filepath.Join(fakeMain, "vcpkg.json")) if err != nil { t.Fatalf("reading vcpkg.json from main layer: %v", err) } @@ -234,7 +233,7 @@ func TestPopulateMainLayer(t *testing.T) { t.Errorf("mismatched contents in vcpkg.json, got=%s, want=%s", string(vcpkgContents), tc.vcpkgJSONContents) } - cmakeContents, err := ioutil.ReadFile(filepath.Join(fakeMain, "CMakeLists.txt")) + cmakeContents, err := os.ReadFile(filepath.Join(fakeMain, "CMakeLists.txt")) if err != nil { t.Fatalf("reading CMakeLists.txt from main layer: %v", err) } diff --git a/cmd/dotnet/publish/main_test.go b/cmd/dotnet/publish/main_test.go index 287477952..10a16afd2 100644 --- a/cmd/dotnet/publish/main_test.go +++ b/cmd/dotnet/publish/main_test.go @@ -16,7 +16,6 @@ package main import ( "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -82,14 +81,14 @@ func TestGetAssemblyName(t *testing.T) { for _, tc := range tcs { ctx := gcp.NewContext() t.Run(tc.name, func(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "dotnettest") + tmpDir, err := os.MkdirTemp("", "dotnettest") if err != nil { t.Fatalf("creating temp dir: %v", err) } defer os.RemoveAll(tmpDir) filename := filepath.Join(tmpDir, "app.csproj") - if err = ioutil.WriteFile(filename, []byte(tc.data), 0644); err != nil { + if err = os.WriteFile(filename, []byte(tc.data), 0644); err != nil { t.Fatalf("writing project file: %v", err) } @@ -159,7 +158,7 @@ func TestGetEntrypoint(t *testing.T) { t.Run(tc.name, func(t *testing.T) { ctx := gcp.NewContext() - tmpDir, err := ioutil.TempDir("", "dotnettest") + tmpDir, err := os.MkdirTemp("", "dotnettest") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -171,13 +170,13 @@ func TestGetEntrypoint(t *testing.T) { // Write the expected exe file. exe := filepath.Join(tmpDir, tc.exe) - if err = ioutil.WriteFile(exe, []byte(""), 0644); err != nil { + if err = os.WriteFile(exe, []byte(""), 0644); err != nil { t.Fatalf("writing exe file: %v", err) } // Write the project file. proj := filepath.Join(tmpDir, tc.proj) - if err = ioutil.WriteFile(proj, []byte(tc.data), 0644); err != nil { + if err = os.WriteFile(proj, []byte(tc.data), 0644); err != nil { t.Fatalf("writing proj file: %v", err) } diff --git a/cmd/go/appengine_gomod/main_test.go b/cmd/go/appengine_gomod/main_test.go index ab3f227bc..e9998ddc7 100644 --- a/cmd/go/appengine_gomod/main_test.go +++ b/cmd/go/appengine_gomod/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -105,7 +104,7 @@ func TestMainPath(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "TestMainPath-") + dir, err := os.MkdirTemp("", "TestMainPath-") if err != nil { t.Fatalf("Creating temporary directory: %v", err) } @@ -118,7 +117,7 @@ func TestMainPath(t *testing.T) { ctx := gcp.NewContext(gcp.WithApplicationRoot(dir)) if tc.stagerFileContents != "" { - if err = ioutil.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil { + if err = os.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil { t.Fatalf("Creating file in temporary directory: %v", err) } } diff --git a/cmd/go/flex_gomod/main_test.go b/cmd/go/flex_gomod/main_test.go index f30501ef9..2b7bb8439 100644 --- a/cmd/go/flex_gomod/main_test.go +++ b/cmd/go/flex_gomod/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -91,7 +90,7 @@ func TestMainPath(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "TestMainPath-") + dir, err := os.MkdirTemp("", "TestMainPath-") if err != nil { t.Fatalf("Creating temporary directory: %v", err) } @@ -104,7 +103,7 @@ func TestMainPath(t *testing.T) { ctx := gcp.NewContext(gcp.WithApplicationRoot(dir)) if tc.stagerFileContents != "" { - if err = ioutil.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil { + if err = os.WriteFile(filepath.Join(dir, "_main-package-path"), []byte(tc.stagerFileContents), 0755); err != nil { t.Fatalf("Creating file in temporary directory: %v", err) } } diff --git a/cmd/go/functions_framework/converter/get_package/main_test.go b/cmd/go/functions_framework/converter/get_package/main_test.go index 05b0670d5..ba8d31b59 100644 --- a/cmd/go/functions_framework/converter/get_package/main_test.go +++ b/cmd/go/functions_framework/converter/get_package/main_test.go @@ -16,7 +16,6 @@ package main import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -109,7 +108,7 @@ func init() { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "golang_bp_test") + dir, err := os.MkdirTemp("", "golang_bp_test") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -121,7 +120,7 @@ func init() { }() for f, c := range tc.files { - if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { t.Fatalf("writing file %s: %v", f, err) } } @@ -159,7 +158,7 @@ func TestExtractFailures(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "golang_bp_test") + dir, err := os.MkdirTemp("", "golang_bp_test") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -171,7 +170,7 @@ func TestExtractFailures(t *testing.T) { }() for f, c := range tc.files { - if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { t.Fatalf("writing file %s: %v", f, err) } } diff --git a/cmd/go/legacy_worker/converter/get_package/main_test.go b/cmd/go/legacy_worker/converter/get_package/main_test.go index a018032b9..723e6c38d 100644 --- a/cmd/go/legacy_worker/converter/get_package/main_test.go +++ b/cmd/go/legacy_worker/converter/get_package/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -44,7 +43,7 @@ func TestExtractPackageNameFromDir(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "golang_bp_test") + dir, err := os.MkdirTemp("", "golang_bp_test") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -56,7 +55,7 @@ func TestExtractPackageNameFromDir(t *testing.T) { }() for f, c := range tc.files { - if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { t.Fatalf("writing file %s: %v", f, err) } } @@ -98,7 +97,7 @@ func TestExtractPackageNameFromDirErrors(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - dir, err := ioutil.TempDir("", "golang_bp_test") + dir, err := os.MkdirTemp("", "golang_bp_test") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -110,7 +109,7 @@ func TestExtractPackageNameFromDirErrors(t *testing.T) { }() for f, c := range tc.files { - if err := ioutil.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, f), []byte(c), 0644); err != nil { t.Fatalf("writing file %s: %v", f, err) } } diff --git a/cmd/go/legacy_worker/main_test.go b/cmd/go/legacy_worker/main_test.go index 61850622f..ca5917f14 100644 --- a/cmd/go/legacy_worker/main_test.go +++ b/cmd/go/legacy_worker/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -110,7 +109,7 @@ func TestCreateMainGoFile(t *testing.T) { t.Fatalf("error creating file at path %q from worker template: %s", targetMain, err) } - b, err := ioutil.ReadFile(targetMain) + b, err := os.ReadFile(targetMain) if err != nil { t.Fatalf("error reading file at path %q: %s", targetMain, err) } @@ -151,7 +150,7 @@ replace fnmod => ./serverless_function_source_code` t.Fatalf("error creating file at path %q from go.mod template: %s", targetGoMod, err) } - b, err := ioutil.ReadFile(targetGoMod) + b, err := os.ReadFile(targetGoMod) if err != nil { t.Fatalf("error reading file at path %q: %s", targetGoMod, err) } diff --git a/cmd/java/maven/main.go b/cmd/java/maven/main.go index 951c4b0d8..700cf2d5f 100644 --- a/cmd/java/maven/main.go +++ b/cmd/java/maven/main.go @@ -19,7 +19,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -178,7 +177,7 @@ func addJvmConfig(ctx *gcp.Context) error { return nil } jvmOptions := "--add-opens java.base/java.lang=ALL-UNNAMED" - if err := ioutil.WriteFile(configFile, []byte(jvmOptions), 0644); err != nil { + if err := os.WriteFile(configFile, []byte(jvmOptions), 0644); err != nil { ctx.Logf("Could not create %s, reflection warnings may not be disabled: %v", configFile, err) } return nil diff --git a/cmd/java/maven/main_test.go b/cmd/java/maven/main_test.go index c71b554b7..59178de93 100644 --- a/cmd/java/maven/main_test.go +++ b/cmd/java/maven/main_test.go @@ -16,7 +16,6 @@ package main import ( "fmt" - "io/ioutil" "os" "strconv" "testing" @@ -105,7 +104,7 @@ func TestCrLfRewrite(t *testing.T) { ensureUnixLineEndings(gcp.NewContext(), tmpFile.Name()) - newContent, err := ioutil.ReadFile(tmpFile.Name()) + newContent, err := os.ReadFile(tmpFile.Name()) if err != nil { t.Fatal("Error reading updated temporary file", err) } diff --git a/cmd/java/native_image/main_test.go b/cmd/java/native_image/main_test.go index 400225c96..2728f61a9 100644 --- a/cmd/java/native_image/main_test.go +++ b/cmd/java/native_image/main_test.go @@ -17,7 +17,7 @@ package main import ( "archive/zip" "bytes" - "io/ioutil" + "os" "path" "path/filepath" "regexp" @@ -194,7 +194,7 @@ func setupTestJar(t *testing.T, mfContent []byte) string { } jarPath := filepath.Join(t.TempDir(), "test.jar") - if err := ioutil.WriteFile(jarPath, buff.Bytes(), 0644); err != nil { + if err := os.WriteFile(jarPath, buff.Bytes(), 0644); err != nil { t.Fatalf("failed to write to file %s: %v", jarPath, err) } return jarPath diff --git a/cmd/ruby/appengine/main_test.go b/cmd/ruby/appengine/main_test.go index 91ef9350a..a5fa24db6 100644 --- a/cmd/ruby/appengine/main_test.go +++ b/cmd/ruby/appengine/main_test.go @@ -15,7 +15,6 @@ package main import ( - "io/ioutil" "os" "path" "path/filepath" @@ -116,7 +115,7 @@ func TestEntrypoint(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tempDir, err := ioutil.TempDir("", "test-entrypoint-") + tempDir, err := os.MkdirTemp("", "test-entrypoint-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -131,7 +130,7 @@ func TestEntrypoint(t *testing.T) { if err := os.MkdirAll(path.Dir(fn), 0755); err != nil { t.Fatalf("creating dir %s: %v", path.Dir(fn), err) } - if err := ioutil.WriteFile(fn, []byte("content"), 0644); err != nil { + if err := os.WriteFile(fn, []byte("content"), 0644); err != nil { t.Fatalf("writing file %s: %v", fn, err) } } diff --git a/cmd/utils/archive_source/main_test.go b/cmd/utils/archive_source/main_test.go index 8085bb693..429466343 100644 --- a/cmd/utils/archive_source/main_test.go +++ b/cmd/utils/archive_source/main_test.go @@ -16,7 +16,6 @@ package main import ( "bytes" - "io/ioutil" "os" "os/exec" "path" @@ -125,7 +124,7 @@ func TestArchiveSource(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - appDir, err := ioutil.TempDir("", "app") + appDir, err := os.MkdirTemp("", "app") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -143,7 +142,7 @@ func TestArchiveSource(t *testing.T) { // File can be a normal file, symlink, or an empty directory. if f.Content != "" { - if err := ioutil.WriteFile(fn, []byte(f.Content), 0644); err != nil { + if err := os.WriteFile(fn, []byte(f.Content), 0644); err != nil { t.Fatalf("writing file %s: %v", fn, err) } } else if f.SymLink != "" { @@ -159,7 +158,7 @@ func TestArchiveSource(t *testing.T) { } // Archive the files in the app directory. - srcDir, err := ioutil.TempDir("", "src") + srcDir, err := os.MkdirTemp("", "src") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -211,11 +210,11 @@ func TestArchiveSource(t *testing.T) { // Compare file content if they are not directories. if !afi.IsDir() { - ac, err := ioutil.ReadFile(af) + ac, err := os.ReadFile(af) if err != nil { t.Fatalf("reading file %s: %v", af, err) } - sc, err := ioutil.ReadFile(sf) + sc, err := os.ReadFile(sf) if err != nil { t.Fatalf("reading file %s: %v", sf, err) } diff --git a/internal/buildpacktest/buildpacktest.go b/internal/buildpacktest/buildpacktest.go index 782722e5b..7bb00b26b 100644 --- a/internal/buildpacktest/buildpacktest.go +++ b/internal/buildpacktest/buildpacktest.go @@ -20,7 +20,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -302,7 +301,7 @@ func runBuildpackPhase(t *testing.T, cfg *config) (bool, error) { } } - if err := ioutil.WriteFile(fn, []byte(c), 0644); err != nil { + if err := os.WriteFile(fn, []byte(c), 0644); err != nil { return false, fmt.Errorf("writing file %s: %v", fn, err) } } diff --git a/internal/buildpacktestenv/buildpacktestenv.go b/internal/buildpacktestenv/buildpacktestenv.go index d2278fe8c..59624e8b7 100644 --- a/internal/buildpacktestenv/buildpacktestenv.go +++ b/internal/buildpacktestenv/buildpacktestenv.go @@ -19,7 +19,6 @@ package buildpacktestenv import ( "encoding/json" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -49,7 +48,7 @@ func TempWorkingDir(t *testing.T) (string, func()) { if err != nil { t.Fatalf("getting working dir: %v", err) } - newwd, err := ioutil.TempDir("", "source-") + newwd, err := os.MkdirTemp("", "source-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -70,19 +69,19 @@ func TempWorkingDir(t *testing.T) (string, func()) { // SetUpTempDirs sets up temp directories that mimic the layers of buildpacks. func SetUpTempDirs(t *testing.T) TempDirs { t.Helper() - LayersDir, err := ioutil.TempDir("", "layers-") + LayersDir, err := os.MkdirTemp("", "layers-") if err != nil { t.Fatalf("creating layers dir: %v", err) } - PlatformDir, err := ioutil.TempDir("", "platform-") + PlatformDir, err := os.MkdirTemp("", "platform-") if err != nil { t.Fatalf("creating platform dir: %v", err) } - CodeDir, err := ioutil.TempDir("", "CodeDir-") + CodeDir, err := os.MkdirTemp("", "CodeDir-") if err != nil { t.Fatalf("creating code dir: %v", err) } - BuildpackDir, err := ioutil.TempDir("", "buildpack-") + BuildpackDir, err := os.MkdirTemp("", "buildpack-") if err != nil { t.Fatalf("creating buildpack dir: %v", err) } @@ -100,7 +99,7 @@ name = "my-name" id = "%s" `, stack) - if err := ioutil.WriteFile(filepath.Join(BuildpackDir, "buildpack.toml"), []byte(buildpackTOML), 0644); err != nil { + if err := os.WriteFile(filepath.Join(BuildpackDir, "buildpack.toml"), []byte(buildpackTOML), 0644); err != nil { t.Fatalf("writing buildpack.toml: %v", err) } @@ -111,7 +110,7 @@ version = "entry-version" [entries.metadata] entry-meta-key = "entry-meta-value" ` - if err := ioutil.WriteFile(filepath.Join(BuildpackDir, "plan.toml"), []byte(planTOML), 0644); err != nil { + if err := os.WriteFile(filepath.Join(BuildpackDir, "plan.toml"), []byte(planTOML), 0644); err != nil { t.Fatalf("writing plan.toml: %v", err) } diff --git a/internal/checktools/checktools.go b/internal/checktools/checktools.go index 89aa44cb9..fb0bacb36 100644 --- a/internal/checktools/checktools.go +++ b/internal/checktools/checktools.go @@ -17,7 +17,6 @@ package checktools import ( "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -57,7 +56,7 @@ func Installed() error { // PackVersion checks that the installed pack has the correct version. func PackVersion() error { // pack requires $HOME to exist. - home, err := ioutil.TempDir("", "pack-home") + home, err := os.MkdirTemp("", "pack-home") if err != nil { return err } diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 2265e618b..66f247df1 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -19,7 +19,7 @@ import ( "crypto/sha256" "encoding/hex" "fmt" - "io/ioutil" + "os" "github.com/buildpacks/libcnb" @@ -43,7 +43,7 @@ func WithFiles(files ...string) Option { return func() ([]string, error) { var strings []string for _, f := range files { - b, err := ioutil.ReadFile(f) + b, err := os.ReadFile(f) if err != nil { return nil, err } diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 43964f966..f4dbfee15 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -15,7 +15,6 @@ package cache import ( - "io/ioutil" "os" "path/filepath" "sort" @@ -192,7 +191,7 @@ func TestWithFiles(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - temp, err := ioutil.TempDir("", "test-sha-") + temp, err := os.MkdirTemp("", "test-sha-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -232,7 +231,7 @@ func TestWithFilesError(t *testing.T) { } func TestHash_SameFileContentsYieldsSameHash(t *testing.T) { - temp, err := ioutil.TempDir("", "test-sha-same-contents-") + temp, err := os.MkdirTemp("", "test-sha-same-contents-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -255,7 +254,7 @@ func TestHash_SameFileContentsYieldsSameHash(t *testing.T) { } func TestHash_Uniqueness(t *testing.T) { - temp, err := ioutil.TempDir("", "test-sha-uniqueness-") + temp, err := os.MkdirTemp("", "test-sha-uniqueness-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -294,7 +293,7 @@ func TestHash_Uniqueness(t *testing.T) { func writeFile(t *testing.T, tempDir, name, contents string) string { t.Helper() fullName := filepath.Join(tempDir, name) - if err := ioutil.WriteFile(fullName, []byte(contents), 0644); err != nil { + if err := os.WriteFile(fullName, []byte(contents), 0644); err != nil { t.Fatalf("writing file %q: %v", fullName, err) } return fullName diff --git a/pkg/clearsource/clearsource_test.go b/pkg/clearsource/clearsource_test.go index 8a2e9b160..bf4eba0ee 100644 --- a/pkg/clearsource/clearsource_test.go +++ b/pkg/clearsource/clearsource_test.go @@ -14,7 +14,7 @@ package clearsource import ( - "io/ioutil" + "os" "path/filepath" "reflect" "testing" @@ -71,7 +71,7 @@ func TestPathsToRemove(t *testing.T) { tDir := t.TempDir() for _, file := range tc.files { path := filepath.Join(tDir, file) - if err := ioutil.WriteFile(path, []byte{}, 0644); err != nil { + if err := os.WriteFile(path, []byte{}, 0644); err != nil { t.Fatalf("writing to file %s: %v", path, err) } } diff --git a/pkg/dart/dart.go b/pkg/dart/dart.go index f59f112e6..94ccabc4a 100644 --- a/pkg/dart/dart.go +++ b/pkg/dart/dart.go @@ -18,7 +18,6 @@ package dart import ( "encoding/json" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -83,7 +82,7 @@ func fetchLatestSdkVersion() (string, error) { // dependency on build_runner. func HasBuildRunner(dir string) (bool, error) { f := filepath.Join(dir, "pubspec.yaml") - rawpjs, err := ioutil.ReadFile(f) + rawpjs, err := os.ReadFile(f) if os.IsNotExist(err) { // If there is no pubspec.yaml, there is no build_runner dependency. return false, nil diff --git a/pkg/devmode/devmode_test.go b/pkg/devmode/devmode_test.go index 463fda31b..8763906d5 100644 --- a/pkg/devmode/devmode_test.go +++ b/pkg/devmode/devmode_test.go @@ -16,7 +16,6 @@ package devmode import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -26,7 +25,7 @@ import ( ) func TestWriteAndRunScripts(t *testing.T) { - testDirRoot, err := ioutil.TempDir("", "test-layer-") + testDirRoot, err := os.MkdirTemp("", "test-layer-") if err != nil { t.Fatalf("Creating temp directory: %v", err) } @@ -74,7 +73,7 @@ func TestWriteAndRunScripts(t *testing.T) { bar := filepath.Join(tc.layerRoot, "bin", "build_and_run.sh") war := filepath.Join(tc.layerRoot, "bin", "watch_and_run.sh") - c, err := ioutil.ReadFile(bar) + c, err := os.ReadFile(bar) if err != nil { t.Fatal(err) } @@ -82,7 +81,7 @@ func TestWriteAndRunScripts(t *testing.T) { t.Errorf("build_and_run.sh = %q, want %q", string(c), tc.wantBuildAndRun) } - c, err = ioutil.ReadFile(war) + c, err = os.ReadFile(war) if err != nil { t.Fatal(err) } diff --git a/pkg/fetch/fetch.go b/pkg/fetch/fetch.go index 2ea9139d8..8e5a2ec89 100644 --- a/pkg/fetch/fetch.go +++ b/pkg/fetch/fetch.go @@ -20,7 +20,6 @@ import ( "compress/gzip" "encoding/json" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -97,7 +96,7 @@ func JSON(url string, v interface{}) error { return err } defer response.Body.Close() - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { return gcp.InternalErrorf("reading response body from %q: %v", url, err) } diff --git a/pkg/gcpbuildpack/builderoutput.go b/pkg/gcpbuildpack/builderoutput.go index 31a9ac60d..daaecbf93 100644 --- a/pkg/gcpbuildpack/builderoutput.go +++ b/pkg/gcpbuildpack/builderoutput.go @@ -17,7 +17,6 @@ package gcpbuildpack import ( "errors" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -99,7 +98,7 @@ func (ctx *Context) saveErrorOutput(err error) { // /bin/detect steps run in parallel, so they might compete over the output file. To eliminate // this competition, write to temp file, then `mv -f` to final location (last one in wins). tname := filepath.Join(outputDir, fmt.Sprintf("%s-%d", builderOutputFilename, rand.Int())) - if err := ioutil.WriteFile(tname, data, 0644); err != nil { + if err := os.WriteFile(tname, data, 0644); err != nil { ctx.Warnf("Failed to write %s, skipping structured error output: %v", tname, err) return } @@ -159,7 +158,7 @@ func (ctx *Context) saveSuccessOutput(duration time.Duration) { } // Previous buildpacks may have already written to the builder output file. if fnameExists { - content, err := ioutil.ReadFile(fname) + content, err := os.ReadFile(fname) if err != nil { ctx.Warnf("Failed to read %s, skipping statistics: %v", fname, err) return @@ -222,7 +221,7 @@ func (ctx *Context) saveSuccessOutput(duration time.Duration) { ctx.Warnf("Failed to create dir %s, skipping statistics: %v", outputDir, err) return } - if err := ioutil.WriteFile(fname, content, 0644); err != nil { + if err := os.WriteFile(fname, content, 0644); err != nil { ctx.Warnf("Failed to write %s, skipping statistics: %v", fname, err) return } diff --git a/pkg/gcpbuildpack/builderoutput_test.go b/pkg/gcpbuildpack/builderoutput_test.go index f8292d368..21dd56a45 100644 --- a/pkg/gcpbuildpack/builderoutput_test.go +++ b/pkg/gcpbuildpack/builderoutput_test.go @@ -16,7 +16,6 @@ package gcpbuildpack import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "strings" @@ -33,7 +32,7 @@ import ( func TestSaveErrorOutput(t *testing.T) { t.Cleanup(buildermetrics.Reset) - tempDir, err := ioutil.TempDir("", "save-error-output-") + tempDir, err := os.MkdirTemp("", "save-error-output-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -55,7 +54,7 @@ func TestSaveErrorOutput(t *testing.T) { ctx.saveErrorOutput(buildererror.Errorf(buildererror.StatusInternal, msg)) - data, err := ioutil.ReadFile(filepath.Join(tempDir, "output")) + data, err := os.ReadFile(filepath.Join(tempDir, "output")) if err != nil { t.Fatalf("TestSaveErrorOutput reading expected file $BUILDER_OUTPUT/output: %v", err) } @@ -453,7 +452,7 @@ func TestSaveBuilderSuccessOutput(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { t.Cleanup(buildermetrics.Reset) - tempDir, err := ioutil.TempDir("", "save-success-output-") + tempDir, err := os.MkdirTemp("", "save-success-output-") if err != nil { t.Fatalf("TestSaveBuilderSuccessOutput creating temp dir: %v", err) } @@ -469,7 +468,7 @@ func TestSaveBuilderSuccessOutput(t *testing.T) { if err != nil { t.Fatalf("Failed to marshal stats: %v", err) } - if err := ioutil.WriteFile(fname, content, 0644); err != nil { + if err := os.WriteFile(fname, content, 0644); err != nil { t.Fatalf("TestSaveBuilderSuccessOutput writing %s: %v", fname, err) } } @@ -486,7 +485,7 @@ func TestSaveBuilderSuccessOutput(t *testing.T) { ctx.saveSuccessOutput(dur) - content, err := ioutil.ReadFile(fname) + content, err := os.ReadFile(fname) if err != nil { t.Fatalf("Failed to read %s: %v", fname, err) } diff --git a/pkg/gcpbuildpack/exec_test.go b/pkg/gcpbuildpack/exec_test.go index 4c64e5979..1aae03541 100644 --- a/pkg/gcpbuildpack/exec_test.go +++ b/pkg/gcpbuildpack/exec_test.go @@ -16,7 +16,6 @@ package gcpbuildpack import ( "bytes" - "io/ioutil" "log" "os" "path/filepath" @@ -312,7 +311,7 @@ func TestExecWithEnvMultiple(t *testing.T) { } func TestExecWithWorkDir(t *testing.T) { - tdir, err := ioutil.TempDir("", "exec2-") + tdir, err := os.MkdirTemp("", "exec2-") if err != nil { t.Fatal(err) } @@ -649,7 +648,7 @@ func TestExecWithCRLF(t *testing.T) { f := filepath.Join(t.TempDir(), "script") // must be executable - if err := ioutil.WriteFile(f, []byte("#!/bin/sh\r\necho NO\r\n"), 0555); err != nil { + if err := os.WriteFile(f, []byte("#!/bin/sh\r\necho NO\r\n"), 0555); err != nil { t.Fatal(err) } diff --git a/pkg/gcpbuildpack/gcpbuildpack_test.go b/pkg/gcpbuildpack/gcpbuildpack_test.go index 1e5a96961..0d4a11495 100644 --- a/pkg/gcpbuildpack/gcpbuildpack_test.go +++ b/pkg/gcpbuildpack/gcpbuildpack_test.go @@ -16,7 +16,6 @@ package gcpbuildpack import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "reflect" @@ -223,7 +222,7 @@ func TestBuildEmitsSpan(t *testing.T) { } func TestBuildEmitsSuccessOutput(t *testing.T) { - tempDir, err := ioutil.TempDir("", "build-emits-success-output-") + tempDir, err := os.MkdirTemp("", "build-emits-success-output-") if err != nil { t.Fatalf("Creating temp dir: %v", err) } @@ -242,7 +241,7 @@ func TestBuildEmitsSuccessOutput(t *testing.T) { fname := filepath.Join(tempDir, builderOutputFilename) var got builderoutput.BuilderOutput - content, err := ioutil.ReadFile(fname) + content, err := os.ReadFile(fname) if err != nil { t.Fatalf("Failed to read %s: %v", fname, err) } @@ -496,7 +495,7 @@ func TestHasAtLeastOne(t *testing.T) { if err := os.MkdirAll(tc.prefix, 0777); err != nil { t.Fatalf("Error creating %s: %v", tc.prefix, err) } - _, err := ioutil.TempFile(tc.prefix, f) + _, err := os.CreateTemp(tc.prefix, f) if err != nil { t.Fatalf("Creating temp file %s/%s: %v", tc.prefix, f, err) } @@ -594,7 +593,7 @@ func TestHasAtLeastOneFiltered(t *testing.T) { if err := os.MkdirAll(prefixDir, 0777); err != nil { t.Fatalf("Error creating %s: %v", prefixDir, err) } - _, err := ioutil.TempFile(prefixDir, f) + _, err := os.CreateTemp(prefixDir, f) if err != nil { t.Fatalf("Creating temp file %s/%s: %v", prefixDir, f, err) } @@ -644,7 +643,7 @@ func TestHasAtLeastOneOutsideDependencyDirectories(t *testing.T) { if err := os.MkdirAll(prefixDir, 0777); err != nil { t.Fatalf("Error creating %s: %v", prefixDir, err) } - _, err := ioutil.TempFile(prefixDir, f) + _, err := os.CreateTemp(prefixDir, f) if err != nil { t.Fatalf("Creating temp file %s/%s: %v", prefixDir, f, err) } diff --git a/pkg/gcpbuildpack/ioutil.go b/pkg/gcpbuildpack/ioutil.go index 87ad7d8e7..431a96043 100644 --- a/pkg/gcpbuildpack/ioutil.go +++ b/pkg/gcpbuildpack/ioutil.go @@ -16,7 +16,7 @@ package gcpbuildpack import ( "fmt" - "io/ioutil" + "io/fs" "os" "path/filepath" @@ -36,29 +36,38 @@ func (ctx *Context) TempDir(name string) (string, error) { return directory, nil } -// WriteFile is a pass through for ioutil.WriteFile(...) and returns any error with proper user / system attribution +// WriteFile is a pass through for os.WriteFile(...) and returns any error with proper user / system attribution func (ctx *Context) WriteFile(filename string, data []byte, perm os.FileMode) error { - if err := ioutil.WriteFile(filename, data, perm); err != nil { + if err := os.WriteFile(filename, data, perm); err != nil { return buildererror.Errorf(buildererror.StatusInternal, "writing file %q: %v", filename, err) } return nil } -// ReadFile is a pass through for ioutil.ReadFile(...) and returns any error with proper user / system attribution +// ReadFile is a pass through for os.ReadFile(...) and returns any error with proper user / system attribution func (ctx *Context) ReadFile(filename string) ([]byte, error) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { return nil, buildererror.Errorf(buildererror.StatusInternal, "reading file %q: %v", filename, err) } return data, nil } -// ReadDir is a pass through for ioutil.ReadDir(...) and returns any error with proper user / system attribution +// ReadDir is a pass through for os.ReadDir(...) and returns any error with proper user / system attribution func (ctx *Context) ReadDir(elem ...string) ([]os.FileInfo, error) { n := filepath.Join(elem...) - files, err := ioutil.ReadDir(n) + entries, err := os.ReadDir(n) if err != nil { return nil, buildererror.Errorf(buildererror.StatusInternal, "reading directory %q: %v", n, err) } - return files, nil + infos := make([]fs.FileInfo, 0, len(entries)) + for _, entry := range entries { + info, err := entry.Info() + if err != nil { + return nil, buildererror.Errorf(buildererror.StatusInternal, "reading directory %q: %v", n, err) + } + infos = append(infos, info) + } + + return infos, nil } diff --git a/pkg/golang/golang_test.go b/pkg/golang/golang_test.go index fe132c4c6..b667dc93d 100644 --- a/pkg/golang/golang_test.go +++ b/pkg/golang/golang_test.go @@ -16,7 +16,6 @@ package golang import ( "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -295,7 +294,7 @@ module dir for tci, tc := range testCases { t.Run(fmt.Sprintf("go.mod testcase %d", tci), func(t *testing.T) { - dir, err := ioutil.TempDir("", tc.name) + dir, err := os.MkdirTemp("", tc.name) if err != nil { t.Fatalf("failing to create temp dir: %v", err) } @@ -303,7 +302,7 @@ module dir ctx := gcp.NewContext(gcp.WithApplicationRoot(dir)) - if err := ioutil.WriteFile(filepath.Join(dir, "go.mod"), []byte(tc.gomod), 0644); err != nil { + if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte(tc.gomod), 0644); err != nil { t.Fatalf("writing go.mod: %v", err) } diff --git a/pkg/java/java.go b/pkg/java/java.go index 9a2782104..4c2736ec3 100644 --- a/pkg/java/java.go +++ b/pkg/java/java.go @@ -18,7 +18,7 @@ package java import ( "archive/zip" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "regexp" @@ -124,7 +124,7 @@ func FindManifestValueFromJar(jarPath, key string) (string, error) { if err != nil { return "", fmt.Errorf("opening file %s in jar %s: %v", f.FileInfo().Name(), jarPath, err) } - content, err := ioutil.ReadAll(rc) + content, err := io.ReadAll(rc) if err != nil { return "", err } diff --git a/pkg/java/java_test.go b/pkg/java/java_test.go index dc509baa7..57d897236 100644 --- a/pkg/java/java_test.go +++ b/pkg/java/java_test.go @@ -17,7 +17,6 @@ package java import ( "archive/zip" "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -273,7 +272,7 @@ func setupTestLayer(t *testing.T, ctx *gcp.Context) (string, *libcnb.Layer) { func setupTestManifest(t *testing.T, mfContent []byte) string { t.Helper() mfPath := filepath.Join(t.TempDir(), "TEST.MF") - if err := ioutil.WriteFile(mfPath, mfContent, 0644); err != nil { + if err := os.WriteFile(mfPath, mfContent, 0644); err != nil { t.Fatalf("writing to file %s: %v", mfPath, err) } return mfPath @@ -300,7 +299,7 @@ func setupTestJar(t *testing.T, mfContent []byte) string { } jarPath := filepath.Join(t.TempDir(), "test.jar") - if err := ioutil.WriteFile(jarPath, buff.Bytes(), 0644); err != nil { + if err := os.WriteFile(jarPath, buff.Bytes(), 0644); err != nil { t.Fatalf("writing to file %s: %v", jarPath, err) } return jarPath diff --git a/pkg/nodejs/nodejs.go b/pkg/nodejs/nodejs.go index 99bcf588b..ac08db6fa 100644 --- a/pkg/nodejs/nodejs.go +++ b/pkg/nodejs/nodejs.go @@ -18,7 +18,6 @@ package nodejs import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -83,7 +82,7 @@ type PackageJSON struct { // directory. func ReadPackageJSONIfExists(dir string) (*PackageJSON, error) { f := filepath.Join(dir, "package.json") - rawpjs, err := ioutil.ReadFile(f) + rawpjs, err := os.ReadFile(f) if os.IsNotExist(err) { // Return an empty struct if the file doesn't exist (null object pattern). return nil, nil diff --git a/pkg/nodejs/yarn.go b/pkg/nodejs/yarn.go index b89fff4e0..3936edacb 100644 --- a/pkg/nodejs/yarn.go +++ b/pkg/nodejs/yarn.go @@ -16,7 +16,6 @@ package nodejs import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -55,7 +54,7 @@ func UseFrozenLockfile(ctx *gcp.Context) (bool, error) { // IsYarn2 detects whether the given lockfile was generated with Yarn 2. func IsYarn2(rootDir string) (bool, error) { - data, err := ioutil.ReadFile(filepath.Join(rootDir, YarnLock)) + data, err := os.ReadFile(filepath.Join(rootDir, YarnLock)) if err != nil { return false, gcp.InternalErrorf("reading yarn.lock: %v", err) } diff --git a/pkg/nodejs/yarn_test.go b/pkg/nodejs/yarn_test.go index 2e95d68ab..1317359d8 100644 --- a/pkg/nodejs/yarn_test.go +++ b/pkg/nodejs/yarn_test.go @@ -16,7 +16,6 @@ package nodejs import ( "fmt" - "io/ioutil" "net/http" "os" "path" @@ -137,7 +136,7 @@ __metadata: if tc.content != "" { fp := path.Join(dir, YarnLock) - if err := ioutil.WriteFile(fp, []byte(tc.content), 0644); err != nil { + if err := os.WriteFile(fp, []byte(tc.content), 0644); err != nil { t.Fatalf("writing %s: %v", fp, err) } } diff --git a/pkg/ruby/entrypoint_test.go b/pkg/ruby/entrypoint_test.go index 0ef9c4a1b..6c1e207a1 100644 --- a/pkg/ruby/entrypoint_test.go +++ b/pkg/ruby/entrypoint_test.go @@ -15,7 +15,6 @@ package ruby import ( - "io/ioutil" "os" "path" "path/filepath" @@ -80,7 +79,7 @@ func TestEntrypoint(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tempDir, err := ioutil.TempDir("", "test-entrypoint-") + tempDir, err := os.MkdirTemp("", "test-entrypoint-") if err != nil { t.Fatalf("creating temp dir: %v", err) } @@ -95,7 +94,7 @@ func TestEntrypoint(t *testing.T) { if err := os.MkdirAll(path.Dir(fn), 0755); err != nil { t.Fatalf("creating dir %s: %v", path.Dir(fn), err) } - if err := ioutil.WriteFile(fn, []byte("content"), 0644); err != nil { + if err := os.WriteFile(fn, []byte("content"), 0644); err != nil { t.Fatalf("writing file %s: %v", fn, err) } } diff --git a/pkg/ruby/gemfile_test.go b/pkg/ruby/gemfile_test.go index 6690fcde0..1de27dda7 100644 --- a/pkg/ruby/gemfile_test.go +++ b/pkg/ruby/gemfile_test.go @@ -15,7 +15,7 @@ package ruby import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -79,7 +79,7 @@ RUBY VERSION tempRoot := t.TempDir() path := filepath.Join(tempRoot, tc.lockFile.name) - if err := ioutil.WriteFile(path, []byte(tc.lockFile.content), 0644); err != nil { + if err := os.WriteFile(path, []byte(tc.lockFile.content), 0644); err != nil { t.Fatalf("writing file %s: %v", path, err) } @@ -167,7 +167,7 @@ BUNDLED WITH tempRoot := t.TempDir() path := filepath.Join(tempRoot, tc.lockFile.name) - if err := ioutil.WriteFile(path, []byte(tc.lockFile.content), 0644); err != nil { + if err := os.WriteFile(path, []byte(tc.lockFile.content), 0644); err != nil { t.Fatalf("writing file %s: %v", path, err) } diff --git a/pkg/ruby/ruby_test.go b/pkg/ruby/ruby_test.go index 9d6d0f2e5..76db1c738 100644 --- a/pkg/ruby/ruby_test.go +++ b/pkg/ruby/ruby_test.go @@ -15,7 +15,7 @@ package ruby import ( - "io/ioutil" + "os" "path/filepath" "strings" "testing" @@ -181,7 +181,7 @@ RUBY VERSION if len(tc.lockFiles) > 0 { for _, lockFile := range tc.lockFiles { path := filepath.Join(tempRoot, lockFile.name) - if err := ioutil.WriteFile(path, []byte(lockFile.content), 0644); err != nil { + if err := os.WriteFile(path, []byte(lockFile.content), 0644); err != nil { t.Fatalf("writing file %s: %v", path, err) } } @@ -316,7 +316,7 @@ RUBY VERSION if len(tc.lockFiles) > 0 { for _, lockFile := range tc.lockFiles { path := filepath.Join(tempRoot, lockFile.name) - if err := ioutil.WriteFile(path, []byte(lockFile.content), 0644); err != nil { + if err := os.WriteFile(path, []byte(lockFile.content), 0644); err != nil { t.Fatalf("writing file %s: %v", path, err) } }