1
0
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:
Chris Evich
2022-11-14 11:22:45 -05:00
parent f1ef461a84
commit 46eea31588
32 changed files with 103 additions and 131 deletions

3
add.go
View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -115,7 +114,7 @@ func getURL(src string, chown *idtools.IDPair, mountpoint, renameTarget string,
if size < 0 { if size < 0 {
// Create a temporary file and copy the content to it, so that // Create a temporary file and copy the content to it, so that
// we can figure out how much content there is. // we can figure out how much content there is.
f, err := ioutil.TempFile(mountpoint, "download") f, err := os.CreateTemp(mountpoint, "download")
if err != nil { if err != nil {
return fmt.Errorf("creating temporary file to hold %q: %w", src, err) return fmt.Errorf("creating temporary file to hold %q: %w", src, err)
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -402,7 +401,7 @@ func OpenBuilder(store storage.Store, container string) (*Builder, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile)) buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -444,7 +443,7 @@ func OpenBuilderByPath(store storage.Store, path string) (*Builder, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile)) buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
logrus.Debugf("error reading %q: %v, ignoring container %q", filepath.Join(cdir, stateFile), err, container.ID) 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 { if err != nil {
return nil, err return nil, err
} }
buildstate, err := ioutil.ReadFile(filepath.Join(cdir, stateFile)) buildstate, err := os.ReadFile(filepath.Join(cdir, stateFile))
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
logrus.Debugf("%v, ignoring container %q", err, container.ID) logrus.Debugf("%v, ignoring container %q", err, container.ID)

View File

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
@ -690,7 +689,7 @@ func runUsingChrootExecMain() {
os.Exit(1) os.Exit(1)
} }
} else { } else {
setgroups, _ := ioutil.ReadFile("/proc/self/setgroups") setgroups, _ := os.ReadFile("/proc/self/setgroups")
if strings.Trim(string(setgroups), "\n") != "deny" { if strings.Trim(string(setgroups), "\n") != "deny" {
logrus.Debugf("clearing supplemental groups") logrus.Debugf("clearing supplemental groups")
if err = syscall.Setgroups([]int{}); err != nil { if err = syscall.Setgroups([]int{}); err != nil {

View File

@ -5,7 +5,7 @@ package chroot
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"github.com/containers/common/pkg/seccomp" "github.com/containers/common/pkg/seccomp"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
@ -187,7 +187,7 @@ func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
} }
spec.Linux.Seccomp = seccompConfig spec.Linux.Seccomp = seccompConfig
default: default:
seccompProfile, err := ioutil.ReadFile(seccompProfilePath) seccompProfile, err := os.ReadFile(seccompProfilePath)
if err != nil { if err != nil {
return fmt.Errorf("opening seccomp profile failed: %w", err) return fmt.Errorf("opening seccomp profile failed: %w", err)
} }

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strings" "strings"
"time" "time"
@ -166,7 +165,7 @@ func onBuild(builder *buildah.Builder, quiet bool) error {
case "RUN": case "RUN":
var stdout io.Writer var stdout io.Writer
if quiet { if quiet {
stdout = ioutil.Discard stdout = io.Discard
} }
if err := builder.Run(args, buildah.RunOptions{Stdout: stdout}); err != nil { if err := builder.Run(args, buildah.RunOptions{Stdout: stdout}); err != nil {
return err return err
@ -347,7 +346,7 @@ func fromCmd(c *cobra.Command, args []string, iopts fromReply) error {
if iopts.cidfile != "" { if iopts.cidfile != "" {
filePath := 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) return fmt.Errorf("failed to write container ID file %q: %w", filePath, err)
} }
} }

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -913,7 +912,7 @@ func manifestPush(systemContext *types.SystemContext, store storage.Store, listI
} }
if opts.digestfile != "" { 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)) return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", opts.digestfile, err))
} }
} }

