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:
Chris Evich committed 2022-09-20 15:34:27 -04:00
1 parent 30231d0da7
commit d968f3fe09
126 files changed
+347 -452

No files matched your search

+1 -2
View File
@@ -5,7 +5,6 @@ package machine
import (
"errors"
"io/ioutil"
"net"
"net/url"
"os"
@@ -283,7 +282,7 @@ func (m *VMFile) Delete() error {
// Read the contents of a given file and return in []bytes
func (m *VMFile) Read() ([]byte, error) {
return ioutil.ReadFile(m.GetPath())
return os.ReadFile(m.GetPath())
}
// NewMachineFile is a constructor for VMFile
+2 -3
View File
@@ -1,7 +1,6 @@
package e2e_test
import (
"io/ioutil"
"os"
"strconv"
"time"
@@ -138,9 +137,9 @@ var _ = Describe("podman machine init", func() {
})
It("machine init with volume", func() {
tmpDir, err := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
Expect(err).To(BeNil())
_, err = ioutil.TempFile(tmpDir, "example")
_, err = os.CreateTemp(tmpDir, "example")
Expect(err).To(BeNil())
mount := tmpDir + ":/testmountdir"
defer os.RemoveAll(tmpDir)
+1 -2
View File
@@ -3,7 +3,6 @@ package e2e_test
import (
"fmt"
"io"
"io/ioutil"
url2 "net/url"
"os"
"path"
@@ -77,7 +76,7 @@ var _ = SynchronizedAfterSuite(func() {},
func setup() (string, *machineTestBuilder) {
// Set TMPDIR if this needs a new directory
homeDir, err := ioutil.TempDir("", "podman_test")
homeDir, err := os.MkdirTemp("", "podman_test")
if err != nil {
Fail(fmt.Sprintf("failed to create home directory: %q", err))
}
+2 -2
View File
@@ -6,7 +6,7 @@ package machine
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
url2 "net/url"
"os"
@@ -175,7 +175,7 @@ func GetFCOSDownload(imageStream string) (*FcosDownloadInfo, error) {
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io/fs"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@@ -227,7 +226,7 @@ WantedBy=sysinit.target
if err != nil {
return err
}
return ioutil.WriteFile(ign.WritePath, b, 0644)
return os.WriteFile(ign.WritePath, b, 0644)
}
func getDirs(usrName string) []Directory {
@@ -559,7 +558,7 @@ func getCerts(certsDir string, isDir bool) []File {
}
func prepareCertFile(path string, name string) (File, error) {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
logrus.Warnf("Unable to read cert file %v", err)
return File{}, err
+2 -3
View File
@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -27,7 +26,7 @@ func CreateSSHKeys(writeLocation string) (string, error) {
if err := generatekeys(writeLocation); err != nil {
return "", err
}
b, err := ioutil.ReadFile(writeLocation + ".pub")
b, err := os.ReadFile(writeLocation + ".pub")
if err != nil {
return "", err
}
@@ -45,7 +44,7 @@ func CreateSSHKeysPrefix(dir string, file string, passThru bool, skipExisting bo
} else {
fmt.Println("Keys already exist, reusing")
}
b, err := ioutil.ReadFile(filepath.Join(dir, file) + ".pub")
b, err := os.ReadFile(filepath.Join(dir, file) + ".pub")
if err != nil {
return "", err
}
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
url2 "net/url"
"os"
@@ -191,7 +190,7 @@ func Decompress(localPath, uncompressedPath string) error {
if err != nil {
return err
}
sourceFile, err := ioutil.ReadFile(localPath)
sourceFile, err := os.ReadFile(localPath)
if err != nil {
return err
}
+2 -2
View File
@@ -2,7 +2,7 @@ package qemu
import (
"fmt"
"io/ioutil"
"io"
"net"
"os"
"os/user"
@@ -43,7 +43,7 @@ func claimDockerSock() bool {
return false
}
_ = con.SetReadDeadline(time.Now().Add(time.Second * 5))
read, err := ioutil.ReadAll(con)
read, err := io.ReadAll(con)
return err == nil && string(read) == "OK"
}
+4 -5
View File
@@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"net"
"net/http"
"net/url"
@@ -391,11 +390,11 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) {
// If the user provides an ignition file, we need to
// copy it into the conf dir
if len(opts.IgnitionPath) > 0 {
inputIgnition, err := ioutil.ReadFile(opts.IgnitionPath)
inputIgnition, err := os.ReadFile(opts.IgnitionPath)
if err != nil {
return false, err
}
return false, ioutil.WriteFile(v.getIgnitionFile(), inputIgnition, 0644)
return false, os.WriteFile(v.getIgnitionFile(), inputIgnition, 0644)
}
// Write the ignition file
ign := machine.DynamicIgnition{
@@ -1109,7 +1108,7 @@ func getVMInfos() ([]*machine.ListResponse, error) {
vm := new(MachineVM)
if strings.HasSuffix(d.Name(), ".json") {
fullPath := filepath.Join(vmConfigDir, d.Name())
b, err := ioutil.ReadFile(fullPath)
b, err := os.ReadFile(fullPath)
if err != nil {
return err
}
@@ -1539,7 +1538,7 @@ func (v *MachineVM) writeConfig() error {
if err != nil {
return err
}
if err := ioutil.WriteFile(v.ConfigPath.GetPath(), b, 0644); err != nil {
if err := os.WriteFile(v.ConfigPath.GetPath(), b, 0644); err != nil {
return err
}
return nil
+2 -3
View File
@@ -10,7 +10,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/url"
"os"
"os/exec"
@@ -423,7 +422,7 @@ func (v *MachineVM) writeConfig() error {
if err != nil {
return err
}
if err := ioutil.WriteFile(jsonFile, b, 0644); err != nil {
if err := os.WriteFile(jsonFile, b, 0644); err != nil {
return fmt.Errorf("could not write machine json config: %w", err)
}
@@ -1285,7 +1284,7 @@ func readWinProxyTid(v *MachineVM) (uint32, uint32, string, error) {
}
tidFile := filepath.Join(stateDir, winSshProxyTid)
contents, err := ioutil.ReadFile(tidFile)
contents, err := os.ReadFile(tidFile)
if err != nil {
return 0, 0, "", err
}
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -209,7 +208,7 @@ func reboot() error {
return fmt.Errorf("could not create data directory: %w", err)
}
commFile := filepath.Join(dataDir, "podman-relaunch.dat")
if err := ioutil.WriteFile(commFile, []byte(encoded), 0600); err != nil {
if err := os.WriteFile(commFile, []byte(encoded), 0600); err != nil {
return fmt.Errorf("could not serialize command state: %w", err)
}