summaryrefslogtreecommitdiff
path: root/pkg/machine
diff options
context:
space:
mode:
authorChris Evich <cevich@redhat.com>2022-09-20 09:59:28 -0400
committerChris Evich <cevich@redhat.com>2022-09-20 15:34:27 -0400
commitd968f3fe09a4c7d74464cfe2eaa9e4febbe61ba5 (patch)
treeedc3b78d1565b5df8074c0cf47c1d1cf1126a97a /pkg/machine
parent30231d0da7e6dcf3d6d1f45b10150baae35aaf28 (diff)
downloadpodman-d968f3fe09a4c7d74464cfe2eaa9e4febbe61ba5.tar.gz
podman-d968f3fe09a4c7d74464cfe2eaa9e4febbe61ba5.tar.bz2
podman-d968f3fe09a4c7d74464cfe2eaa9e4febbe61ba5.zip
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>
Diffstat (limited to 'pkg/machine')
-rw-r--r--pkg/machine/config.go3
-rw-r--r--pkg/machine/e2e/init_test.go5
-rw-r--r--pkg/machine/e2e/machine_test.go3
-rw-r--r--pkg/machine/fcos.go4
-rw-r--r--pkg/machine/ignition.go5
-rw-r--r--pkg/machine/keys.go5
-rw-r--r--pkg/machine/pull.go3
-rw-r--r--pkg/machine/qemu/claim_darwin.go4
-rw-r--r--pkg/machine/qemu/machine.go9
-rw-r--r--pkg/machine/wsl/machine.go5
-rw-r--r--pkg/machine/wsl/util_windows.go3
11 files changed, 20 insertions, 29 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 54aa9e1b7..8c22ae6a3 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -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
diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go
index c298d3b14..ebf59dcd7 100644
--- a/pkg/machine/e2e/init_test.go
+++ b/pkg/machine/e2e/init_test.go
@@ -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)
diff --git a/pkg/machine/e2e/machine_test.go b/pkg/machine/e2e/machine_test.go
index 5de04b9f7..5cd89c7ab 100644
--- a/pkg/machine/e2e/machine_test.go
+++ b/pkg/machine/e2e/machine_test.go
@@ -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))
}
diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go
index 246f92a19..311891c26 100644
--- a/pkg/machine/fcos.go
+++ b/pkg/machine/fcos.go
@@ -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
}
diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go
index 366d10499..39ddce14c 100644
--- a/pkg/machine/ignition.go
+++ b/pkg/machine/ignition.go
@@ -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
diff --git a/pkg/machine/keys.go b/pkg/machine/keys.go
index 94cbdac04..fce405695 100644
--- a/pkg/machine/keys.go
+++ b/pkg/machine/keys.go
@@ -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
}
diff --git a/pkg/machine/pull.go b/pkg/machine/pull.go
index 22a1b4c0a..9cba78237 100644
--- a/pkg/machine/pull.go
+++ b/pkg/machine/pull.go
@@ -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
}
diff --git a/pkg/machine/qemu/claim_darwin.go b/pkg/machine/qemu/claim_darwin.go
index 66aed9ad8..c51d17bc9 100644
--- a/pkg/machine/qemu/claim_darwin.go
+++ b/pkg/machine/qemu/claim_darwin.go
@@ -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"
}
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 738cd74be..fab25aa35 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -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
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go
index 44b82b823..81980736d 100644
--- a/pkg/machine/wsl/machine.go
+++ b/pkg/machine/wsl/machine.go
@@ -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
}
diff --git a/pkg/machine/wsl/util_windows.go b/pkg/machine/wsl/util_windows.go
index 67d1bfc5c..5f8da10ec 100644
--- a/pkg/machine/wsl/util_windows.go
+++ b/pkg/machine/wsl/util_windows.go
@@ -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)
}