mirror of
https://github.com/containers/buildah.git
synced 2025-07-31 15:24:26 +03:00
Replace io/ioutil calls with os calls
In golang 1.19, `io/ioutil` is fully deprecated preventing Buildah from compiling. Replace all calls with equivalent calls from the `os` package. Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
3
add.go
3
add.go
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -115,7 +114,7 @@ func getURL(src string, chown *idtools.IDPair, mountpoint, renameTarget string,
|
||||
if size < 0 {
|
||||
// Create a temporary file and copy the content to it, so that
|
||||
// we can figure out how much content there is.
|
||||
f, err := ioutil.TempFile(mountpoint, "download")
|
||||
f, err := os.CreateTemp(mountpoint, "download")
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating temporary file to hold %q: %w", src, err)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -402,7 +401,7 @@ func OpenBuilder(store storage.Store, container string) (*Builder, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile))
|
||||
buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -444,7 +443,7 @@ func OpenBuilderByPath(store storage.Store, path string) (*Builder, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile))
|
||||
buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
logrus.Debugf("error reading %q: %v, ignoring container %q", filepath.Join(cdir, stateFile), err, container.ID)
|
||||
@ -481,7 +480,7 @@ func OpenAllBuilders(store storage.Store) (builders []*Builder, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile))
|
||||
buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
logrus.Debugf("%v, ignoring container %q", err, container.ID)
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
@ -690,7 +689,7 @@ func runUsingChrootExecMain() {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
setgroups, _ := ioutil.ReadFile("/proc/self/setgroups")
|
||||
setgroups, _ := os.ReadFile("/proc/self/setgroups")
|
||||
if strings.Trim(string(setgroups), "\n") != "deny" {
|
||||
logrus.Debugf("clearing supplemental groups")
|
||||
if err = syscall.Setgroups([]int{}); err != nil {
|
||||
|
@ -5,7 +5,7 @@ package chroot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/seccomp"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -187,7 +187,7 @@ func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
|
||||
}
|
||||
spec.Linux.Seccomp = seccompConfig
|
||||
default:
|
||||
seccompProfile, err := ioutil.ReadFile(seccompProfilePath)
|
||||
seccompProfile, err := os.ReadFile(seccompProfilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening seccomp profile failed: %w", err)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@ -166,7 +165,7 @@ func onBuild(builder *buildah.Builder, quiet bool) error {
|
||||
case "RUN":
|
||||
var stdout io.Writer
|
||||
if quiet {
|
||||
stdout = ioutil.Discard
|
||||
stdout = io.Discard
|
||||
}
|
||||
if err := builder.Run(args, buildah.RunOptions{Stdout: stdout}); err != nil {
|
||||
return err
|
||||
@ -347,7 +346,7 @@ func fromCmd(c *cobra.Command, args []string, iopts fromReply) error {
|
||||
|
||||
if iopts.cidfile != "" {
|
||||
filePath := iopts.cidfile
|
||||
if err := ioutil.WriteFile(filePath, []byte(builder.ContainerID), 0644); err != nil {
|
||||
if err := os.WriteFile(filePath, []byte(builder.ContainerID), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write container ID file %q: %w", filePath, err)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -913,7 +912,7 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI
|
||||
}
|
||||
|
||||
if opts.digestfile != "" {
|
||||
if err = ioutil.WriteFile(opts.digestfile, []byte(digest.String()), 0644); err != nil {
|
||||
if err = os.WriteFile(opts.digestfile, []byte(digest.String()), 0644); err != nil {
|
||||
return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", opts.digestfile, err))
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@ -246,7 +245,7 @@ func pushCmd(c *cobra.Command, args []string, iopts pushOptions) error {
|
||||
logrus.Debugf("Successfully pushed %s with digest %s", transports.ImageName(dest), digest.String())
|
||||
|
||||
if iopts.digestfile != "" {
|
||||
if err = ioutil.WriteFile(iopts.digestfile, []byte(digest.String()), 0644); err != nil {
|
||||
if err = os.WriteFile(iopts.digestfile, []byte(digest.String()), 0644); err != nil {
|
||||
return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", iopts.digestfile, err))
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@ -392,7 +391,7 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options
|
||||
dest = dest2
|
||||
}
|
||||
if options.IIDFile != "" {
|
||||
if err = ioutil.WriteFile(options.IIDFile, []byte("sha256:"+img.ID), 0644); err != nil {
|
||||
if err = os.WriteFile(options.IIDFile, []byte("sha256:"+img.ID), 0644); err != nil {
|
||||
return imgID, nil, "", err
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
@ -573,7 +572,7 @@ func copierWithSubprocess(bulkReader io.Reader, bulkWriter io.Writer, req reques
|
||||
bulkReader = bytes.NewReader([]byte{})
|
||||
}
|
||||
if bulkWriter == nil {
|
||||
bulkWriter = ioutil.Discard
|
||||
bulkWriter = io.Discard
|
||||
}
|
||||
cmd := reexec.Command(copierCommand)
|
||||
stdinRead, stdinWrite, err := os.Pipe()
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -124,11 +123,11 @@ func testGetPermissionError(t *testing.T) {
|
||||
require.NoError(t, err, "error creating a readable directory")
|
||||
err = os.Mkdir(filepath.Join(tmp, "readable-directory", "unreadable-subdirectory"), 0000)
|
||||
require.NoError(t, err, "error creating an unreadable subdirectory")
|
||||
err = ioutil.WriteFile(filepath.Join(tmp, "unreadable-file"), []byte("hi, i'm a file that you can't read"), 0000)
|
||||
err = os.WriteFile(filepath.Join(tmp, "unreadable-file"), []byte("hi, i'm a file that you can't read"), 0000)
|
||||
require.NoError(t, err, "error creating an unreadable file")
|
||||
err = ioutil.WriteFile(filepath.Join(tmp, "readable-file"), []byte("hi, i'm also a file, and you can read me"), 0644)
|
||||
err = os.WriteFile(filepath.Join(tmp, "readable-file"), []byte("hi, i'm also a file, and you can read me"), 0644)
|
||||
require.NoError(t, err, "error creating a readable file")
|
||||
err = ioutil.WriteFile(filepath.Join(tmp, "readable-directory", "unreadable-file"), []byte("hi, i'm also a file that you can't read"), 0000)
|
||||
err = os.WriteFile(filepath.Join(tmp, "readable-directory", "unreadable-file"), []byte("hi, i'm also a file that you can't read"), 0000)
|
||||
require.NoError(t, err, "error creating an unreadable file in a readable directory")
|
||||
for _, ignore := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("ignore=%v", ignore), func(t *testing.T) {
|
||||
@ -175,7 +174,7 @@ func TestGetNoCrossDevice(t *testing.T) {
|
||||
}()
|
||||
|
||||
skipped := filepath.Join(subdir, "skipped.txt")
|
||||
err = ioutil.WriteFile(skipped, []byte("this file should have been skipped\n"), 0644)
|
||||
err = os.WriteFile(skipped, []byte("this file should have been skipped\n"), 0644)
|
||||
require.NoErrorf(t, err, "error writing file at %q", skipped)
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@ -779,7 +778,7 @@ func testGetSingle(t *testing.T) {
|
||||
}
|
||||
t.Run(fmt.Sprintf("absolute=%t,topdir=%s,archive=%s,item=%s", absolute, topdir, testArchive.name, name), func(t *testing.T) {
|
||||
// check if we can get this one item
|
||||
err := Get(root, topdir, getOptions, []string{name}, ioutil.Discard)
|
||||
err := Get(root, topdir, getOptions, []string{name}, io.Discard)
|
||||
// if we couldn't read that content, check if it's one of the expected failures
|
||||
if err != nil && isExpectedError(err, topdir != "" && topdir != ".", testItem.Name, testArchive.expectedGetErrors) {
|
||||
return
|
||||
@ -1404,7 +1403,7 @@ func testGetMultiple(t *testing.T) {
|
||||
|
||||
t.Run(fmt.Sprintf("topdir=%s,archive=%s,case=%s,pattern=%s", topdir, testArchive.name, testCase.name, testCase.pattern), func(t *testing.T) {
|
||||
// ensure that we can get stuff using this spec
|
||||
err := Get(root, topdir, getOptions, []string{testCase.pattern}, ioutil.Discard)
|
||||
err := Get(root, topdir, getOptions, []string{testCase.pattern}, io.Discard)
|
||||
if err != nil && isExpectedError(err, topdir != "" && topdir != ".", testCase.pattern, testArchive.expectedGetErrors) {
|
||||
return
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package copier
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
@ -28,7 +27,7 @@ func TestXattrs(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
for attribute, value := range testValues {
|
||||
t.Run(fmt.Sprintf("attribute=%s", attribute), func(t *testing.T) {
|
||||
f, err := ioutil.TempFile(tmp, "copier-xattr-test-")
|
||||
f, err := os.CreateTemp(tmp, "copier-xattr-test-")
|
||||
if !assert.Nil(t, err, "error creating test file: %v", err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
urlpkg "net/url"
|
||||
"os"
|
||||
@ -121,7 +121,7 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
|
||||
url != "-" {
|
||||
return "", "", nil
|
||||
}
|
||||
name, err = ioutil.TempDir(dir, prefix)
|
||||
name, err = os.MkdirTemp(dir, prefix)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("creating temporary directory for %q: %w", url, err)
|
||||
}
|
||||
@ -255,7 +255,7 @@ func downloadToDirectory(url, dir string) error {
|
||||
return err
|
||||
}
|
||||
defer resp1.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp1.Body)
|
||||
body, err := io.ReadAll(resp1.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -271,7 +271,7 @@ func downloadToDirectory(url, dir string) error {
|
||||
func stdinToDirectory(dir string) error {
|
||||
logrus.Debugf("extracting stdin to %q", dir)
|
||||
r := bufio.NewReader(os.Stdin)
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read from stdin: %w", err)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -167,7 +166,7 @@ func TestCompositeDigester(t *testing.T) {
|
||||
// the filter should have left modtime to "roughly now"
|
||||
require.NotEqual(t, zero, hdr.ModTime, "timestamp for entry should not have been zero")
|
||||
}
|
||||
n, err = io.Copy(ioutil.Discard, tr)
|
||||
n, err = io.Copy(io.Discard, tr)
|
||||
require.Nil(t, err, "error reading tar content from buffer: %v", err)
|
||||
require.Equal(t, hdr.Size, n, "short read reading tar content")
|
||||
hdr, err = tr.Next()
|
||||
|
3
image.go
3
image.go
@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -309,7 +308,7 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
|
||||
logrus.Debugf("layer list: %q", layers)
|
||||
|
||||
// Make a temporary directory to hold blobs.
|
||||
path, err := ioutil.TempDir(os.TempDir(), define.Package)
|
||||
path, err := os.MkdirTemp(os.TempDir(), define.Package)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("creating temporary directory to hold layer blobs: %w", err)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -153,7 +152,7 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
data = ioutil.NopCloser(pData)
|
||||
data = io.NopCloser(pData)
|
||||
}
|
||||
|
||||
dockerfiles = append(dockerfiles, data)
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
@ -200,7 +199,7 @@ func newExecutor(logger *logrus.Logger, logPrefix string, store storage.Store, o
|
||||
|
||||
writer := options.ReportWriter
|
||||
if options.Quiet {
|
||||
writer = ioutil.Discard
|
||||
writer = io.Discard
|
||||
}
|
||||
|
||||
var rusageLogFile io.Writer
|
||||
@ -589,7 +588,7 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
|
||||
|
||||
stdout := b.out
|
||||
if b.quiet {
|
||||
b.out = ioutil.Discard
|
||||
b.out = io.Discard
|
||||
}
|
||||
|
||||
cleanup := func() error {
|
||||
@ -954,7 +953,7 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
|
||||
}
|
||||
logrus.Debugf("printing final image id %q", imageID)
|
||||
if b.iidfile != "" {
|
||||
if err = ioutil.WriteFile(b.iidfile, []byte("sha256:"+imageID), 0644); err != nil {
|
||||
if err = os.WriteFile(b.iidfile, []byte("sha256:"+imageID), 0644); err != nil {
|
||||
return imageID, ref, fmt.Errorf("failed to write image ID to file %q: %w", b.iidfile, err)
|
||||
}
|
||||
} else {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -116,7 +115,7 @@ func updateIndexWithNewManifestDescriptor(manifest *specV1.Descriptor, sourcePat
|
||||
index := specV1.Index{}
|
||||
indexPath := filepath.Join(sourcePath, "index.json")
|
||||
|
||||
rawData, err := ioutil.ReadFile(indexPath)
|
||||
rawData, err := os.ReadFile(indexPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,5 +129,5 @@ func updateIndexWithNewManifestDescriptor(manifest *specV1.Descriptor, sourcePat
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(indexPath, rawData, 0644)
|
||||
return os.WriteFile(indexPath, rawData, 0644)
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -423,7 +422,7 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) (
|
||||
UnsetEnvs: iopts.UnsetEnvs,
|
||||
}
|
||||
if iopts.Quiet {
|
||||
options.ReportWriter = ioutil.Discard
|
||||
options.ReportWriter = io.Discard
|
||||
}
|
||||
return options, containerfiles, removeAll, nil
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package overlay
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -60,7 +59,7 @@ func TempDir(containerDir string, rootUID, rootGID int) (string, error) {
|
||||
return "", fmt.Errorf("failed to create the overlay %s directory: %w", contentDir, err)
|
||||
}
|
||||
|
||||
contentDir, err := ioutil.TempDir(contentDir, "")
|
||||
contentDir, err := os.MkdirTemp(contentDir, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create the overlay tmpdir in %s directory: %w", contentDir, err)
|
||||
}
|
||||
@ -291,7 +290,7 @@ func CleanupMount(contentDir string) (Err error) {
|
||||
func CleanupContent(containerDir string) (Err error) {
|
||||
contentDir := filepath.Join(containerDir, "overlay")
|
||||
|
||||
files, err := ioutil.ReadDir(contentDir)
|
||||
files, err := os.ReadDir(contentDir)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -80,7 +79,7 @@ func (a *AgentServer) Serve(processLabel string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
serveDir, err := ioutil.TempDir("", ".buildah-ssh-sock")
|
||||
serveDir, err := os.MkdirTemp("", ".buildah-ssh-sock")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -223,7 +222,7 @@ func NewSource(paths []string) (*Source, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dt, err := ioutil.ReadAll(&io.LimitedReader{R: f, N: 100 * 1024})
|
||||
dt, err := io.ReadAll(&io.LimitedReader{R: f, N: 100 * 1024})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package util
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ReadUptime() (time.Duration, error) {
|
||||
buf, err := ioutil.ReadFile("/proc/uptime")
|
||||
buf, err := os.ReadFile("/proc/uptime")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -21,12 +20,12 @@ func MirrorToTempFileIfPathIsDescriptor(file string) (string, bool) {
|
||||
if !strings.HasPrefix(file, "/dev/fd") {
|
||||
return file, false
|
||||
}
|
||||
b, err := ioutil.ReadFile(file)
|
||||
b, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
// if anything goes wrong return original path
|
||||
return file, false
|
||||
}
|
||||
tmpfile, err := ioutil.TempFile(os.TempDir(), "buildah-temp-file")
|
||||
tmpfile, err := os.CreateTemp(os.TempDir(), "buildah-temp-file")
|
||||
if err != nil {
|
||||
return file, false
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -556,7 +555,7 @@ func runUsingRuntime(options RunOptions, configureNetwork bool, moreCreateArgs [
|
||||
}()
|
||||
|
||||
// Make sure we read the container's exit status when it exits.
|
||||
pidValue, err := ioutil.ReadFile(pidFile)
|
||||
pidValue, err := os.ReadFile(pidFile)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
@ -1185,7 +1184,7 @@ func (b *Builder) runUsingRuntimeSubproc(isolation define.Isolation, options Run
|
||||
logrus.Errorf("did not get container create message from subprocess: %v", err)
|
||||
} else {
|
||||
pidFile := filepath.Join(bundlePath, "pid")
|
||||
pidValue, err := ioutil.ReadFile(pidFile)
|
||||
pidValue, err := os.ReadFile(pidFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1655,7 +1654,7 @@ func (b *Builder) getSecretMount(tokens []string, secrets map[string]define.Secr
|
||||
switch secr.SourceType {
|
||||
case "env":
|
||||
data = []byte(os.Getenv(secr.Source))
|
||||
tmpFile, err := ioutil.TempFile(define.TempDir, "buildah*")
|
||||
tmpFile, err := os.CreateTemp(define.TempDir, "buildah*")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@ -1666,7 +1665,7 @@ func (b *Builder) getSecretMount(tokens []string, secrets map[string]define.Secr
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
data, err = ioutil.ReadFile(secr.Source)
|
||||
data, err = os.ReadFile(secr.Source)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@ -1680,7 +1679,7 @@ func (b *Builder) getSecretMount(tokens []string, secrets map[string]define.Secr
|
||||
if err := os.MkdirAll(filepath.Dir(ctrFileOnHost), 0755); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if err := ioutil.WriteFile(ctrFileOnHost, data, 0644); err != nil {
|
||||
if err := os.WriteFile(ctrFileOnHost, data, 0644); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ package buildah
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -72,7 +71,7 @@ func setChildProcess() error {
|
||||
}
|
||||
|
||||
func (b *Builder) Run(command []string, options RunOptions) error {
|
||||
p, err := ioutil.TempDir("", Package)
|
||||
p, err := os.MkdirTemp("", Package)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -70,7 +69,7 @@ func setChildProcess() error {
|
||||
|
||||
// Run runs the specified command in the container's root filesystem.
|
||||
func (b *Builder) Run(command []string, options RunOptions) error {
|
||||
p, err := ioutil.TempDir("", define.Package)
|
||||
p, err := os.MkdirTemp("", define.Package)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -480,7 +479,7 @@ func setupRootlessNetwork(pid int) (teardown func(), err error) {
|
||||
defer rootlessSlirpSyncR.Close()
|
||||
|
||||
// Be sure there are no fds inherited to slirp4netns except the sync pipe
|
||||
files, err := ioutil.ReadDir("/proc/self/fd")
|
||||
files, err := os.ReadDir("/proc/self/fd")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list open fds: %w", err)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ package buildah
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/seccomp"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -22,7 +22,7 @@ func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
|
||||
}
|
||||
spec.Linux.Seccomp = seccompConfig
|
||||
default:
|
||||
seccompProfile, err := ioutil.ReadFile(seccompProfilePath)
|
||||
seccompProfile, err := os.ReadFile(seccompProfilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening seccomp profile failed: %w", err)
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -174,7 +173,7 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int) {
|
||||
require.Nil(t, err, "error creating test directory to check if xattrs are testable: %v", err)
|
||||
}
|
||||
testFile := filepath.Join(testDir, "testfile")
|
||||
if err := ioutil.WriteFile(testFile, []byte("whatever"), 0600); err != nil {
|
||||
if err := os.WriteFile(testFile, []byte("whatever"), 0600); err != nil {
|
||||
require.Nil(t, err, "error creating test file to check if xattrs are testable: %v", err)
|
||||
}
|
||||
can := false
|
||||
@ -232,7 +231,7 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int) {
|
||||
dockerfileContents := []byte(test.dockerfileContents)
|
||||
if len(dockerfileContents) == 0 {
|
||||
// no inlined contents -> read them from the specified location
|
||||
contents, err := ioutil.ReadFile(dockerfileName)
|
||||
contents, err := os.ReadFile(dockerfileName)
|
||||
require.Nil(t, err, "error reading Dockerfile %q", filepath.Join(tempdir, dockerfileName))
|
||||
dockerfileContents = contents
|
||||
}
|
||||
@ -266,7 +265,7 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int) {
|
||||
require.Nil(t, err, "error mounting test layer to check if xattrs are testable: %v", err)
|
||||
}
|
||||
testFile := filepath.Join(mountPoint, "testfile")
|
||||
if err := ioutil.WriteFile(testFile, []byte("whatever"), 0600); err != nil {
|
||||
if err := os.WriteFile(testFile, []byte("whatever"), 0600); err != nil {
|
||||
require.Nil(t, err, "error creating file in test layer to check if xattrs are testable: %v", err)
|
||||
}
|
||||
can := false
|
||||
@ -341,7 +340,7 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
|
||||
// contents we were passed, which may only be an initial subset of the
|
||||
// original file, or inlined information, in which case the file didn't
|
||||
// necessarily exist
|
||||
err := ioutil.WriteFile(dockerfileName, dockerfileContents, 0644)
|
||||
err := os.WriteFile(dockerfileName, dockerfileContents, 0644)
|
||||
require.Nil(t, err, "error writing Dockerfile at %q", dockerfileName)
|
||||
err = os.Chtimes(dockerfileName, testDate, testDate)
|
||||
require.Nil(t, err, "error resetting timestamp on Dockerfile at %q", dockerfileName)
|
||||
@ -364,7 +363,7 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
|
||||
dockerfileContents = append(dockerfileContents, []byte("\n(no final end-of-line)")...)
|
||||
}
|
||||
t.Logf("Dockerfile contents:\n%s", dockerfileContents)
|
||||
if dockerignoreContents, err := ioutil.ReadFile(filepath.Join(contextDir, ".dockerignore")); err == nil {
|
||||
if dockerignoreContents, err := os.ReadFile(filepath.Join(contextDir, ".dockerignore")); err == nil {
|
||||
t.Logf(".dockerignore contents:\n%s", string(dockerignoreContents))
|
||||
}
|
||||
}
|
||||
@ -796,14 +795,14 @@ func saveReport(ctx context.Context, t *testing.T, ref types.ImageReference, dir
|
||||
err := os.MkdirAll(directory, 0755)
|
||||
require.Nil(t, err, "error ensuring directory %q exists for storing a report")
|
||||
// save the Dockerfile that was used to generate the image
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "Dockerfile"), dockerfileContents, 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "Dockerfile"), dockerfileContents, 0644)
|
||||
require.Nil(t, err, "error saving Dockerfile for image %q", imageName)
|
||||
// save the log generated while building the image
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "build.log"), buildLog, 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "build.log"), buildLog, 0644)
|
||||
require.Nil(t, err, "error saving build log for image %q", imageName)
|
||||
// save the version information
|
||||
if len(version) > 0 {
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "version"), []byte(strings.Join(version, "\n")+"\n"), 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "version"), []byte(strings.Join(version, "\n")+"\n"), 0644)
|
||||
require.Nil(t, err, "error saving builder version information for image %q", imageName)
|
||||
}
|
||||
// open the image for reading
|
||||
@ -829,10 +828,10 @@ func saveReport(ctx context.Context, t *testing.T, ref types.ImageReference, dir
|
||||
encodedConfig, err := json.Marshal(ociConfig)
|
||||
require.Nil(t, err, "error encoding OCI-format configuration from image %q for saving", imageName)
|
||||
// save the config blob in the OCI format
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "oci.json"), encodedConfig, 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "oci.json"), encodedConfig, 0644)
|
||||
require.Nil(t, err, "error saving OCI-format configuration from image %q", imageName)
|
||||
// save the config blob in its original format
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "config.json"), rawConfig, 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "config.json"), rawConfig, 0644)
|
||||
require.Nil(t, err, "error saving original configuration from image %q", imageName)
|
||||
// start pulling layer information
|
||||
layerBlobInfos, err := img.LayerInfosForCopy(ctx)
|
||||
@ -876,7 +875,7 @@ func saveReport(ctx context.Context, t *testing.T, ref types.ImageReference, dir
|
||||
// there's no point in saving them for comparison later
|
||||
encodedFSTree, err := json.Marshal(fstree.Tree)
|
||||
require.Nil(t, err, "error encoding filesystem tree from image %q for saving", imageName)
|
||||
err = ioutil.WriteFile(filepath.Join(directory, "fs.json"), encodedFSTree, 0644)
|
||||
err = os.WriteFile(filepath.Join(directory, "fs.json"), encodedFSTree, 0644)
|
||||
require.Nil(t, err, "error saving filesystem tree from image %q", imageName)
|
||||
}
|
||||
|
||||
@ -1008,21 +1007,21 @@ func applyLayerToFSTree(t *testing.T, layer *Layer, root *FSEntry) {
|
||||
// read information about the specified image from the specified directory
|
||||
func readReport(t *testing.T, directory string) (original, oci, fs map[string]interface{}) {
|
||||
// read the config in the as-committed (docker) format
|
||||
originalConfig, err := ioutil.ReadFile(filepath.Join(directory, "config.json"))
|
||||
originalConfig, err := os.ReadFile(filepath.Join(directory, "config.json"))
|
||||
require.Nil(t, err, "error reading configuration file %q", filepath.Join(directory, "config.json"))
|
||||
// dump it into a map
|
||||
original = make(map[string]interface{})
|
||||
err = json.Unmarshal(originalConfig, &original)
|
||||
require.Nil(t, err, "error decoding configuration from file %q", filepath.Join(directory, "config.json"))
|
||||
// read the config in converted-to-OCI format
|
||||
ociConfig, err := ioutil.ReadFile(filepath.Join(directory, "oci.json"))
|
||||
ociConfig, err := os.ReadFile(filepath.Join(directory, "oci.json"))
|
||||
require.Nil(t, err, "error reading OCI configuration file %q", filepath.Join(directory, "oci.json"))
|
||||
// dump it into a map
|
||||
oci = make(map[string]interface{})
|
||||
err = json.Unmarshal(ociConfig, &oci)
|
||||
require.Nil(t, err, "error decoding OCI configuration from file %q", filepath.Join(directory, "oci.json"))
|
||||
// read the filesystem
|
||||
fsInfo, err := ioutil.ReadFile(filepath.Join(directory, "fs.json"))
|
||||
fsInfo, err := os.ReadFile(filepath.Join(directory, "fs.json"))
|
||||
require.Nil(t, err, "error reading filesystem summary file %q", filepath.Join(directory, "fs.json"))
|
||||
// dump it into a map for comparison
|
||||
fs = make(map[string]interface{})
|
||||
@ -1542,7 +1541,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
|
||||
}
|
||||
filename := filepath.Join(contextDir, "archive", "should-be-owned-by-root")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 0, 0); err != nil {
|
||||
@ -1552,7 +1551,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on file owned by root file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "archive", "should-be-owned-by-99")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 99, 99); err != nil {
|
||||
@ -1628,7 +1627,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
|
||||
}
|
||||
filename := filepath.Join(contextDir, "subdir", "would-be-owned-by-root")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 0, 0); err != nil {
|
||||
@ -1638,7 +1637,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on file owned by root file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "subdir", "would-be-owned-by-99")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 99, 99); err != nil {
|
||||
@ -1667,7 +1666,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
|
||||
}
|
||||
filename := filepath.Join(contextDir, "subdir", "would-be-owned-by-root")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 0, 0); err != nil {
|
||||
@ -1677,7 +1676,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on file owned by root file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "subdir", "would-be-owned-by-99")
|
||||
if err = ioutil.WriteFile(filename, content, 0640); err != nil {
|
||||
if err = os.WriteFile(filename, content, 0640); err != nil {
|
||||
return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
|
||||
}
|
||||
if err = os.Chown(filename, 99, 99); err != nil {
|
||||
@ -1724,7 +1723,7 @@ var internalTestCases = []testCase{
|
||||
}, "\n"),
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
filename := filepath.Join(contextDir, "should-be-setuid-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating setuid test file in temporary context directory: %w", err)
|
||||
}
|
||||
if err = syscall.Chmod(filename, syscall.S_ISUID|0755); err != nil {
|
||||
@ -1734,7 +1733,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on setuid test file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "should-be-setgid-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating setgid test file in temporary context directory: %w", err)
|
||||
}
|
||||
if err = syscall.Chmod(filename, syscall.S_ISGID|0755); err != nil {
|
||||
@ -1744,7 +1743,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on setgid test file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "should-be-sticky-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating sticky test file in temporary context directory: %w", err)
|
||||
}
|
||||
if err = syscall.Chmod(filename, syscall.S_ISVTX|0755); err != nil {
|
||||
@ -1754,7 +1753,7 @@ var internalTestCases = []testCase{
|
||||
return fmt.Errorf("setting date on sticky test file in temporary context directory: %w", err)
|
||||
}
|
||||
filename = filepath.Join(contextDir, "should-not-be-setuid-setgid-sticky-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating non-suid non-sgid non-sticky test file in temporary context directory: %w", err)
|
||||
}
|
||||
if err = syscall.Chmod(filename, 0640); err != nil {
|
||||
@ -1785,7 +1784,7 @@ var internalTestCases = []testCase{
|
||||
}
|
||||
|
||||
filename := filepath.Join(contextDir, "xattrs-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating test file with xattrs in temporary context directory: %w", err)
|
||||
}
|
||||
if err = copier.Lsetxattrs(filename, map[string]string{"user.a": "test"}); err != nil {
|
||||
@ -1980,7 +1979,7 @@ var internalTestCases = []testCase{
|
||||
}
|
||||
|
||||
filename := filepath.Join(contextDir, "xattrs-file")
|
||||
if err = ioutil.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
if err = os.WriteFile(filename, []byte("test content"), 0644); err != nil {
|
||||
return fmt.Errorf("creating test file with xattrs in temporary context directory: %w", err)
|
||||
}
|
||||
if err = copier.Lsetxattrs(filename, map[string]string{"user.a": "test"}); err != nil {
|
||||
@ -2147,7 +2146,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/empty",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0600); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0600); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2167,7 +2166,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0644); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0644); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2187,7 +2186,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0600); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0600); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2207,7 +2206,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"!**/*-c"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0640); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0640); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2227,7 +2226,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("!**/*-c\n")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0100); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0100); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2247,7 +2246,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("subdir-c")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0200); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0200); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2267,7 +2266,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("subdir-c")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0400); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0400); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2287,7 +2286,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-c")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0200); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0200); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2307,7 +2306,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-c")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0400); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0400); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2327,7 +2326,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("subdir-*")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0000); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0000); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2347,7 +2346,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("subdir-*")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0660); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0660); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2367,7 +2366,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-*")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0000); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0000); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2387,7 +2386,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-*")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0660); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0660); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2407,7 +2406,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-f")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0666); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2427,7 +2426,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-f")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0640); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0640); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2447,7 +2446,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-b")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0705); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0705); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2467,7 +2466,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte("**/subdir-b")
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2487,7 +2486,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/subdir-e", "!**/subdir-f"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2507,7 +2506,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/subdir-e", "!**/subdir-f"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2527,7 +2526,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/subdir-f", "!**/subdir-g"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
@ -2547,7 +2546,7 @@ var internalTestCases = []testCase{
|
||||
contextDir: "dockerignore/populated",
|
||||
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
|
||||
dockerignore := []byte(strings.Join([]string{"**/subdir-f", "!**/subdir-g"}, "\n"))
|
||||
if err := ioutil.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(contextDir, ".dockerignore"), dockerignore, 0750); err != nil {
|
||||
return fmt.Errorf("writing .dockerignore file: %w", err)
|
||||
}
|
||||
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@ -88,7 +87,7 @@ var _ = BeforeSuite(func() {
|
||||
|
||||
// CreateTempDirin
|
||||
func CreateTempDirInTempDir() (string, error) {
|
||||
return ioutil.TempDir("", "buildah_test")
|
||||
return os.MkdirTemp("", "buildah_test")
|
||||
}
|
||||
|
||||
// BuildahCreate a BuildAhTest instance for the tests
|
||||
|
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -49,7 +48,7 @@ func main() {
|
||||
BaseContext: func(l net.Listener) context.Context {
|
||||
if tcp, ok := l.Addr().(*net.TCPAddr); ok {
|
||||
if len(args) > 3 {
|
||||
f, err := ioutil.TempFile(filepath.Dir(args[3]), filepath.Base(args[3]))
|
||||
f, err := os.CreateTemp(filepath.Dir(args[3]), filepath.Base(args[3]))
|
||||
if err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@ -181,7 +180,7 @@ func getProcessAppArmorProfile(r *types.TestReport) error {
|
||||
|
||||
func getProcessOOMScoreAdjust(r *types.TestReport) error {
|
||||
node := "/proc/self/oom_score_adj"
|
||||
score, err := ioutil.ReadFile(node)
|
||||
score, err := os.ReadFile(node)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading %q: %w", node, err)
|
||||
}
|
||||
@ -313,7 +312,7 @@ func getLinuxSysctl(r *types.TestReport) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
value, err := ioutil.ReadFile(path)
|
||||
value, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if pe, ok := err.(*os.PathError); ok {
|
||||
if errno, ok := pe.Err.(syscall.Errno); ok {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -39,7 +38,7 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
d, err := ioutil.TempDir("", "")
|
||||
d, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user