Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/build/builder/cmd/dockercfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dockercfg

import (
"encoding/json"
"io/ioutil"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -121,7 +120,7 @@ func readSpecificDockerConfigJSONFile(filePath string) error {
var contents []byte
var err error

if contents, err = ioutil.ReadFile(filePath); err != nil {
if contents, err = os.ReadFile(filePath); err != nil {
log.V(4).Infof("error reading file: %v", err)
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/build/builder/cmd/dockercfg/cfg_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dockercfg

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -16,7 +15,7 @@ func TestGetDockerAuth(t *testing.T) {

content := "{ \"auths\": { \"test-server-1.tld\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"test@email.test.com\"}}}"

tmpDirPath, err := ioutil.TempDir("", "test_foo_bar_")
tmpDirPath, err := os.MkdirTemp("", "test_foo_bar_")
if err != nil {
t.Fatalf("Creating tmp dir fail: %v", err)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/builder/cmd/scmauth/cacert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scmauth

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

s2igit "github.com/openshift/source-to-image/pkg/scm/git"
Expand All @@ -27,7 +27,7 @@ func (s CACert) Setup(baseDir string, context SCMAuthContext) (string, error) {
if !(s.SourceURL.Type == s2igit.URLTypeURL && s.SourceURL.URL.Scheme == "https" && s.SourceURL.URL.Opaque == "") {
return "", nil
}
gitconfig, err := ioutil.TempFile("", "ca.crt.")
gitconfig, err := os.CreateTemp("", "ca.crt.")
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/build/builder/cmd/scmauth/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scmauth

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -66,12 +65,12 @@ func (u UsernamePassword) Setup(baseDir string, context SCMAuthContext) (string,

// Write git config if needed
if gitconfigURL != nil {
gitcredentials, err := ioutil.TempFile("", "gitcredentials.")
gitcredentials, err := os.CreateTemp("", "gitcredentials.")
if err != nil {
return "", err
}
defer gitcredentials.Close()
gitconfig, err := ioutil.TempFile("", "gitcredentialscfg.")
gitconfig, err := os.CreateTemp("", "gitcredentialscfg.")
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/build/builder/cmd/scmauth/scmauth_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scmauth

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

func secretDir(t *testing.T, files ...string) string {
dir, err := ioutil.TempDir("", "test")
dir, err := os.MkdirTemp("", "test")
if err != nil {
t.Fatalf("error creating temp dir: %v", err)
}
for _, f := range files {
err := ioutil.WriteFile(filepath.Join(dir, f), []byte("test"), 0600)
err := os.WriteFile(filepath.Join(dir, f), []byte("test"), 0600)
if err != nil {
t.Fatalf("error creating test file: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/build/builder/cmd/scmauth/scmauths.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scmauth

import (
"fmt"
"io/ioutil"
"net/url"
"os"

Expand Down Expand Up @@ -53,7 +52,7 @@ func (a SCMAuths) doSetup(secretsDir string) (SCMAuthContext, error) {
}

func (a SCMAuths) Setup(secretsDir string) (env []string, overrideURL *url.URL, gitConfig string, err error) {
files, err := ioutil.ReadDir(secretsDir)
files, err := os.ReadDir(secretsDir)
if err != nil {
return nil, nil, "", err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/build/builder/cmd/scmauth/scmauths_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scmauth

import (
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -34,7 +33,7 @@ func scmAuths() SCMAuths {
func TestPresent(t *testing.T) {
secretDir := secretDir(t, "one", "three")
defer os.RemoveAll(secretDir)
files, err := ioutil.ReadDir(secretDir)
files, err := os.ReadDir(secretDir)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/build/builder/cmd/scmauth/sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scmauth

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
)

Expand All @@ -16,7 +16,7 @@ type SSHPrivateKey struct{}
// SSH key while accessing private repository. Note that this does _not_ generate a .gitconfig
// file or set the GIT_CONFIG environment variable.
func (SSHPrivateKey) Setup(baseDir string, context SCMAuthContext) (string, error) {
script, err := ioutil.TempFile("", "gitssh")
script, err := os.CreateTemp("", "gitssh")
if err != nil {
return "", err
}
Expand All @@ -26,7 +26,7 @@ func (SSHPrivateKey) Setup(baseDir string, context SCMAuthContext) (string, erro
}
foundPrivateKey := false
foundKnownHosts := false
files, err := ioutil.ReadDir(baseDir)
files, err := os.ReadDir(baseDir)
if err != nil {
return "", err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/build/builder/cmd/scmauth/sshkey_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scmauth

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -31,7 +30,7 @@ func TestSSHPrivateKeySetup(t *testing.T) {
if !isSet {
t.Errorf("GIT_SSH is not set")
}
buf, err := ioutil.ReadFile(fileName)
buf, err := os.ReadFile(fileName)
if err != nil {
t.Errorf("problem reading ssh file %s", err.Error())
}
Expand All @@ -55,7 +54,7 @@ func TestSSHPrivateKeyWithKnownHostsSetup(t *testing.T) {
if !isSet {
t.Errorf("GIT_SSH is not set")
}
buf, err := ioutil.ReadFile(fileName)
buf, err := os.ReadFile(fileName)
if err != nil {
t.Errorf("problem reading ssh file %s", err.Error())
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/builder/cmd/scmauth/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scmauth

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -17,13 +16,13 @@ var log = utillog.ToFile(os.Stderr, 2)
// section to the provided path.
// Returns the path to the git configuration file, and error if raised.
func createGitConfig(includePath string, context SCMAuthContext) (string, error) {
tempDir, err := ioutil.TempDir("", "git")
tempDir, err := os.MkdirTemp("", "git")
if err != nil {
return "", err
}
gitconfig := filepath.Join(tempDir, ".gitconfig")
content := fmt.Sprintf("[include]\npath = %s\n", includePath)
if err := ioutil.WriteFile(gitconfig, []byte(content), 0600); err != nil {
if err := os.WriteFile(gitconfig, []byte(content), 0600); err != nil {
return "", err
}
// The GIT_CONFIG variable won't affect regular git operation
Expand Down Expand Up @@ -61,6 +60,6 @@ func ensureGitConfigIncludes(path string, context SCMAuthContext) (string, error

lines = append(lines, fmt.Sprintf("path = %s", path))
content := []byte(strings.Join(lines, "\n"))
err = ioutil.WriteFile(gitconfig, content, 0600)
err = os.WriteFile(gitconfig, content, 0600)
return gitconfig, err
}
5 changes: 2 additions & 3 deletions pkg/build/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -369,7 +368,7 @@ func readSourceInfo() (*git.SourceInfo, error) {
return nil, nil
}

data, err := ioutil.ReadFile(sourceInfoPath)
data, err := os.ReadFile(sourceInfoPath)
if err != nil {
return nil, err
}
Expand All @@ -389,7 +388,7 @@ func readSourceInfo() (*git.SourceInfo, error) {
func addBuildParameters(dir string, build *buildapiv1.Build, sourceInfo *git.SourceInfo) error {
dockerfilePath := getDockerfilePath(dir, build)

in, err := ioutil.ReadFile(dockerfilePath)
in, err := os.ReadFile(dockerfilePath)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package builder

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -506,7 +505,7 @@ func Test_addBuildParameters(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
f, err := ioutil.TempFile("", "builder-dockertest")
f, err := os.CreateTemp("", "builder-dockertest")
if err != nil {
t.Fatal(err)
}
Expand All @@ -532,7 +531,7 @@ func Test_addBuildParameters(t *testing.T) {
build.Spec.Source.Images = test.build
sourceInfo := &git.SourceInfo{}
testErr := addBuildParameters(filepath.Dir(f.Name()), build, sourceInfo)
out, err := ioutil.ReadFile(f.Name())
out, err := os.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -658,7 +657,7 @@ func Test_findReferencedImages(t *testing.T) {
}
for i, test := range tests {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
f, err := ioutil.TempFile("", "builder-dockertest")
f, err := os.CreateTemp("", "builder-dockertest")
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/builder/daemonless.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -191,7 +190,7 @@ func pullDaemonlessImage(sc types.SystemContext, store storage.Store, imageName
// in case the node credentials facilitate the pulling of the image
mergedCreds := mergeNodeCredentials(dockerConfigCreds)

dstFile, err := ioutil.TempFile("", "config")
dstFile, err := os.CreateTemp("", "config")
if err != nil {
return fmt.Errorf("error creating tmp credentials file: %v", err)
}
Expand Down Expand Up @@ -407,7 +406,7 @@ func appendRHRepoMount(pathStart string, mountsMap *TransientMounts) error {

// Add a bind of repo file, to pass along anything that the runtime mounted from the node
log.V(0).Infof("Adding transient rw bind mount for %s", path)
tmpDir, err := ioutil.TempDir("/tmp", repoFile+"-copy")
tmpDir, err := os.MkdirTemp("/tmp", repoFile+"-copy")
if err != nil {
log.V(0).Infof("Falling back to the Red Hat yum repository configuration in the base image: failed to create tmpdir for %s secret: %v", repoFile, err)
return nil
Expand Down Expand Up @@ -445,7 +444,7 @@ func coreAppendSecretLinksToDirs(pathStart, pathEnd string, mountsMap *Transient

// Add a bind of dir secret, to pass along anything that the runtime mounted from the node
log.V(0).Infof("Adding transient rw bind mount for %s", path)
tmpDir, err := ioutil.TempDir("/tmp", pathEnd+"-copy")
tmpDir, err := os.MkdirTemp("/tmp", pathEnd+"-copy")
if err != nil {
log.V(0).Infof("Red Hat subscription content will not be available in this build: failed to create tmpdir for %s secrets: %v", pathEnd, err)
return nil
Expand Down
7 changes: 3 additions & 4 deletions pkg/build/builder/daemonless_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package builder

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -429,7 +428,7 @@ func coreTestSubscriptionDirMounts(t *testing.T, path string, fn appendFunc) {
},
}
for _, tc := range cases {
tmpDir, err := ioutil.TempDir(os.TempDir(), tc.name)
tmpDir, err := os.MkdirTemp(os.TempDir(), tc.name)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down Expand Up @@ -498,7 +497,7 @@ func coreTestSubscriptionDirMounts(t *testing.T, path string, fn appendFunc) {
splitMount := strings.Split(mounts[0], ":")
if len(splitMount) > 0 {
copyDir := splitMount[0]
files, err := ioutil.ReadDir(copyDir)
files, err := os.ReadDir(copyDir)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down Expand Up @@ -573,7 +572,7 @@ func TestRHRepoMount(t *testing.T) {
},
}
for _, tc := range cases {
tmpDir, err := ioutil.TempDir(os.TempDir(), tc.name)
tmpDir, err := os.MkdirTemp(os.TempDir(), tc.name)
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/build/builder/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -391,7 +390,7 @@ func TestDockerfilePath(t *testing.T) {
}

for _, test := range tests {
buildDir, err := ioutil.TempDir("", "dockerfile-path")
buildDir, err := os.MkdirTemp("", "dockerfile-path")
if err != nil {
t.Errorf("failed to create tmpdir: %v", err)
continue
Expand All @@ -407,7 +406,7 @@ func TestDockerfilePath(t *testing.T) {
t.Errorf("failed to create directory %s: %v", filepath.Dir(absoluteDockerfilePath), err)
continue
}
if err = ioutil.WriteFile(absoluteDockerfilePath, []byte(from), os.FileMode(0644)); err != nil {
if err = os.WriteFile(absoluteDockerfilePath, []byte(from), os.FileMode(0644)); err != nil {
t.Errorf("failed to write dockerfile to %s: %v", absoluteDockerfilePath, err)
continue
}
Expand Down Expand Up @@ -465,7 +464,7 @@ func TestDockerfilePath(t *testing.T) {
}

// check that our Dockerfile has been modified
dockerfileData, err := ioutil.ReadFile(absoluteDockerfilePath)
dockerfileData, err := os.ReadFile(absoluteDockerfilePath)
if err != nil {
t.Errorf("failed to read dockerfile %s: %v", absoluteDockerfilePath, err)
continue
Expand Down Expand Up @@ -573,7 +572,7 @@ USER 1001`

client := buildfake.Clientset{}

buildDir, err := ioutil.TempDir("", "dockerfile-path")
buildDir, err := os.MkdirTemp("", "dockerfile-path")
if err != nil {
t.Errorf("failed to create tmpdir: %v", err)
}
Expand Down
Loading