mirror of
https://github.com/containers/podman.git
synced 2026-03-06 07:52:56 -05: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:
@@ -2,7 +2,6 @@ package compat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
@@ -19,7 +18,7 @@ func ExportContainer(w http.ResponseWriter, r *http.Request) {
|
||||
utils.ContainerNotFound(w, name, err)
|
||||
return
|
||||
}
|
||||
tmpfile, err := ioutil.TempFile("", "api.tar")
|
||||
tmpfile, err := os.CreateTemp("", "api.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -49,7 +48,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
|
||||
// 500 server
|
||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "api.tar")
|
||||
tmpfile, err := os.CreateTemp("", "api.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
@@ -193,7 +192,7 @@ func CreateImageFromSrc(w http.ResponseWriter, r *http.Request) {
|
||||
// fromSrc – Source to import. The value may be a URL from which the image can be retrieved or - to read the image from the request body. This parameter may only be used when importing an image.
|
||||
source := query.FromSrc
|
||||
if source == "-" {
|
||||
f, err := ioutil.TempFile("", "api_load.tar")
|
||||
f, err := os.CreateTemp("", "api_load.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to create tempfile: %w", err))
|
||||
return
|
||||
@@ -480,7 +479,7 @@ func LoadImages(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// First write the body to a temporary file that we can later attempt
|
||||
// to load.
|
||||
f, err := ioutil.TempFile("", "api_load.tar")
|
||||
f, err := os.CreateTemp("", "api_load.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("failed to create tempfile: %w", err))
|
||||
return
|
||||
@@ -547,7 +546,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
|
||||
images[i] = possiblyNormalizedName
|
||||
}
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "api.tar")
|
||||
tmpfile, err := os.CreateTemp("", "api.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -182,7 +181,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||
dockerFileSet := false
|
||||
if utils.IsLibpodRequest(r) && query.Remote != "" {
|
||||
// The context directory could be a URL. Try to handle that.
|
||||
anchorDir, err := ioutil.TempDir(parse.GetTempDir(), "libpod_builder")
|
||||
anchorDir, err := os.MkdirTemp(parse.GetTempDir(), "libpod_builder")
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
}
|
||||
@@ -730,7 +729,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
|
||||
if logrus.IsLevelEnabled(logrus.DebugLevel) {
|
||||
if v, found := os.LookupEnv("PODMAN_RETAIN_BUILD_ARTIFACT"); found {
|
||||
if keep, _ := strconv.ParseBool(v); keep {
|
||||
t, _ := ioutil.TempFile("", "build_*_server")
|
||||
t, _ := os.CreateTemp("", "build_*_server")
|
||||
defer t.Close()
|
||||
body = io.MultiWriter(t, w)
|
||||
}
|
||||
@@ -852,7 +851,7 @@ func parseLibPodIsolation(isolation string) (buildah.Isolation, error) {
|
||||
|
||||
func extractTarFile(r *http.Request) (string, error) {
|
||||
// build a home for the request body
|
||||
anchorDir, err := ioutil.TempDir("", "libpod_builder")
|
||||
anchorDir, err := os.MkdirTemp("", "libpod_builder")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/image/v5/types"
|
||||
@@ -26,7 +27,7 @@ func PushImage(w http.ResponseWriter, r *http.Request) {
|
||||
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
|
||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||
|
||||
digestFile, err := ioutil.TempFile("", "digest.txt")
|
||||
digestFile, err := os.CreateTemp("", "digest.txt")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
@@ -186,7 +187,7 @@ loop: // break out of for/select infinite loop
|
||||
break loop
|
||||
}
|
||||
|
||||
digestBytes, err := ioutil.ReadAll(digestFile)
|
||||
digestBytes, err := io.ReadAll(digestFile)
|
||||
if err != nil {
|
||||
report.Error = &jsonmessage.JSONError{
|
||||
Message: err.Error(),
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -248,7 +247,7 @@ func Checkpoint(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if query.Export {
|
||||
f, err := ioutil.TempFile("", "checkpoint")
|
||||
f, err := os.CreateTemp("", "checkpoint")
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
@@ -329,7 +328,7 @@ func Restore(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var names []string
|
||||
if query.Import {
|
||||
t, err := ioutil.TempFile("", "restore")
|
||||
t, err := os.CreateTemp("", "restore")
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -182,7 +181,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch query.Format {
|
||||
case define.OCIArchive, define.V2s2Archive:
|
||||
tmpfile, err := ioutil.TempFile("", "api.tar")
|
||||
tmpfile, err := os.CreateTemp("", "api.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
@@ -193,7 +192,7 @@ func ExportImage(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
case define.OCIManifestDir, define.V2s2ManifestDir:
|
||||
tmpdir, err := ioutil.TempDir("", "save")
|
||||
tmpdir, err := os.MkdirTemp("", "save")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempdir: %w", err))
|
||||
return
|
||||
@@ -279,7 +278,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch query.Format {
|
||||
case define.V2s2Archive, define.OCIArchive:
|
||||
tmpfile, err := ioutil.TempFile("", "api.tar")
|
||||
tmpfile, err := os.CreateTemp("", "api.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
@@ -290,7 +289,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
case define.OCIManifestDir, define.V2s2ManifestDir:
|
||||
tmpdir, err := ioutil.TempDir("", "save")
|
||||
tmpdir, err := os.MkdirTemp("", "save")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tmpdir: %w", err))
|
||||
return
|
||||
@@ -329,7 +328,7 @@ func ExportImages(w http.ResponseWriter, r *http.Request) {
|
||||
func ImagesLoad(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
|
||||
|
||||
tmpfile, err := ioutil.TempFile("", "libpod-images-load.tar")
|
||||
tmpfile, err := os.CreateTemp("", "libpod-images-load.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
@@ -378,7 +377,7 @@ func ImagesImport(w http.ResponseWriter, r *http.Request) {
|
||||
// Check if we need to load the image from a URL or from the request's body.
|
||||
source := query.URL
|
||||
if len(query.URL) == 0 {
|
||||
tmpfile, err := ioutil.TempFile("", "libpod-images-import.tar")
|
||||
tmpfile, err := os.CreateTemp("", "libpod-images-import.tar")
|
||||
if err != nil {
|
||||
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("unable to create tempfile: %w", err))
|
||||
return
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -83,7 +83,7 @@ func ManifestCreate(w http.ResponseWriter, r *http.Request) {
|
||||
status = http.StatusCreated
|
||||
}
|
||||
|
||||
buffer, err := ioutil.ReadAll(r.Body)
|
||||
buffer, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
|
||||
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -41,7 +40,7 @@ func loggingHandler() mux.MiddlewareFunc {
|
||||
"API": "request",
|
||||
"X-Reference-Id": r.Header.Get("X-Reference-Id"),
|
||||
})
|
||||
r.Body = ioutil.NopCloser(
|
||||
r.Body = io.NopCloser(
|
||||
io.TeeReader(r.Body, annotated.WriterLevel(logrus.TraceLevel)))
|
||||
|
||||
w = responseWriter{ResponseWriter: w}
|
||||
|
||||
@@ -2,7 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/containers/podman/v4/pkg/api/types"
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
func referenceIDHandler() mux.MiddlewareFunc {
|
||||
return func(h http.Handler) http.Handler {
|
||||
// Only log Apache access_log-like entries at Info level or below
|
||||
out := ioutil.Discard
|
||||
out := io.Discard
|
||||
if logrus.IsLevelEnabled(logrus.InfoLevel) {
|
||||
out = logrus.StandardLogger().Out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user