Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated ioutil #15871

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/podman-mac-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -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])
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/containers/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containers
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/containers/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containers
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package containers
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package containers
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package containers
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/containers/common/pkg/cgroups"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/generate/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/images/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/images/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/images/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package images
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/podman/kube/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kube
import (
"fmt"
"io"
"io/ioutil"
"os"

"github.com/containers/common/pkg/completion"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/kube/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/manifest/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package manifest
import (
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/containers/common/pkg/auth"
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/parse/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package parse

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/pods/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"runtime"
"sort"
Expand Down Expand Up @@ -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)
}
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/rootlessport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading