1
0
mirror of https://github.com/openshift/source-to-image.git synced 2026-02-05 12:44:54 +01:00

Migrate away from deprecated ioutil

This commit is contained in:
Brandon Palm
2025-11-24 12:28:04 -06:00
parent 133a13bbab
commit 16f8838309
22 changed files with 114 additions and 120 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -446,7 +445,7 @@ func getImageScriptsDir(config *api.Config, builder *Dockerfile) (string, map[st
// scanScripts returns a map of provided s2i scripts // scanScripts returns a map of provided s2i scripts
func scanScripts(name string) map[string]bool { func scanScripts(name string) map[string]bool {
scriptsMap := make(map[string]bool) scriptsMap := make(map[string]bool)
items, err := ioutil.ReadDir(name) items, err := os.ReadDir(name)
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Warningf("Unable to access directory %q: %v", name, err) log.Warningf("Unable to access directory %q: %v", name, err)
} }

View File

@@ -2,7 +2,6 @@ package dockerfile
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@@ -161,7 +160,7 @@ func TestInstallScripts(t *testing.T) {
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
workDir, err := ioutil.TempDir("", "s2i-dockerfile-uploads") workDir, err := os.MkdirTemp("", "s2i-dockerfile-uploads")
if err != nil { if err != nil {
t.Fatalf("failed to create working dir: %v", err) t.Fatalf("failed to create working dir: %v", err)
} }
@@ -177,7 +176,7 @@ func TestInstallScripts(t *testing.T) {
} }
} }
tempDir, err := ioutil.TempDir("", "s2i-dockerfile-scripts") tempDir, err := os.MkdirTemp("", "s2i-dockerfile-scripts")
if err != nil { if err != nil {
t.Fatalf("could not create temp dir: %v", err) t.Fatalf("could not create temp dir: %v", err)
} }
@@ -221,6 +220,6 @@ func TestInstallScripts(t *testing.T) {
func createTestScript(dir string, name string) error { func createTestScript(dir string, name string) error {
script := "echo \"test script\"" script := "echo \"test script\""
path := filepath.Join(dir, name) path := filepath.Join(dir, name)
err := ioutil.WriteFile(path, []byte(script), 0700) err := os.WriteFile(path, []byte(script), 0700)
return err return err
} }

View File

@@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -73,7 +72,7 @@ func getDestination(config *api.Config) string {
// checkValidDirWithContents returns true if the parameter provided is a valid, // checkValidDirWithContents returns true if the parameter provided is a valid,
// accessible and non-empty directory. // accessible and non-empty directory.
func checkValidDirWithContents(name string) bool { func checkValidDirWithContents(name string) bool {
items, err := ioutil.ReadDir(name) items, err := os.ReadDir(name)
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Warningf("Unable to access directory %q: %v", name, err) log.Warningf("Unable to access directory %q: %v", name, err)
} }

View File

@@ -2,7 +2,6 @@ package layered
import ( import (
"errors" "errors"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -45,7 +44,7 @@ func newFakeLayeredWithScripts(workDir string) *Layered {
} }
func TestBuildOK(t *testing.T) { func TestBuildOK(t *testing.T) {
workDir, _ := ioutil.TempDir("", "sti") workDir, _ := os.MkdirTemp("", "sti")
scriptDir := filepath.Join(workDir, constants.UploadScripts) scriptDir := filepath.Join(workDir, constants.UploadScripts)
err := os.MkdirAll(scriptDir, 0700) err := os.MkdirAll(scriptDir, 0700)
assemble := filepath.Join(scriptDir, constants.Assemble) assemble := filepath.Join(scriptDir, constants.Assemble)
@@ -78,7 +77,7 @@ func TestBuildOK(t *testing.T) {
} }
func TestBuildOKWithImageRef(t *testing.T) { func TestBuildOKWithImageRef(t *testing.T) {
workDir, _ := ioutil.TempDir("", "sti") workDir, _ := os.MkdirTemp("", "sti")
scriptDir := filepath.Join(workDir, constants.UploadScripts) scriptDir := filepath.Join(workDir, constants.UploadScripts)
err := os.MkdirAll(scriptDir, 0700) err := os.MkdirAll(scriptDir, 0700)
assemble := filepath.Join(scriptDir, constants.Assemble) assemble := filepath.Join(scriptDir, constants.Assemble)

View File

@@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -242,7 +241,7 @@ type startRuntimeImageAndUploadFilesStep struct {
func (step *startRuntimeImageAndUploadFilesStep) execute(ctx *postExecutorStepContext) error { func (step *startRuntimeImageAndUploadFilesStep) execute(ctx *postExecutorStepContext) error {
log.V(3).Info("Executing step: start runtime image and upload files") log.V(3).Info("Executing step: start runtime image and upload files")
fd, err := ioutil.TempFile("", "s2i-upload-done") fd, err := os.CreateTemp("", "s2i-upload-done")
if err != nil { if err != nil {
step.builder.result.BuildInfo.FailureReason = utilstatus.NewFailureReason( step.builder.result.BuildInfo.FailureReason = utilstatus.NewFailureReason(
utilstatus.ReasonGenericS2IBuildFailed, utilstatus.ReasonGenericS2IBuildFailed,
@@ -464,7 +463,7 @@ func createCommandForExecutingRunScript(scriptsURL map[string]string, location s
func downloadAndExtractFileFromContainer(docker dockerpkg.Docker, tar s2itar.Tar, sourcePath, destinationPath, containerID string) (api.FailureReason, error) { func downloadAndExtractFileFromContainer(docker dockerpkg.Docker, tar s2itar.Tar, sourcePath, destinationPath, containerID string) (api.FailureReason, error) {
log.V(5).Infof("Downloading file %q", sourcePath) log.V(5).Infof("Downloading file %q", sourcePath)
fd, err := ioutil.TempFile(destinationPath, "s2i-runtime-artifact") fd, err := os.CreateTemp(destinationPath, "s2i-runtime-artifact")
if err != nil { if err != nil {
res := utilstatus.NewFailureReason( res := utilstatus.NewFailureReason(
utilstatus.ReasonFSOperationFailed, utilstatus.ReasonFSOperationFailed,
@@ -549,7 +548,7 @@ func checkAndGetNewLabels(builder *STI, docker dockerpkg.Docker, tar s2itar.Tar,
defer fd.Close() defer fd.Close()
// read the file to a string // read the file to a string
str, err := ioutil.ReadAll(fd) str, err := io.ReadAll(fd)
if err != nil { if err != nil {
return fmt.Errorf("error reading file '%s' in to a string: %v", filePath, err) return fmt.Errorf("error reading file '%s' in to a string: %v", filePath, err)
} }

View File

@@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -525,7 +524,7 @@ func (builder *STI) Save(config *api.Config) (err error) {
extractFunc := func(string) error { extractFunc := func(string) error {
startTime := time.Now() startTime := time.Now()
extractErr := builder.tar.ExtractTarStream(artifactTmpDir, outReader) extractErr := builder.tar.ExtractTarStream(artifactTmpDir, outReader)
io.Copy(ioutil.Discard, outReader) // must ensure reader from container is drained io.Copy(io.Discard, outReader) // must ensure reader from container is drained
builder.result.BuildInfo.Stages = api.RecordStageAndStepInfo(builder.result.BuildInfo.Stages, api.StageRetrieve, api.StepRetrievePreviousArtifacts, startTime, time.Now()) builder.result.BuildInfo.Stages = api.RecordStageAndStepInfo(builder.result.BuildInfo.Stages, api.StageRetrieve, api.StepRetrievePreviousArtifacts, startTime, time.Now())
if extractErr != nil { if extractErr != nil {

View File

@@ -3,7 +3,7 @@ package config
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "os"
"regexp" "regexp"
"strings" "strings"
@@ -51,7 +51,7 @@ func Save(config *api.Config, cmd *cobra.Command) {
log.V(1).Infof("Unable to serialize to %s: %v", DefaultConfigPath, err) log.V(1).Infof("Unable to serialize to %s: %v", DefaultConfigPath, err)
return return
} }
if err := ioutil.WriteFile(DefaultConfigPath, data, 0644); err != nil { if err := os.WriteFile(DefaultConfigPath, data, 0644); err != nil {
log.V(1).Infof("Unable to save %s: %v", DefaultConfigPath, err) log.V(1).Infof("Unable to save %s: %v", DefaultConfigPath, err)
} }
return return
@@ -59,9 +59,9 @@ func Save(config *api.Config, cmd *cobra.Command) {
// Restore loads the arguments from disk and prefills the Request // Restore loads the arguments from disk and prefills the Request
func Restore(config *api.Config, cmd *cobra.Command) { func Restore(config *api.Config, cmd *cobra.Command) {
data, err := ioutil.ReadFile(DefaultConfigPath) data, err := os.ReadFile(DefaultConfigPath)
if err != nil { if err != nil {
data, err = ioutil.ReadFile(".stifile") data, err = os.ReadFile(".stifile")
if err != nil { if err != nil {
log.V(1).Infof("Unable to restore %s: %v", DefaultConfigPath, err) log.V(1).Infof("Unable to restore %s: %v", DefaultConfigPath, err)
return return

View File

@@ -3,8 +3,7 @@ package docker
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/docker/docker/api/types/image" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@@ -13,6 +12,7 @@ import (
dockertypes "github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container" dockercontainer "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/registry"
dockerstrslice "github.com/docker/docker/api/types/strslice" dockerstrslice "github.com/docker/docker/api/types/strslice"
dockerspec "github.com/moby/docker-image-spec/specs-go/v1" dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
@@ -131,7 +131,7 @@ func TestCopyToContainer(t *testing.T) {
var err error var err error
var file *os.File var file *os.File
if len(tst.src) > 0 { if len(tst.src) > 0 {
tempDir, err = ioutil.TempDir("", tst.src) tempDir, err = os.MkdirTemp("", tst.src)
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
fileName = filepath.Join(tempDir, "bar") fileName = filepath.Join(tempDir, "bar")
if err = os.MkdirAll(filepath.Dir(fileName), 0700); err == nil { if err = os.MkdirAll(filepath.Dir(fileName), 0700); err == nil {
@@ -557,7 +557,7 @@ func TestRunContainer(t *testing.T) {
Destination: tst.paramDestination, Destination: tst.paramDestination,
Command: tst.cmd, Command: tst.cmd,
Env: []string{"Key1=Value1", "Key2=Value2"}, Env: []string{"Key1=Value1", "Key2=Value2"},
Stdin: ioutil.NopCloser(os.Stdin), Stdin: io.NopCloser(os.Stdin),
}) })
if tst.errResult > 0 { if tst.errResult > 0 {

View File

@@ -3,7 +3,6 @@ package docker
import ( import (
"errors" "errors"
"io" "io"
"io/ioutil"
dockertypes "github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types"
@@ -130,7 +129,7 @@ func (f *FakeDocker) RunContainer(opts RunContainerOptions) error {
} }
} }
if opts.Stdin != nil { if opts.Stdin != nil {
_, err := io.Copy(ioutil.Discard, opts.Stdin) _, err := io.Copy(io.Discard, opts.Stdin)
if err != nil { if err != nil {
return err return err
} }
@@ -210,7 +209,7 @@ func (f *FakeDocker) CheckAndPullImage(name string) (*api.Image, error) {
func (f *FakeDocker) BuildImage(opts BuildImageOptions) error { func (f *FakeDocker) BuildImage(opts BuildImageOptions) error {
f.BuildImageOpts = opts f.BuildImageOpts = opts
if opts.Stdin != nil { if opts.Stdin != nil {
_, err := io.Copy(ioutil.Discard, opts.Stdin) _, err := io.Copy(io.Discard, opts.Stdin)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"time" "time"
@@ -127,7 +126,7 @@ func (d *FakeDockerClient) CopyToContainer(ctx context.Context, container, path
func (d *FakeDockerClient) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, dockercontainer.PathStat, error) { func (d *FakeDockerClient) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, dockercontainer.PathStat, error) {
d.CopyFromContainerID = container d.CopyFromContainerID = container
d.CopyFromContainerPath = srcPath d.CopyFromContainerPath = srcPath
return ioutil.NopCloser(bytes.NewReader([]byte(""))), dockercontainer.PathStat{}, d.CopyFromContainerErr return io.NopCloser(bytes.NewReader([]byte(""))), dockercontainer.PathStat{}, d.CopyFromContainerErr
} }
// ContainerWait pauses execution until a container exits. // ContainerWait pauses execution until a container exits.
@@ -165,7 +164,7 @@ func (d *FakeDockerClient) ContainerAttach(ctx context.Context, container string
func (d *FakeDockerClient) ImageBuild(ctx context.Context, buildContext io.Reader, options dockertypes.ImageBuildOptions) (dockertypes.ImageBuildResponse, error) { func (d *FakeDockerClient) ImageBuild(ctx context.Context, buildContext io.Reader, options dockertypes.ImageBuildOptions) (dockertypes.ImageBuildResponse, error) {
d.BuildImageOpts = options d.BuildImageOpts = options
return dockertypes.ImageBuildResponse{ return dockertypes.ImageBuildResponse{
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), Body: io.NopCloser(bytes.NewReader([]byte(""))),
}, d.BuildImageErr }, d.BuildImageErr
} }
@@ -213,7 +212,7 @@ func (d *FakeDockerClient) ImagePull(ctx context.Context, ref string, options im
return nil, d.PullFail return nil, d.PullFail
} }
return ioutil.NopCloser(bytes.NewReader([]byte{})), nil return io.NopCloser(bytes.NewReader([]byte{})), nil
} }
// ImageRemove removes an image from the docker host. // ImageRemove removes an image from the docker host.

View File

@@ -1,7 +1,6 @@
package git package git
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@@ -41,7 +40,7 @@ func CreateLocalGitDirectory() (string, error) {
func CreateEmptyLocalGitDirectory() (string, error) { func CreateEmptyLocalGitDirectory() (string, error) {
cr := cmd.NewCommandRunner() cr := cmd.NewCommandRunner()
dir, err := ioutil.TempDir(os.TempDir(), "gitdir-s2i-test") dir, err := os.MkdirTemp(os.TempDir(), "gitdir-s2i-test")
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@@ -3,7 +3,6 @@ package scripts
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@@ -23,7 +22,7 @@ type FakeHTTPGet struct {
func (f *FakeHTTPGet) get(url string) (*http.Response, error) { func (f *FakeHTTPGet) get(url string) (*http.Response, error) {
f.url = url f.url = url
f.body = ioutil.NopCloser(strings.NewReader(f.content)) f.body = io.NopCloser(strings.NewReader(f.content))
return &http.Response{ return &http.Response{
Body: f.body, Body: f.body,
StatusCode: f.statusCode, StatusCode: f.statusCode,
@@ -81,7 +80,7 @@ type FakeSchemeReader struct {
} }
func (f *FakeSchemeReader) Read(url *url.URL) (io.ReadCloser, error) { func (f *FakeSchemeReader) Read(url *url.URL) (io.ReadCloser, error) {
return ioutil.NopCloser(strings.NewReader(f.content)), f.err return io.NopCloser(strings.NewReader(f.content)), f.err
} }
func getDownloader() (Downloader, *FakeSchemeReader) { func getDownloader() (Downloader, *FakeSchemeReader) {
@@ -98,7 +97,7 @@ func getDownloader() (Downloader, *FakeSchemeReader) {
func TestDownload(t *testing.T) { func TestDownload(t *testing.T) {
dl, fr := getDownloader() dl, fr := getDownloader()
fr.content = "test file content" fr.content = "test file content"
temp, err := ioutil.TempFile("", "testdownload") temp, err := os.CreateTemp("", "testdownload")
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory for test: %v", err) t.Fatalf("Cannot create temp directory for test: %v", err)
} }
@@ -112,7 +111,7 @@ func TestDownload(t *testing.T) {
if len(info.Location) == 0 { if len(info.Location) == 0 {
t.Errorf("Expected info.Location to be set, got %v", info) t.Errorf("Expected info.Location to be set, got %v", info)
} }
content, _ := ioutil.ReadFile(temp.Name()) content, _ := os.ReadFile(temp.Name())
if string(content) != fr.content { if string(content) != fr.content {
t.Errorf("Unexpected file content: %s", string(content)) t.Errorf("Unexpected file content: %s", string(content))
} }

View File

@@ -4,7 +4,6 @@ import (
"archive/tar" "archive/tar"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -197,7 +196,7 @@ func (t *stiTar) SetExclusionPattern(p *regexp.Regexp) {
// while excluding files that match the given exclusion pattern // while excluding files that match the given exclusion pattern
// It returns the name of the created file // It returns the name of the created file
func (t *stiTar) CreateTarFile(base, dir string) (string, error) { func (t *stiTar) CreateTarFile(base, dir string) (string, error) {
tarFile, err := ioutil.TempFile(base, "tar") tarFile, err := os.CreateTemp(base, "tar")
defer tarFile.Close() defer tarFile.Close()
if err != nil { if err != nil {
return "", err return "", err

View File

@@ -4,7 +4,6 @@ import (
"archive/tar" "archive/tar"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -47,7 +46,7 @@ func createTestFiles(baseDir string, dirs []dirDesc, files []fileDesc, links []l
} }
for _, fd := range files { for _, fd := range files {
fileName := filepath.Join(baseDir, fd.name) fileName := filepath.Join(baseDir, fd.name)
err := ioutil.WriteFile(fileName, []byte(fd.content), fd.mode) err := os.WriteFile(fileName, []byte(fd.content), fd.mode)
if err != nil { if err != nil {
return err return err
} }
@@ -140,7 +139,7 @@ func verifyTarFile(t *testing.T, filename string, dirs []dirDesc, files []fileDe
t.Errorf("File %q from tar %q does not match expected modified date. Expected: %v, actual: %v", t.Errorf("File %q from tar %q does not match expected modified date. Expected: %v, actual: %v",
hdr.Name, filename, fd.modifiedDate, finfo.ModTime().UTC()) hdr.Name, filename, fd.modifiedDate, finfo.ModTime().UTC())
} }
fileBytes, err := ioutil.ReadAll(tr) fileBytes, err := io.ReadAll(tr)
if err != nil { if err != nil {
t.Fatalf("Error reading tar %q: %v", filename, err) t.Fatalf("Error reading tar %q: %v", filename, err)
} }
@@ -168,7 +167,7 @@ func verifyTarFile(t *testing.T, filename string, dirs []dirDesc, files []fileDe
} }
func TestCreateTarStreamIncludeParentDir(t *testing.T) { func TestCreateTarStreamIncludeParentDir(t *testing.T) {
tempDir, err := ioutil.TempDir("", "testtar") tempDir, err := os.MkdirTemp("", "testtar")
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory for test: %v", err) t.Fatalf("Cannot create temp directory for test: %v", err)
@@ -190,7 +189,7 @@ func TestCreateTarStreamIncludeParentDir(t *testing.T) {
t.Fatalf("Cannot create test files: %v", err) t.Fatalf("Cannot create test files: %v", err)
} }
th := New(fs.NewFileSystem()) th := New(fs.NewFileSystem())
tarFile, err := ioutil.TempFile("", "testtarout") tarFile, err := os.CreateTemp("", "testtarout")
if err != nil { if err != nil {
t.Fatalf("Unable to create temporary file %v", err) t.Fatalf("Unable to create temporary file %v", err)
} }
@@ -211,7 +210,7 @@ func TestCreateTarStreamIncludeParentDir(t *testing.T) {
func TestCreateTar(t *testing.T) { func TestCreateTar(t *testing.T) {
th := New(fs.NewFileSystem()) th := New(fs.NewFileSystem())
tempDir, err := ioutil.TempDir("", "testtar") tempDir, err := os.MkdirTemp("", "testtar")
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory for test: %v", err) t.Fatalf("Cannot create temp directory for test: %v", err)
@@ -252,7 +251,7 @@ func TestCreateTar(t *testing.T) {
func TestCreateTarIncludeDotGit(t *testing.T) { func TestCreateTarIncludeDotGit(t *testing.T) {
th := New(fs.NewFileSystem()) th := New(fs.NewFileSystem())
th.SetExclusionPattern(regexp.MustCompile("test3.txt")) th.SetExclusionPattern(regexp.MustCompile("test3.txt"))
tempDir, err := ioutil.TempDir("", "testtar") tempDir, err := os.MkdirTemp("", "testtar")
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory for test: %v", err) t.Fatalf("Cannot create temp directory for test: %v", err)
@@ -292,7 +291,7 @@ func TestCreateTarIncludeDotGit(t *testing.T) {
func TestCreateTarEmptyRegexp(t *testing.T) { func TestCreateTarEmptyRegexp(t *testing.T) {
th := New(fs.NewFileSystem()) th := New(fs.NewFileSystem())
th.SetExclusionPattern(regexp.MustCompile("")) th.SetExclusionPattern(regexp.MustCompile(""))
tempDir, err := ioutil.TempDir("", "testtar") tempDir, err := os.MkdirTemp("", "testtar")
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory for test: %v", err) t.Fatalf("Cannot create temp directory for test: %v", err)
@@ -501,7 +500,7 @@ func verifyDirectory(t *testing.T, dir string, dirs []dirDesc, files []fileDesc,
relpath, fd.modifiedDate, info.ModTime()) relpath, fd.modifiedDate, info.ModTime())
} }
if !info.IsDir() { if !info.IsDir() {
contentBytes, err := ioutil.ReadFile(path) contentBytes, err := os.ReadFile(path)
if err != nil { if err != nil {
t.Errorf("Error reading file %q: %v", path, err) t.Errorf("Error reading file %q: %v", path, err)
return err return err
@@ -565,7 +564,7 @@ func TestExtractTarStream(t *testing.T) {
{"dir01/dir03/tëst3.txt", modificationDate, 0444, "utf-8 header file content", false, ""}, {"dir01/dir03/tëst3.txt", modificationDate, 0444, "utf-8 header file content", false, ""},
} }
reader, writer := io.Pipe() reader, writer := io.Pipe()
destDir, err := ioutil.TempDir("", "testExtract") destDir, err := os.MkdirTemp("", "testExtract")
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory: %v", err) t.Fatalf("Cannot create temp directory: %v", err)
} }
@@ -585,7 +584,7 @@ func TestExtractTarStream(t *testing.T) {
func TestExtractTarStreamTimeout(t *testing.T) { func TestExtractTarStreamTimeout(t *testing.T) {
reader, writer := io.Pipe() reader, writer := io.Pipe()
destDir, err := ioutil.TempDir("", "testExtract") destDir, err := os.MkdirTemp("", "testExtract")
if err != nil { if err != nil {
t.Fatalf("Cannot create temp directory: %v", err) t.Fatalf("Cannot create temp directory: %v", err)
} }
@@ -602,12 +601,12 @@ func TestExtractTarStreamTimeout(t *testing.T) {
func TestRoundTripTar(t *testing.T) { func TestRoundTripTar(t *testing.T) {
tarWriter := New(fs.NewFileSystem()) tarWriter := New(fs.NewFileSystem())
tarReader := New(fs.NewFileSystem()) tarReader := New(fs.NewFileSystem())
tempDir, err := ioutil.TempDir("", "testtar") tempDir, err := os.MkdirTemp("", "testtar")
defer os.RemoveAll(tempDir) defer os.RemoveAll(tempDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp input directory for test: %v", err) t.Fatalf("Cannot create temp input directory for test: %v", err)
} }
destDir, err := ioutil.TempDir("", "testExtract") destDir, err := os.MkdirTemp("", "testExtract")
defer os.RemoveAll(destDir) defer os.RemoveAll(destDir)
if err != nil { if err != nil {
t.Fatalf("Cannot create temp extract directory for test: %v", err) t.Fatalf("Cannot create temp extract directory for test: %v", err)

View File

@@ -3,7 +3,6 @@ package cmd
import ( import (
"bytes" "bytes"
"io" "io"
"io/ioutil"
"github.com/openshift/source-to-image/pkg/util/cmd" "github.com/openshift/source-to-image/pkg/util/cmd"
) )
@@ -32,7 +31,7 @@ func (f *FakeCmdRunner) Run(name string, args ...string) error {
// StartWithStdoutPipe executes a command returning a ReadCloser connected to // StartWithStdoutPipe executes a command returning a ReadCloser connected to
// the command's stdout. // the command's stdout.
func (f *FakeCmdRunner) StartWithStdoutPipe(opts cmd.CommandOpts, name string, arg ...string) (io.ReadCloser, error) { func (f *FakeCmdRunner) StartWithStdoutPipe(opts cmd.CommandOpts, name string, arg ...string) (io.ReadCloser, error) {
return ioutil.NopCloser(&bytes.Buffer{}), f.Err return io.NopCloser(&bytes.Buffer{}), f.Err
} }
// Wait waits for the command to exit. // Wait waits for the command to exit.

View File

@@ -3,7 +3,6 @@ package util
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"testing" "testing"
) )
@@ -17,7 +16,7 @@ type FakePost struct {
func (f *FakePost) post(url, contentType string, body io.Reader) (resp *http.Response, err error) { func (f *FakePost) post(url, contentType string, body io.Reader) (resp *http.Response, err error) {
f.url = url f.url = url
f.body, _ = ioutil.ReadAll(body) f.body, _ = io.ReadAll(body)
return &f.response, f.err return &f.response, f.err
} }

View File

@@ -3,7 +3,6 @@ package fs
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@@ -133,11 +132,23 @@ func (h *fs) Lstat(path string) (os.FileInfo, error) {
// ReadDir reads the directory named by dirname and returns a list of directory // ReadDir reads the directory named by dirname and returns a list of directory
// entries sorted by filename. // entries sorted by filename.
func (h *fs) ReadDir(path string) ([]os.FileInfo, error) { func (h *fs) ReadDir(path string) ([]os.FileInfo, error) {
fis, err := ioutil.ReadDir(path) entries, err := os.ReadDir(path)
if runtime.GOOS == "windows" && err == nil { if err != nil {
return nil, err
}
// Convert []os.DirEntry to []os.FileInfo
fis := make([]os.FileInfo, len(entries))
for i, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, err
}
fis[i] = info
}
if runtime.GOOS == "windows" {
h.enrichFileInfos(path, fis) h.enrichFileInfos(path, fis)
} }
return fis, err return fis, nil
} }
// Chmod sets the file mode // Chmod sets the file mode
@@ -328,7 +339,7 @@ func (h *fs) RemoveDirectory(dir string) error {
// CreateWorkingDirectory creates a directory to be used for STI // CreateWorkingDirectory creates a directory to be used for STI
func (h *fs) CreateWorkingDirectory() (directory string, err error) { func (h *fs) CreateWorkingDirectory() (directory string, err error) {
directory, err = ioutil.TempDir("", "s2i") directory, err = os.MkdirTemp("", "s2i")
if err != nil { if err != nil {
return "", s2ierr.NewWorkDirError(directory, err) return "", s2ierr.NewWorkDirError(directory, err)
} }
@@ -349,7 +360,7 @@ func (h *fs) Create(filename string) (io.WriteCloser, error) {
// WriteFile opens a file and writes data to it, returning error if such // WriteFile opens a file and writes data to it, returning error if such
// occurred // occurred
func (h *fs) WriteFile(filename string, data []byte) error { func (h *fs) WriteFile(filename string, data []byte) error {
return ioutil.WriteFile(filename, data, 0700) return os.WriteFile(filename, data, 0700)
} }
// Walk walks the file tree rooted at root, calling walkFn for each file or // Walk walks the file tree rooted at root, calling walkFn for each file or

View File

@@ -2,7 +2,6 @@ package util
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -115,7 +114,7 @@ func CreateTruncateFilesScript(files []string, scriptName string) (string, error
rmScript += fmt.Sprintf("truncate -s0 %q\n", s) rmScript += fmt.Sprintf("truncate -s0 %q\n", s)
} }
f, err := ioutil.TempFile("", "s2i-injection-remove") f, err := os.CreateTemp("", "s2i-injection-remove")
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -123,7 +122,7 @@ func CreateTruncateFilesScript(files []string, scriptName string) (string, error
rmScript += fmt.Sprintf("truncate -s0 %q\n", scriptName) rmScript += fmt.Sprintf("truncate -s0 %q\n", scriptName)
} }
rmScript += "set +e\n" rmScript += "set +e\n"
err = ioutil.WriteFile(f.Name(), []byte(rmScript), 0700) err = os.WriteFile(f.Name(), []byte(rmScript), 0700)
return f.Name(), err return f.Name(), err
} }
@@ -131,12 +130,12 @@ func CreateTruncateFilesScript(files []string, scriptName string) (string, error
// error. The path to the result file is returned. If the provided error is nil, an empty file is // error. The path to the result file is returned. If the provided error is nil, an empty file is
// created. // created.
func CreateInjectionResultFile(injectErr error) (string, error) { func CreateInjectionResultFile(injectErr error) (string, error) {
f, err := ioutil.TempFile("", "s2i-injection-result") f, err := os.CreateTemp("", "s2i-injection-result")
if err != nil { if err != nil {
return "", err return "", err
} }
if injectErr != nil { if injectErr != nil {
err = ioutil.WriteFile(f.Name(), []byte(injectErr.Error()), 0700) err = os.WriteFile(f.Name(), []byte(injectErr.Error()), 0700)
} }
return f.Name(), err return f.Name(), err
} }

View File

@@ -3,7 +3,6 @@ package util
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -27,7 +26,7 @@ func TestCreateTruncateFilesScript(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Expected file %q to exists, got: %v", name, err) t.Errorf("Expected file %q to exists, got: %v", name, err)
} }
data, err := ioutil.ReadFile(name) data, err := os.ReadFile(name)
if err != nil { if err != nil {
t.Errorf("Unable to read %q: %v", name, err) t.Errorf("Unable to read %q: %v", name, err)
} }
@@ -43,9 +42,9 @@ func TestCreateTruncateFilesScript(t *testing.T) {
} }
func TestListFilesToTruncate(t *testing.T) { func TestListFilesToTruncate(t *testing.T) {
tmp, err := ioutil.TempDir("", "s2i-test-") tmp, err := os.MkdirTemp("", "s2i-test-")
tmpKeep, err := ioutil.TempDir("", "s2i-test-") tmpKeep, err := os.MkdirTemp("", "s2i-test-")
tmpNested, err := ioutil.TempDir(tmp, "nested") tmpNested, err := os.MkdirTemp(tmp, "nested")
if err != nil { if err != nil {
t.Errorf("Unable to create temp directory: %v", err) t.Errorf("Unable to create temp directory: %v", err)
} }
@@ -55,9 +54,9 @@ func TestListFilesToTruncate(t *testing.T) {
{Source: tmp, Destination: "/foo"}, {Source: tmp, Destination: "/foo"},
{Source: tmpKeep, Destination: "/this", Keep: true}, {Source: tmpKeep, Destination: "/this", Keep: true},
} }
f1, _ := ioutil.TempFile(tmp, "foo") f1, _ := os.CreateTemp(tmp, "foo")
f2, _ := ioutil.TempFile(tmpNested, "bar") f2, _ := os.CreateTemp(tmpNested, "bar")
ioutil.TempFile(tmpKeep, "that") os.CreateTemp(tmpKeep, "that")
files, err := ListFilesToTruncate(fs.NewFileSystem(), list) files, err := ListFilesToTruncate(fs.NewFileSystem(), list)
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
@@ -101,7 +100,7 @@ func TestCreateInjectionResultFile(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Expected file %q to exists, got: %v", name, err) t.Errorf("Expected file %q to exists, got: %v", name, err)
} }
data, err := ioutil.ReadFile(name) data, err := os.ReadFile(name)
if err != nil { if err != nil {
t.Errorf("Unable to read %q: %v", name, err) t.Errorf("Unable to read %q: %v", name, err)
} }

View File

@@ -6,7 +6,7 @@ package docker
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"io/ioutil" "io"
"log" "log"
"net" "net"
"net/http" "net/http"
@@ -36,7 +36,7 @@ func init() {
panic(err) panic(err)
} }
ca, err := ioutil.ReadFile("../testdata/ca.crt") ca, err := os.ReadFile("../testdata/ca.crt")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -44,7 +44,7 @@ func init() {
caPool = x509.NewCertPool() caPool = x509.NewCertPool()
caPool.AppendCertsFromPEM(ca) caPool.AppendCertsFromPEM(ca)
log.SetOutput(ioutil.Discard) log.SetOutput(io.Discard)
} }
type Server struct { type Server struct {

View File

@@ -8,7 +8,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@@ -111,13 +111,13 @@ func getDefaultContext() (context.Context, context.CancelFunc) {
// TestInjectionBuild tests the build where we inject files to assemble script. // TestInjectionBuild tests the build where we inject files to assemble script.
func TestInjectionBuild(t *testing.T) { func TestInjectionBuild(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-test-dir") tempdir, err := os.MkdirTemp("", "s2i-test-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
defer os.RemoveAll(tempdir) defer os.RemoveAll(tempdir)
err = ioutil.WriteFile(filepath.Join(tempdir, "secret"), []byte("secret"), 0666) err = os.WriteFile(filepath.Join(tempdir, "secret"), []byte("secret"), 0666)
if err != nil { if err != nil {
t.Errorf("Unable to write content to temporary injection file: %v", err) t.Errorf("Unable to write content to temporary injection file: %v", err)
} }
@@ -130,13 +130,13 @@ func TestInjectionBuild(t *testing.T) {
} }
func TestInjectionBuildBadDestination(t *testing.T) { func TestInjectionBuildBadDestination(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-test-dir") tempdir, err := os.MkdirTemp("", "s2i-test-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
defer os.RemoveAll(tempdir) defer os.RemoveAll(tempdir)
err = ioutil.WriteFile(filepath.Join(tempdir, "secret"), []byte("secret"), 0666) err = os.WriteFile(filepath.Join(tempdir, "secret"), []byte("secret"), 0666)
if err != nil { if err != nil {
t.Errorf("Unable to write content to temporary injection file: %v", err) t.Errorf("Unable to write content to temporary injection file: %v", err)
} }
@@ -329,7 +329,7 @@ func (i *integrationTest) exerciseCleanBuild(tag string, verifyCallback bool, im
// the request body is as expected // the request body is as expected
if callbackHasValidJSON { if callbackHasValidJSON {
defer r.Body.Close() defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body) body, _ := io.ReadAll(r.Body)
type CallbackMessage struct { type CallbackMessage struct {
Success bool Success bool
Labels map[string]string Labels map[string]string

View File

@@ -5,7 +5,6 @@ package dockerfile
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -21,7 +20,7 @@ import (
) )
func TestDockerfileBuild(t *testing.T) { func TestDockerfileBuild(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -64,7 +63,7 @@ func TestDockerfileBuild(t *testing.T) {
} }
func TestDockerfileBuildDefaultDockerfile(t *testing.T) { func TestDockerfileBuildDefaultDockerfile(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -106,7 +105,7 @@ func TestDockerfileBuildDefaultDockerfile(t *testing.T) {
} }
func TestDockerfileBuildEnv(t *testing.T) { func TestDockerfileBuildEnv(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -144,7 +143,7 @@ func TestDockerfileBuildEnv(t *testing.T) {
} }
func TestDockerfileBuildLabels(t *testing.T) { func TestDockerfileBuildLabels(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -183,7 +182,7 @@ func TestDockerfileBuildLabels(t *testing.T) {
} }
func TestDockerfileBuildInjections(t *testing.T) { func TestDockerfileBuildInjections(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -196,7 +195,7 @@ func TestDockerfileBuildInjections(t *testing.T) {
} }
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
_, err = ioutil.TempFile(injection1, "injectfile-") _, err = os.CreateTemp(injection1, "injectfile-")
if err != nil { if err != nil {
t.Errorf("Unable to create injection file: %v", err) t.Errorf("Unable to create injection file: %v", err)
} }
@@ -207,7 +206,7 @@ func TestDockerfileBuildInjections(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Unable to create injection dir: %v", err) t.Errorf("Unable to create injection dir: %v", err)
} }
_, err = ioutil.TempFile(injection2, "injectfile-2") _, err = os.CreateTemp(injection2, "injectfile-2")
if err != nil { if err != nil {
t.Errorf("Unable to create injection file: %v", err) t.Errorf("Unable to create injection file: %v", err)
} }
@@ -263,7 +262,7 @@ func TestDockerfileBuildInjections(t *testing.T) {
} }
func TestDockerfileBuildScriptsURLAssemble(t *testing.T) { func TestDockerfileBuildScriptsURLAssemble(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -303,7 +302,7 @@ func TestDockerfileBuildScriptsURLAssemble(t *testing.T) {
} }
func TestDockerfileBuildScriptsURLRun(t *testing.T) { func TestDockerfileBuildScriptsURLRun(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -343,7 +342,7 @@ func TestDockerfileBuildScriptsURLRun(t *testing.T) {
} }
func TestDockerfileBuildScriptsURLNone(t *testing.T) { func TestDockerfileBuildScriptsURLNone(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -367,7 +366,7 @@ func TestDockerfileBuildScriptsURLNone(t *testing.T) {
} }
func TestDockerfileBuildSourceScriptsAssemble(t *testing.T) { func TestDockerfileBuildSourceScriptsAssemble(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -414,7 +413,7 @@ func TestDockerfileBuildSourceScriptsAssemble(t *testing.T) {
} }
func TestDockerfileBuildSourceScriptsRun(t *testing.T) { func TestDockerfileBuildSourceScriptsRun(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -465,7 +464,7 @@ func TestDockerfileBuildSourceScriptsRun(t *testing.T) {
// contains all of the s2i scripts at the given directory, regardless // contains all of the s2i scripts at the given directory, regardless
// of what is contained in the source. // of what is contained in the source.
func TestDockerfileBuildScriptsURLImage(t *testing.T) { func TestDockerfileBuildScriptsURLImage(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -512,7 +511,7 @@ func TestDockerfileBuildScriptsURLImage(t *testing.T) {
} }
func TestDockerfileBuildImageScriptsURLAssemble(t *testing.T) { func TestDockerfileBuildImageScriptsURLAssemble(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -552,7 +551,7 @@ func TestDockerfileBuildImageScriptsURLAssemble(t *testing.T) {
} }
func TestDockerfileBuildImageScriptsURLRun(t *testing.T) { func TestDockerfileBuildImageScriptsURLRun(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -592,7 +591,7 @@ func TestDockerfileBuildImageScriptsURLRun(t *testing.T) {
} }
func TestDockerfileBuildImageScriptsURLImage(t *testing.T) { func TestDockerfileBuildImageScriptsURLImage(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -639,7 +638,7 @@ func TestDockerfileBuildImageScriptsURLImage(t *testing.T) {
} }
func TestDockerfileBuildScriptsAndImageURL(t *testing.T) { func TestDockerfileBuildScriptsAndImageURL(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -683,19 +682,19 @@ func TestDockerfileBuildScriptsAndImageURL(t *testing.T) {
// the ScriptsURL and ImageScriptsURL point to a non-image directory. // the ScriptsURL and ImageScriptsURL point to a non-image directory.
// In this event, the ScriptsURL value should take precedence. // In this event, the ScriptsURL value should take precedence.
func TestDockerfileBuildScriptsAndImageURLConflicts(t *testing.T) { func TestDockerfileBuildScriptsAndImageURLConflicts(t *testing.T) {
scriptsTempDir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") scriptsTempDir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
defer os.RemoveAll(scriptsTempDir) defer os.RemoveAll(scriptsTempDir)
imageTempDir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") imageTempDir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
defer os.RemoveAll(imageTempDir) defer os.RemoveAll(imageTempDir)
outputDir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") outputDir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -703,7 +702,7 @@ func TestDockerfileBuildScriptsAndImageURLConflicts(t *testing.T) {
scriptsAssemble := filepath.Join(scriptsTempDir, "assemble") scriptsAssemble := filepath.Join(scriptsTempDir, "assemble")
assembleData := []byte("#!/bin/bash\necho \"Hello World!\"") assembleData := []byte("#!/bin/bash\necho \"Hello World!\"")
err = ioutil.WriteFile(scriptsAssemble, assembleData, 0666) err = os.WriteFile(scriptsAssemble, assembleData, 0666)
if err != nil { if err != nil {
t.Errorf("Unable to create image assemble file: %v", err) t.Errorf("Unable to create image assemble file: %v", err)
} }
@@ -740,7 +739,7 @@ func TestDockerfileBuildScriptsAndImageURLConflicts(t *testing.T) {
filepath.Join(outputDir, "upload/scripts/assemble"), filepath.Join(outputDir, "upload/scripts/assemble"),
} }
runDockerfileTest(t, config, expected, nil, expectedFiles, false) runDockerfileTest(t, config, expected, nil, expectedFiles, false)
dockerfileAssemble, err := ioutil.ReadFile(filepath.Join(outputDir, "upload/scripts/assemble")) dockerfileAssemble, err := os.ReadFile(filepath.Join(outputDir, "upload/scripts/assemble"))
if err != nil { if err != nil {
t.Errorf("Failed to read uploaded assemble script: %v", err) t.Errorf("Failed to read uploaded assemble script: %v", err)
} }
@@ -750,7 +749,7 @@ func TestDockerfileBuildScriptsAndImageURLConflicts(t *testing.T) {
} }
func TestDockerfileIncrementalBuild(t *testing.T) { func TestDockerfileIncrementalBuild(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -791,7 +790,7 @@ func TestDockerfileIncrementalBuild(t *testing.T) {
} }
func TestDockerfileIncrementalSourceSave(t *testing.T) { func TestDockerfileIncrementalSourceSave(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -846,7 +845,7 @@ func TestDockerfileIncrementalSourceSave(t *testing.T) {
} }
func TestDockerfileIncrementalSaveURL(t *testing.T) { func TestDockerfileIncrementalSaveURL(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -894,7 +893,7 @@ func TestDockerfileIncrementalSaveURL(t *testing.T) {
} }
func TestDockerfileIncrementalTag(t *testing.T) { func TestDockerfileIncrementalTag(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -930,7 +929,7 @@ func TestDockerfileIncrementalTag(t *testing.T) {
} }
func TestDockerfileIncrementalAssembleUser(t *testing.T) { func TestDockerfileIncrementalAssembleUser(t *testing.T) {
tempdir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") tempdir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -966,13 +965,13 @@ func TestDockerfileIncrementalAssembleUser(t *testing.T) {
} }
func TestDockerfileLocalSource(t *testing.T) { func TestDockerfileLocalSource(t *testing.T) {
localTempDir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") localTempDir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
defer os.RemoveAll(localTempDir) defer os.RemoveAll(localTempDir)
outputDir, err := ioutil.TempDir("", "s2i-dockerfiletest-dir") outputDir, err := os.MkdirTemp("", "s2i-dockerfiletest-dir")
if err != nil { if err != nil {
t.Errorf("Unable to create temporary directory: %v", err) t.Errorf("Unable to create temporary directory: %v", err)
} }
@@ -1003,7 +1002,7 @@ func TestDockerfileLocalSource(t *testing.T) {
} }
for _, fileName := range fileTree { for _, fileName := range fileTree {
dummyContent := []byte("Hello World!") dummyContent := []byte("Hello World!")
err = ioutil.WriteFile(filepath.Join(localTempDir, fileName), dummyContent, 0666) err = os.WriteFile(filepath.Join(localTempDir, fileName), dummyContent, 0666)
if err != nil { if err != nil {
t.Errorf("Unable to create file: %v", err) t.Errorf("Unable to create file: %v", err)
} }
@@ -1022,7 +1021,7 @@ func TestDockerfileLocalSource(t *testing.T) {
s2iignore := filepath.Join(localTempDir, ".s2iignore") s2iignore := filepath.Join(localTempDir, ".s2iignore")
s2iignoreDate := []byte("dummy\n#skip_file\nfoo/bar/another_file\nfoo/baz/foobar") s2iignoreDate := []byte("dummy\n#skip_file\nfoo/bar/another_file\nfoo/baz/foobar")
err = ioutil.WriteFile(s2iignore, s2iignoreDate, 0666) err = os.WriteFile(s2iignore, s2iignoreDate, 0666)
if err != nil { if err != nil {
t.Errorf("Unable to create .s2iignore file: %v", err) t.Errorf("Unable to create .s2iignore file: %v", err)
} }
@@ -1056,7 +1055,7 @@ func runDockerfileTest(t *testing.T, config *api.Config, expected []string, notE
t.Fatalf("The build failed when it should have succeeded.") t.Fatalf("The build failed when it should have succeeded.")
} }
filebytes, err := ioutil.ReadFile(config.AsDockerfile) filebytes, err := os.ReadFile(config.AsDockerfile)
if err != nil { if err != nil {
t.Fatalf("An error occurred reading the dockerfile: %v", err) t.Fatalf("An error occurred reading the dockerfile: %v", err)
} }