View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"time" "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()) logrus.Debugf("Successfully pushed %s with digest %s", transports.ImageName(dest), digest.String())
if iopts.digestfile != "" { 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)) return util.GetFailureCause(err, fmt.Errorf("failed to write digest to file %q: %w", iopts.digestfile, err))
} }
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"strings" "strings"
"time" "time"
@ -392,7 +391,7 @@ func (b *Builder) Commit(ctx context.Context, dest types.ImageReference, options
dest = dest2 dest = dest2
} }
if options.IIDFile != "" { 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 return imgID, nil, "", err
} }
} }

View File

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
"io/ioutil"
"net" "net"
"os" "os"
"os/user" "os/user"
@ -573,7 +572,7 @@ func copierWithSubprocess(bulkReader io.Reader, bulkWriter io.Writer, req reques
bulkReader = bytes.NewReader([]byte{}) bulkReader = bytes.NewReader([]byte{})
} }
if bulkWriter == nil { if bulkWriter == nil {
bulkWriter = ioutil.Discard bulkWriter = io.Discard
} }
cmd := reexec.Command(copierCommand) cmd := reexec.Command(copierCommand)
stdinRead, stdinWrite, err := os.Pipe() stdinRead, stdinWrite, err := os.Pipe()

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -124,11 +123,11 @@ func testGetPermissionError(t *testing.T) {
require.NoError(t, err, "error creating a readable directory") require.NoError(t, err, "error creating a readable directory")
err = os.Mkdir(filepath.Join(tmp, "readable-directory", "unreadable-subdirectory"), 0000) err = os.Mkdir(filepath.Join(tmp, "readable-directory", "unreadable-subdirectory"), 0000)
require.NoError(t, err, "error creating an unreadable subdirectory") 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") 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") 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") require.NoError(t, err, "error creating an unreadable file in a readable directory")
for _, ignore := range []bool{false, true} { for _, ignore := range []bool{false, true} {
t.Run(fmt.Sprintf("ignore=%v", ignore), func(t *testing.T) { 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") 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) require.NoErrorf(t, err, "error writing file at %q", skipped)
var buf bytes.Buffer var buf bytes.Buffer

View File

@ -9,7 +9,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "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) { 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 // 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 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) { if err != nil && isExpectedError(err, topdir != "" && topdir != ".", testItem.Name, testArchive.expectedGetErrors) {
return 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) { 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 // 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) { if err != nil && isExpectedError(err, topdir != "" && topdir != ".", testCase.pattern, testArchive.expectedGetErrors) {
return return
} }

View File

@ -3,7 +3,6 @@ package copier
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"syscall" "syscall"
"testing" "testing"
@ -28,7 +27,7 @@ func TestXattrs(t *testing.T) {
tmp := t.TempDir() tmp := t.TempDir()
for attribute, value := range testValues { for attribute, value := range testValues {
t.Run(fmt.Sprintf("attribute=%s", attribute), func(t *testing.T) { 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) { if !assert.Nil(t, err, "error creating test file: %v", err) {
t.FailNow() t.FailNow()
} }

View File

@ -5,7 +5,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
urlpkg "net/url" urlpkg "net/url"
"os" "os"
@ -121,7 +121,7 @@ func TempDirForURL(dir, prefix, url string) (name string, subdir string, err err
url != "-" { url != "-" {
return "", "", nil return "", "", nil
} }
name, err = ioutil.TempDir(dir, prefix) name, err = os.MkdirTemp(dir, prefix)
if err != nil { if err != nil {
return "", "", fmt.Errorf("creating temporary directory for %q: %w", url, err) return "", "", fmt.Errorf("creating temporary directory for %q: %w", url, err)
} }
@ -255,7 +255,7 @@ func downloadToDirectory(url, dir string) error {
return err return err
} }
defer resp1.Body.Close() defer resp1.Body.Close()
body, err := ioutil.ReadAll(resp1.Body) body, err := io.ReadAll(resp1.Body)
if err != nil { if err != nil {
return err return err
} }
@ -271,7 +271,7 @@ func downloadToDirectory(url, dir string) error {
func stdinToDirectory(dir string) error { func stdinToDirectory(dir string) error {
logrus.Debugf("extracting stdin to %q", dir) logrus.Debugf("extracting stdin to %q", dir)
r := bufio.NewReader(os.Stdin) r := bufio.NewReader(os.Stdin)
b, err := ioutil.ReadAll(r) b, err := io.ReadAll(r)
if err != nil { if err != nil {
return fmt.Errorf("failed to read from stdin: %w", err) return fmt.Errorf("failed to read from stdin: %w", err)
} }

View File

@ -4,7 +4,6 @@ import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"io" "io"
"io/ioutil"
"strings" "strings"
"sync" "sync"
"testing" "testing"
@ -167,7 +166,7 @@ func TestCompositeDigester(t *testing.T) {
// the filter should have left modtime to "roughly now" // the filter should have left modtime to "roughly now"
require.NotEqual(t, zero, hdr.ModTime, "timestamp for entry should not have been zero") 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.Nil(t, err, "error reading tar content from buffer: %v", err)
require.Equal(t, hdr.Size, n, "short read reading tar content") require.Equal(t, hdr.Size, n, "short read reading tar content")
hdr, err = tr.Next() hdr, err = tr.Next()

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -309,7 +308,7 @@ func (i *containerImageRef) NewImageSource(ctx context.Context, sc *types.System
logrus.Debugf("layer list: %q", layers) logrus.Debugf("layer list: %q", layers)
// Make a temporary directory to hold blobs. // 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 { if err != nil {
return nil, fmt.Errorf("creating temporary directory to hold layer blobs: %w", err) return nil, fmt.Errorf("creating temporary directory to hold layer blobs: %w", err)
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -153,7 +152,7 @@ func BuildDockerfiles(ctx context.Context, store storage.Store, options define.B
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
data = ioutil.NopCloser(pData) data = io.NopCloser(pData)
} }
dockerfiles = append(dockerfiles, data) dockerfiles = append(dockerfiles, data)

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"sort" "sort"
"strconv" "strconv"
@ -200,7 +199,7 @@ func newExecutor(logger *logrus.Logger, logPrefix string, store storage.Store, o
writer := options.ReportWriter writer := options.ReportWriter
if options.Quiet { if options.Quiet {
writer = ioutil.Discard writer = io.Discard
} }
var rusageLogFile io.Writer var rusageLogFile io.Writer
@ -589,7 +588,7 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
stdout := b.out stdout := b.out
if b.quiet { if b.quiet {
b.out = ioutil.Discard b.out = io.Discard
} }
cleanup := func() error { 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) logrus.Debugf("printing final image id %q", imageID)
if b.iidfile != "" { 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) return imageID, ref, fmt.Errorf("failed to write image ID to file %q: %w", b.iidfile, err)
} }
} else { } else {

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -116,7 +115,7 @@ func updateIndexWithNewManifestDescriptor(manifest *specV1.Descriptor, sourcePat
index := specV1.Index{} index := specV1.Index{}
indexPath := filepath.Join(sourcePath, "index.json") indexPath := filepath.Join(sourcePath, "index.json")
rawData, err := ioutil.ReadFile(indexPath) rawData, err := os.ReadFile(indexPath)
if err != nil { if err != nil {
return err return err
} }
@ -130,5 +129,5 @@ func updateIndexWithNewManifestDescriptor(manifest *specV1.Descriptor, sourcePat
return err return err
} }
return ioutil.WriteFile(indexPath, rawData, 0644) return os.WriteFile(indexPath, rawData, 0644)
} }

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -423,7 +422,7 @@ func GenBuildOptions(c *cobra.Command, inputArgs []string, iopts BuildOptions) (
UnsetEnvs: iopts.UnsetEnvs, UnsetEnvs: iopts.UnsetEnvs,
} }
if iopts.Quiet { if iopts.Quiet {
options.ReportWriter = ioutil.Discard options.ReportWriter = io.Discard
} }
return options, containerfiles, removeAll, nil return options, containerfiles, removeAll, nil
} }

View File

@ -2,7 +2,6 @@ package overlay
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "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) 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 { if err != nil {
return "", fmt.Errorf("failed to create the overlay tmpdir in %s directory: %w", contentDir, err) 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) { func CleanupContent(containerDir string) (Err error) {
contentDir := filepath.Join(containerDir, "overlay") contentDir := filepath.Join(containerDir, "overlay")
files, err := ioutil.ReadDir(contentDir) files, err := os.ReadDir(contentDir)
if err != nil { if err != nil {
if errors.Is(err, os.ErrNotExist) { if errors.Is(err, os.ErrNotExist) {
return nil return nil

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -80,7 +79,7 @@ func (a *AgentServer) Serve(processLabel string) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
serveDir, err := ioutil.TempDir("", ".buildah-ssh-sock") serveDir, err := os.MkdirTemp("", ".buildah-ssh-sock")
if err != nil { if err != nil {
return "", err return "", err
} }
@ -223,7 +222,7 @@ func NewSource(paths []string) (*Source, error) {
if err != nil { if err != nil {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,12 +3,12 @@ package util
import ( import (
"bytes" "bytes"
"errors" "errors"
"io/ioutil"
"time" "time"
"os"
) )
func ReadUptime() (time.Duration, error) { func ReadUptime() (time.Duration, error) {
buf, err := ioutil.ReadFile("/proc/uptime") buf, err := os.ReadFile("/proc/uptime")
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -2,7 +2,6 @@ package util
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -21,12 +20,12 @@ func MirrorToTempFileIfPathIsDescriptor(file string) (string, bool) {
if !strings.HasPrefix(file, "/dev/fd") { if !strings.HasPrefix(file, "/dev/fd") {
return file, false return file, false
} }
b, err := ioutil.ReadFile(file) b, err := os.ReadFile(file)
if err != nil { if err != nil {
// if anything goes wrong return original path // if anything goes wrong return original path
return file, false return file, false
} }
tmpfile, err := ioutil.TempFile(os.TempDir(), "buildah-temp-file") tmpfile, err := os.CreateTemp(os.TempDir(), "buildah-temp-file")
if err != nil { if err != nil {
return file, false return file, false
} }

View File

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"os" "os"
"os/exec" "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. // 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 { if err != nil {
return 1, err 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) logrus.Errorf("did not get container create message from subprocess: %v", err)
} else { } else {
pidFile := filepath.Join(bundlePath, "pid") pidFile := filepath.Join(bundlePath, "pid")
pidValue, err := ioutil.ReadFile(pidFile) pidValue, err := os.ReadFile(pidFile)
if err != nil { if err != nil {
return err return err
} }
@ -1655,7 +1654,7 @@ func (b *Builder) getSecretMount(tokens []string, secrets map[string]define.Secr
switch secr.SourceType { switch secr.SourceType {
case "env": case "env":
data = []byte(os.Getenv(secr.Source)) data = []byte(os.Getenv(secr.Source))
tmpFile, err := ioutil.TempFile(define.TempDir, "buildah*") tmpFile, err := os.CreateTemp(define.TempDir, "buildah*")
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
@ -1666,7 +1665,7 @@ func (b *Builder) getSecretMount(tokens []string, secrets map[string]define.Secr
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
data, err = ioutil.ReadFile(secr.Source) data, err = os.ReadFile(secr.Source)
if err != nil { if err != nil {
return nil, "", err 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 { if err := os.MkdirAll(filepath.Dir(ctrFileOnHost), 0755); err != nil {
return nil, "", err return nil, "", err
} }
if err := ioutil.WriteFile(ctrFileOnHost, data, 0644); err != nil { if err := os.WriteFile(ctrFileOnHost, data, 0644); err != nil {
return nil, "", err return nil, "", err
} }

View File

@ -6,7 +6,6 @@ package buildah
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -72,7 +71,7 @@ func setChildProcess() error {
} }
func (b *Builder) Run(command []string, options RunOptions) error { func (b *Builder) Run(command []string, options RunOptions) error {
p, err := ioutil.TempDir("", Package) p, err := os.MkdirTemp("", Package)
if err != nil { if err != nil {
return err return err
} }

View File

@ -7,7 +7,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -70,7 +69,7 @@ func setChildProcess() error {
// Run runs the specified command in the container's root filesystem. // Run runs the specified command in the container's root filesystem.
func (b *Builder) Run(command []string, options RunOptions) error { func (b *Builder) Run(command []string, options RunOptions) error {
p, err := ioutil.TempDir("", define.Package) p, err := os.MkdirTemp("", define.Package)
if err != nil { if err != nil {
return err return err
} }
@ -480,7 +479,7 @@ func setupRootlessNetwork(pid int) (teardown func(), err error) {
defer rootlessSlirpSyncR.Close() defer rootlessSlirpSyncR.Close()
// Be sure there are no fds inherited to slirp4netns except the sync pipe // 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 { if err != nil {
return nil, fmt.Errorf("cannot list open fds: %w", err) return nil, fmt.Errorf("cannot list open fds: %w", err)
} }

View File

@ -5,7 +5,7 @@ package buildah
import ( import (
"fmt" "fmt"
"io/ioutil" "os"
"github.com/containers/common/pkg/seccomp" "github.com/containers/common/pkg/seccomp"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
@ -22,7 +22,7 @@ func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error {
} }
spec.Linux.Seccomp = seccompConfig spec.Linux.Seccomp = seccompConfig
default: default:
seccompProfile, err := ioutil.ReadFile(seccompProfilePath) seccompProfile, err := os.ReadFile(seccompProfilePath)
if err != nil { if err != nil {
return fmt.Errorf("opening seccomp profile failed: %w", err) return fmt.Errorf("opening seccomp profile failed: %w", err)
} }

View File

@ -9,7 +9,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "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) require.Nil(t, err, "error creating test directory to check if xattrs are testable: %v", err)
} }
testFile := filepath.Join(testDir, "testfile") 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) require.Nil(t, err, "error creating test file to check if xattrs are testable: %v", err)
} }
can := false can := false
@ -232,7 +231,7 @@ func testConformanceInternal(t *testing.T, dateStamp string, testIndex int) {
dockerfileContents := []byte(test.dockerfileContents) dockerfileContents := []byte(test.dockerfileContents)
if len(dockerfileContents) == 0 { if len(dockerfileContents) == 0 {
// no inlined contents -> read them from the specified location // 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)) require.Nil(t, err, "error reading Dockerfile %q", filepath.Join(tempdir, dockerfileName))
dockerfileContents = contents 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) require.Nil(t, err, "error mounting test layer to check if xattrs are testable: %v", err)
} }
testFile := filepath.Join(mountPoint, "testfile") 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) require.Nil(t, err, "error creating file in test layer to check if xattrs are testable: %v", err)
} }
can := false 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 // 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 // original file, or inlined information, in which case the file didn't
// necessarily exist // necessarily exist
err := ioutil.WriteFile(dockerfileName, dockerfileContents, 0644) err := os.WriteFile(dockerfileName, dockerfileContents, 0644)
require.Nil(t, err, "error writing Dockerfile at %q", dockerfileName) require.Nil(t, err, "error writing Dockerfile at %q", dockerfileName)
err = os.Chtimes(dockerfileName, testDate, testDate) err = os.Chtimes(dockerfileName, testDate, testDate)
require.Nil(t, err, "error resetting timestamp on Dockerfile at %q", dockerfileName) 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)")...) dockerfileContents = append(dockerfileContents, []byte("\n(no final end-of-line)")...)
} }
t.Logf("Dockerfile contents:\n%s", dockerfileContents) 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)) 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) err := os.MkdirAll(directory, 0755)
require.Nil(t, err, "error ensuring directory %q exists for storing a report") require.Nil(t, err, "error ensuring directory %q exists for storing a report")
// save the Dockerfile that was used to generate the image // 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) require.Nil(t, err, "error saving Dockerfile for image %q", imageName)
// save the log generated while building the image // 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) require.Nil(t, err, "error saving build log for image %q", imageName)
// save the version information // save the version information
if len(version) > 0 { 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) require.Nil(t, err, "error saving builder version information for image %q", imageName)
} }
// open the image for reading // 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) encodedConfig, err := json.Marshal(ociConfig)
require.Nil(t, err, "error encoding OCI-format configuration from image %q for saving", imageName) require.Nil(t, err, "error encoding OCI-format configuration from image %q for saving", imageName)
// save the config blob in the OCI format // 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) require.Nil(t, err, "error saving OCI-format configuration from image %q", imageName)
// save the config blob in its original format // 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) require.Nil(t, err, "error saving original configuration from image %q", imageName)
// start pulling layer information // start pulling layer information
layerBlobInfos, err := img.LayerInfosForCopy(ctx) 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 // there's no point in saving them for comparison later
encodedFSTree, err := json.Marshal(fstree.Tree) encodedFSTree, err := json.Marshal(fstree.Tree)
require.Nil(t, err, "error encoding filesystem tree from image %q for saving", imageName) 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) 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 // read information about the specified image from the specified directory
func readReport(t *testing.T, directory string) (original, oci, fs map[string]interface{}) { func readReport(t *testing.T, directory string) (original, oci, fs map[string]interface{}) {
// read the config in the as-committed (docker) format // 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")) require.Nil(t, err, "error reading configuration file %q", filepath.Join(directory, "config.json"))
// dump it into a map // dump it into a map
original = make(map[string]interface{}) original = make(map[string]interface{})
err = json.Unmarshal(originalConfig, &original) err = json.Unmarshal(originalConfig, &original)
require.Nil(t, err, "error decoding configuration from file %q", filepath.Join(directory, "config.json")) require.Nil(t, err, "error decoding configuration from file %q", filepath.Join(directory, "config.json"))
// read the config in converted-to-OCI format // 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")) require.Nil(t, err, "error reading OCI configuration file %q", filepath.Join(directory, "oci.json"))
// dump it into a map // dump it into a map
oci = make(map[string]interface{}) oci = make(map[string]interface{})
err = json.Unmarshal(ociConfig, &oci) err = json.Unmarshal(ociConfig, &oci)
require.Nil(t, err, "error decoding OCI configuration from file %q", filepath.Join(directory, "oci.json")) require.Nil(t, err, "error decoding OCI configuration from file %q", filepath.Join(directory, "oci.json"))
// read the filesystem // 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")) require.Nil(t, err, "error reading filesystem summary file %q", filepath.Join(directory, "fs.json"))
// dump it into a map for comparison // dump it into a map for comparison
fs = make(map[string]interface{}) fs = make(map[string]interface{})
@ -1542,7 +1541,7 @@ var internalTestCases = []testCase{
return fmt.Errorf("creating subdirectory of temporary context directory: %w", err) return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
} }
filename := filepath.Join(contextDir, "archive", "should-be-owned-by-root") 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) return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 0, 0); err != nil { 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) 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") 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) return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 99, 99); err != nil { 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) return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
} }
filename := filepath.Join(contextDir, "subdir", "would-be-owned-by-root") 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) return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 0, 0); err != nil { 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) 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") 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) return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 99, 99); err != nil { 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) return fmt.Errorf("creating subdirectory of temporary context directory: %w", err)
} }
filename := filepath.Join(contextDir, "subdir", "would-be-owned-by-root") 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) return fmt.Errorf("creating file owned by root in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 0, 0); err != nil { 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) 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") 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) return fmt.Errorf("creating file owned by 99 in temporary context directory: %w", err)
} }
if err = os.Chown(filename, 99, 99); err != nil { if err = os.Chown(filename, 99, 99); err != nil {
@ -1724,7 +1723,7 @@ var internalTestCases = []testCase{
}, "\n"), }, "\n"),
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
filename := filepath.Join(contextDir, "should-be-setuid-file") 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) return fmt.Errorf("creating setuid test file in temporary context directory: %w", err)
} }
if err = syscall.Chmod(filename, syscall.S_ISUID|0755); err != nil { 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) return fmt.Errorf("setting date on setuid test file in temporary context directory: %w", err)
} }
filename = filepath.Join(contextDir, "should-be-setgid-file") 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) return fmt.Errorf("creating setgid test file in temporary context directory: %w", err)
} }
if err = syscall.Chmod(filename, syscall.S_ISGID|0755); err != nil { 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) return fmt.Errorf("setting date on setgid test file in temporary context directory: %w", err)
} }
filename = filepath.Join(contextDir, "should-be-sticky-file") 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) return fmt.Errorf("creating sticky test file in temporary context directory: %w", err)
} }
if err = syscall.Chmod(filename, syscall.S_ISVTX|0755); err != nil { 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) 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") 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) 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 { if err = syscall.Chmod(filename, 0640); err != nil {
@ -1785,7 +1784,7 @@ var internalTestCases = []testCase{
} }
filename := filepath.Join(contextDir, "xattrs-file") 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) 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 { 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") 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) 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 { if err = copier.Lsetxattrs(filename, map[string]string{"user.a": "test"}); err != nil {
@ -2147,7 +2146,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/empty", contextDir: "dockerignore/empty",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2167,7 +2166,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2187,7 +2186,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/*-a", "!**/*-c"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2207,7 +2206,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"!**/*-c"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2227,7 +2226,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("!**/*-c\n") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2247,7 +2246,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("subdir-c") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2267,7 +2266,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("subdir-c") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2287,7 +2286,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-c") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2307,7 +2306,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-c") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2327,7 +2326,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("subdir-*") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2347,7 +2346,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("subdir-*") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2367,7 +2366,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-*") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2387,7 +2386,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-*") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2407,7 +2406,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-f") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2427,7 +2426,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-f") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2447,7 +2446,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-b") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2467,7 +2466,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte("**/subdir-b") 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2487,7 +2486,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/subdir-e", "!**/subdir-f"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2507,7 +2506,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/subdir-e", "!**/subdir-f"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2527,7 +2526,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/subdir-f", "!**/subdir-g"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {
@ -2547,7 +2546,7 @@ var internalTestCases = []testCase{
contextDir: "dockerignore/populated", contextDir: "dockerignore/populated",
tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) { tweakContextDir: func(t *testing.T, contextDir, storageDriver, storageRoot string) (err error) {
dockerignore := []byte(strings.Join([]string{"**/subdir-f", "!**/subdir-g"}, "\n")) 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) return fmt.Errorf("writing .dockerignore file: %w", err)
} }
if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil { if err = os.Chtimes(filepath.Join(contextDir, ".dockerignore"), testDate, testDate); err != nil {

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -88,7 +87,7 @@ var _ = BeforeSuite(func() {
// CreateTempDirin // CreateTempDirin
func CreateTempDirInTempDir() (string, error) { func CreateTempDirInTempDir() (string, error) {
return ioutil.TempDir("", "buildah_test") return os.MkdirTemp("", "buildah_test")
} }
// BuildahCreate a BuildAhTest instance for the tests // BuildahCreate a BuildAhTest instance for the tests

View File

@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"errors" "errors"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
@ -49,7 +48,7 @@ func main() {
BaseContext: func(l net.Listener) context.Context { BaseContext: func(l net.Listener) context.Context {
if tcp, ok := l.Addr().(*net.TCPAddr); ok { if tcp, ok := l.Addr().(*net.TCPAddr); ok {
if len(args) > 3 { 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 { if err != nil {
log.Fatalf("%v", err) log.Fatalf("%v", err)
} }

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -181,7 +180,7 @@ func getProcessAppArmorProfile(r *types.TestReport) error {
func getProcessOOMScoreAdjust(r *types.TestReport) error { func getProcessOOMScoreAdjust(r *types.TestReport) error {
node := "/proc/self/oom_score_adj" node := "/proc/self/oom_score_adj"
score, err := ioutil.ReadFile(node) score, err := os.ReadFile(node)
if err != nil { if err != nil {
return fmt.Errorf("reading %q: %w", node, err) return fmt.Errorf("reading %q: %w", node, err)
} }
@ -313,7 +312,7 @@ func getLinuxSysctl(r *types.TestReport) error {
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
value, err := ioutil.ReadFile(path) value, err := os.ReadFile(path)
if err != nil { if err != nil {
if pe, ok := err.(*os.PathError); ok { if pe, ok := err.(*os.PathError); ok {
if errno, ok := pe.Err.(syscall.Errno); ok { if errno, ok := pe.Err.(syscall.Errno); ok {

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -39,7 +38,7 @@ func main() {
} }
}() }()
d, err := ioutil.TempDir("", "") d, err := os.MkdirTemp("", "")
if err != nil { if err != nil {
panic(err) panic(err)
} }