mirror of
https://github.com/containers/podman.git
synced 2026-03-18 06:38:49 -04:00
Replace deprecated ioutil
Package `io/ioutil` was deprecated in golang 1.16, preventing podman from building under Fedora 37. Fortunately, functionality identical replacements are provided by the packages `io` and `os`. Replace all usage of all `io/ioutil` symbols with appropriate substitutions according to the golang docs. Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
@@ -131,7 +130,7 @@ func readCapped(reader io.Reader) string {
|
||||
// Cap output
|
||||
buffer := make([]byte, 2048)
|
||||
n, _ := io.ReadFull(reader, buffer)
|
||||
_, _ = io.Copy(ioutil.Discard, reader)
|
||||
_, _ = io.Copy(io.Discard, reader)
|
||||
if n > 0 {
|
||||
return string(buffer[:n])
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package containers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -107,7 +106,7 @@ func commit(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
if len(iidFile) > 0 {
|
||||
if err = ioutil.WriteFile(iidFile, []byte(response.Id), 0644); err != nil {
|
||||
if err = os.WriteFile(iidFile, []byte(response.Id), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write image ID: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package containers
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
@@ -379,7 +378,7 @@ func copyToContainer(container string, containerPath string, hostPath string) er
|
||||
// Copy from stdin to a temporary file *before* throwing it
|
||||
// over the wire. This allows for proper client-side error
|
||||
// reporting.
|
||||
tmpFile, err := ioutil.TempFile("", "")
|
||||
tmpFile, err := os.CreateTemp("", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -96,7 +96,7 @@ func kill(_ *cobra.Command, args []string) error {
|
||||
return errors.New("valid signals are 1 through 64")
|
||||
}
|
||||
for _, cidFile := range killCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package containers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -92,7 +92,7 @@ func pause(cmd *cobra.Command, args []string) error {
|
||||
)
|
||||
|
||||
for _, cidFile := range pauseCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package containers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -105,7 +105,7 @@ func restart(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
for _, cidFile := range restartCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -108,7 +108,7 @@ func rm(cmd *cobra.Command, args []string) error {
|
||||
rmOptions.Timeout = &stopTimeout
|
||||
}
|
||||
for _, cidFile := range rmCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package containers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -105,7 +105,7 @@ func stop(cmd *cobra.Command, args []string) error {
|
||||
stopOptions.Timeout = &stopTimeout
|
||||
}
|
||||
for _, cidFile := range stopCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
@@ -99,7 +99,7 @@ func unpause(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
for _, cidFile := range unpauseCidFiles {
|
||||
content, err := ioutil.ReadFile(cidFile)
|
||||
content, err := os.ReadFile(cidFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading CIDFile: %w", err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package generate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v4/cmd/podman/common"
|
||||
@@ -59,7 +59,7 @@ func spec(cmd *cobra.Command, args []string) error {
|
||||
// if we are looking to print the output, do not mess it up by printing the path
|
||||
// if we are using -v the user probably expects to pipe the output somewhere else
|
||||
if len(opts.FileName) > 0 {
|
||||
err = ioutil.WriteFile(opts.FileName, report.Data, 0644)
|
||||
err = os.WriteFile(opts.FileName, report.Data, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -635,7 +634,7 @@ func getDecryptConfig(decryptionKeys []string) (*encconfig.DecryptConfig, error)
|
||||
|
||||
func parseDockerignore(ignoreFile string) ([]string, error) {
|
||||
excludes := []string{}
|
||||
ignore, err := ioutil.ReadFile(ignoreFile)
|
||||
ignore, err := os.ReadFile(ignoreFile)
|
||||
if err != nil {
|
||||
return excludes, err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -116,7 +115,7 @@ func importCon(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if source == "-" {
|
||||
outFile, err := ioutil.TempFile("", "podman")
|
||||
outFile, err := os.CreateTemp("", "podman")
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating file %v", err)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -93,7 +92,7 @@ func load(cmd *cobra.Command, args []string) error {
|
||||
if term.IsTerminal(int(os.Stdin.Fd())) {
|
||||
return errors.New("cannot read from terminal, use command-line redirection or the --input flag")
|
||||
}
|
||||
outFile, err := ioutil.TempFile(util.Tmpdir(), "podman")
|
||||
outFile, err := os.CreateTemp(util.Tmpdir(), "podman")
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating file %v", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package images
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -16,7 +15,7 @@ import (
|
||||
// the caller should use the returned function to clean up the pipeDir
|
||||
func setupPipe() (string, func() <-chan error, error) {
|
||||
errc := make(chan error)
|
||||
pipeDir, err := ioutil.TempDir(os.TempDir(), "pipeDir")
|
||||
pipeDir, err := os.MkdirTemp(os.TempDir(), "pipeDir")
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package kube
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/completion"
|
||||
@@ -77,7 +76,7 @@ func generateKube(cmd *cobra.Command, args []string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
content, err := ioutil.ReadAll(report.Reader)
|
||||
content, err := io.ReadAll(report.Reader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -89,7 +88,7 @@ func generateKube(cmd *cobra.Command, args []string) error {
|
||||
if _, err := os.Stat(generateFile); err == nil {
|
||||
return fmt.Errorf("cannot write to %q; file exists", generateFile)
|
||||
}
|
||||
if err := ioutil.WriteFile(generateFile, content, 0644); err != nil {
|
||||
if err := os.WriteFile(generateFile, content, 0644); err != nil {
|
||||
return fmt.Errorf("cannot write to %q: %w", generateFile, err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -284,7 +283,7 @@ func readerFromArg(fileName string) (*bytes.Reader, error) {
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package manifest
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
@@ -149,7 +148,7 @@ func push(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
if manifestPushOpts.DigestFile != "" {
|
||||
if err := ioutil.WriteFile(manifestPushOpts.DigestFile, []byte(digest), 0644); err != nil {
|
||||
if err := os.WriteFile(manifestPushOpts.DigestFile, []byte(digest), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package parse
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -15,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
func createTmpFile(content []byte) (string, error) {
|
||||
tmpfile, err := ioutil.TempFile(os.TempDir(), "unittest")
|
||||
tmpfile, err := os.CreateTemp(os.TempDir(), "unittest")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
@@ -300,7 +299,7 @@ func create(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if len(podIDFile) > 0 {
|
||||
if err = ioutil.WriteFile(podIDFile, []byte(response.Id), 0644); err != nil {
|
||||
if err = os.WriteFile(podIDFile, []byte(response.Id), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write pod ID to file: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -50,7 +49,7 @@ func main() {
|
||||
}
|
||||
|
||||
func loadConfig(r io.Reader) (*rootlessport.Config, io.ReadCloser, io.WriteCloser, error) {
|
||||
stdin, err := ioutil.ReadAll(r)
|
||||
stdin, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
@@ -92,7 +91,7 @@ func parent() error {
|
||||
}
|
||||
|
||||
// create the parent driver
|
||||
stateDir, err := ioutil.TempDir(cfg.TmpDir, "rootlessport")
|
||||
stateDir, err := os.MkdirTemp(cfg.TmpDir, "rootlessport")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -240,7 +239,7 @@ outer:
|
||||
|
||||
// wait for ExitFD to be closed
|
||||
logrus.Info("Waiting for exitfd to be closed")
|
||||
if _, err := ioutil.ReadAll(exitR); err != nil {
|
||||
if _, err := io.ReadAll(exitR); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -357,7 +356,7 @@ func child() error {
|
||||
}()
|
||||
|
||||
// wait for stdin to be closed
|
||||
if _, err := ioutil.ReadAll(os.Stdin); err != nil {
|
||||
if _, err := io.ReadAll(os.Stdin); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user