Remove 99% of deprecated ioutil usage

Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
David Gageot 2022-10-07 20:28:10 +02:00
parent 8ef4fa3483
commit 7687de2d20
No known key found for this signature in database
GPG Key ID: 93C3F22BE5D3A40B
23 changed files with 65 additions and 87 deletions

View File

@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@ -151,7 +150,7 @@ func build(args []string) {
var config []byte
if conf := arg; conf == "-" {
var err error
config, err = ioutil.ReadAll(os.Stdin)
config, err = io.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Cannot read stdin: %v", err)
}
@ -169,7 +168,7 @@ func build(args []string) {
config = buffer.Bytes()
} else {
var err error
config, err = ioutil.ReadFile(conf)
config, err = os.ReadFile(conf)
if err != nil {
log.Fatalf("Cannot open config file: %v", err)
}
@ -190,7 +189,7 @@ func build(args []string) {
if outputFile != nil {
w = outputFile
} else {
if tf, err = ioutil.TempFile("", ""); err != nil {
if tf, err = os.CreateTemp("", ""); err != nil {
log.Fatalf("Error creating tempfile: %v", err)
}
defer os.Remove(tf.Name())

View File

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strings"
"github.com/containerd/containerd/reference"
@ -167,7 +166,7 @@ func (p *Provider) ImageLoad(ref *reference.Spec, architecture string, r io.Read
return ImageSource{}, fmt.Errorf("invalid hash filename for %s: %v", filename, err)
}
log.Debugf("writing %s as hash %s", filename, hash)
if err := p.cache.WriteBlob(hash, ioutil.NopCloser(tr)); err != nil {
if err := p.cache.WriteBlob(hash, io.NopCloser(tr)); err != nil {
return ImageSource{}, fmt.Errorf("error reading data for file %s : %v", filename, err)
}
}
@ -300,7 +299,7 @@ func (p *Provider) IndexWrite(ref *reference.Spec, descriptors ...v1.Descriptor)
if err != nil {
return ImageSource{}, fmt.Errorf("error calculating hash of index json: %v", err)
}
if err := p.cache.WriteBlob(hash, ioutil.NopCloser(bytes.NewReader(b))); err != nil {
if err := p.cache.WriteBlob(hash, io.NopCloser(bytes.NewReader(b))); err != nil {
return ImageSource{}, fmt.Errorf("error writing new index to json: %v", err)
}
// finally update the descriptor in the root

View File

@ -5,7 +5,6 @@ import (
"crypto/rsa"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strings"
@ -54,7 +53,7 @@ func NewGCPClient(keys, projectName string) (*GCPClient, error) {
return nil, err
}
jsonKey, err := ioutil.ReadAll(f)
jsonKey, err := io.ReadAll(f)
if err != nil {
return nil, err
}
@ -397,7 +396,7 @@ func (g GCPClient) ConnectToInstanceSerialPort(instance, zone string) error {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}

View File

@ -5,7 +5,6 @@ import (
"bytes"
"errors"
"io"
"io/ioutil"
"path/filepath"
"strings"
@ -107,19 +106,19 @@ func CopySplitTar(w *Writer, r *tar.Reader) (kernel []byte, cmdline string, ucod
}
switch {
case thdr.Name == "boot/kernel":
kernel, err = ioutil.ReadAll(r)
kernel, err = io.ReadAll(r)
if err != nil {
return
}
case thdr.Name == "boot/cmdline":
var buf []byte
buf, err = ioutil.ReadAll(r)
buf, err = io.ReadAll(r)
if err != nil {
return
}
cmdline = string(buf)
case thdr.Name == "boot/ucode.cpio":
ucode, err = ioutil.ReadAll(r)
ucode, err = io.ReadAll(r)
if err != nil {
return
}

View File

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -52,7 +51,7 @@ func printVersion() {
func readConfig() {
cfgPath := filepath.Join(os.Getenv("HOME"), ".moby", "linuxkit", "config.yml")
cfgBytes, err := ioutil.ReadFile(cfgPath)
cfgBytes, err := os.ReadFile(cfgPath)
if err != nil {
if os.IsNotExist(err) {
return

View File

@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -596,7 +595,7 @@ func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error {
}
}
var err error
contents, err = ioutil.ReadFile(source)
contents, err = os.ReadFile(source)
if err != nil {
return err
}

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"path"
"sort"
"strings"
@ -218,7 +217,7 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, resolv string, o
hdr.Format = tar.FormatPAX
if exclude[hdr.Name] {
log.Debugf("image tar: %s %s exclude %s", ref, prefix, hdr.Name)
_, err = io.Copy(ioutil.Discard, tr)
_, err = io.Copy(io.Discard, tr)
if err != nil {
return err
}
@ -249,7 +248,7 @@ func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, resolv string, o
return err
}
}
_, err = io.Copy(ioutil.Discard, tr)
_, err = io.Copy(io.Discard, tr)
if err != nil {
return err
}

View File

@ -8,7 +8,6 @@ import (
_ "embed"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -52,7 +51,7 @@ func ensureLinuxkitImage(name, cache string) error {
// Might as well just use our local one.
arch := runtime.GOARCH
// TODO pass through --pull to here
tf, err := ioutil.TempFile("", "")
tf, err := os.CreateTemp("", "")
if err != nil {
return err
}
@ -77,21 +76,21 @@ func ensureLinuxkitImage(name, cache string) error {
}
func writeKernelInitrd(filename string, kernel []byte, initrd []byte, cmdline string) error {
err := ioutil.WriteFile(filename+"-kernel", kernel, 0600)
err := os.WriteFile(filename+"-kernel", kernel, 0600)
if err != nil {
return err
}
err = ioutil.WriteFile(filename+"-initrd.img", initrd, 0600)
err = os.WriteFile(filename+"-initrd.img", initrd, 0600)
if err != nil {
return err
}
return ioutil.WriteFile(filename+"-cmdline", []byte(cmdline), 0600)
return os.WriteFile(filename+"-cmdline", []byte(cmdline), 0600)
}
func outputLinuxKit(format string, filename string, kernel []byte, initrd []byte, cmdline string, size int) error {
log.Debugf("output linuxkit generated img: %s %s size %d", format, filename, size)
tmp, err := ioutil.TempDir(filepath.Join(MobyDir, "tmp"), "moby")
tmp, err := os.MkdirTemp(filepath.Join(MobyDir, "tmp"), "moby")
if err != nil {
return err
}

View File

@ -10,7 +10,6 @@ import (
_ "embed"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"strings"
@ -379,7 +378,7 @@ func outputKernelInitrd(base string, kernel []byte, initrd []byte, cmdline strin
if len(ucode) != 0 {
log.Infof(" %s ucode+%s %s", base+"-kernel", base+"-initrd.img", base+"-cmdline")
if err := ioutil.WriteFile(base+"-initrd.img", ucode, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-initrd.img", ucode, os.FileMode(0644)); err != nil {
return err
}
if len(initrd) != 0 {
@ -395,18 +394,18 @@ func outputKernelInitrd(base string, kernel []byte, initrd []byte, cmdline strin
} else {
if len(initrd) != 0 {
log.Infof(" %s %s %s", base+"-kernel", base+"-initrd.img", base+"-cmdline")
if err := ioutil.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-initrd.img", initrd, os.FileMode(0644)); err != nil {
return err
}
}
}
if len(kernel) != 0 {
if err := ioutil.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
return err
}
}
if len(cmdline) != 0 {
return ioutil.WriteFile(base+"-cmdline", []byte(cmdline), os.FileMode(0644))
return os.WriteFile(base+"-cmdline", []byte(cmdline), os.FileMode(0644))
}
return nil
}
@ -503,19 +502,19 @@ func outputKernelSquashFS(image, base string, filesystem io.Reader) error {
thdr.Format = tar.FormatPAX
switch {
case thdr.Name == "boot/kernel":
kernel, err := ioutil.ReadAll(tr)
kernel, err := io.ReadAll(tr)
if err != nil {
return err
}
if err := ioutil.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
return err
}
case thdr.Name == "boot/cmdline":
cmdline, err := ioutil.ReadAll(tr)
cmdline, err := io.ReadAll(tr)
if err != nil {
return err
}
if err := ioutil.WriteFile(base+"-cmdline", cmdline, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-cmdline", cmdline, os.FileMode(0644)); err != nil {
return err
}
case strings.HasPrefix(thdr.Name, "boot/"):
@ -558,19 +557,19 @@ func outputKernelISO(image, base string, filesystem io.Reader) error {
thdr.Format = tar.FormatPAX
switch {
case thdr.Name == "boot/kernel":
kernel, err := ioutil.ReadAll(tr)
kernel, err := io.ReadAll(tr)
if err != nil {
return err
}
if err := ioutil.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-kernel", kernel, os.FileMode(0644)); err != nil {
return err
}
case thdr.Name == "boot/cmdline":
cmdline, err := ioutil.ReadAll(tr)
cmdline, err := io.ReadAll(tr)
if err != nil {
return err
}
if err := ioutil.WriteFile(base+"-cmdline", cmdline, os.FileMode(0644)); err != nil {
if err := os.WriteFile(base+"-cmdline", cmdline, os.FileMode(0644)); err != nil {
return err
}
case strings.HasPrefix(thdr.Name, "boot/"):

View File

@ -7,8 +7,8 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"strings"
"testing"
@ -72,10 +72,10 @@ func (d *dockerMocker) save(tgt string, refs ...string) error {
}
return fmt.Errorf("do not have image %s", ref)
}
return ioutil.WriteFile(tgt, b, 0666)
return os.WriteFile(tgt, b, 0666)
}
func (d *dockerMocker) load(src io.Reader) error {
b, err := ioutil.ReadAll(src)
b, err := io.ReadAll(src)
if err != nil {
return err
}
@ -123,7 +123,7 @@ func (c *cacheMocker) imageWriteStream(ref *reference.Spec, architecture string,
image := fmt.Sprintf("%s-%s", ref.String(), architecture)
// make some random data for a layer
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("error reading data: %v", err)
}
@ -323,7 +323,7 @@ func TestBuild(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.msg, func(t *testing.T) {
opts := append(tt.options, WithBuildDocker(tt.runner), WithBuildCacheProvider(tt.cache), WithBuildOutputWriter(ioutil.Discard))
opts := append(tt.options, WithBuildDocker(tt.runner), WithBuildCacheProvider(tt.cache), WithBuildOutputWriter(io.Discard))
// build our build options
if len(tt.targets) > 0 {
var targets []imagespec.Platform

View File

@ -12,7 +12,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
@ -199,7 +198,7 @@ func (dr *dockerRunnerImpl) versionCheck(version string) (string, string, error)
// of docker in Actions, which makes it difficult to tell if context is supported.
// See https://github.community/t/what-really-is-docker-3-0-6/16171
func (dr *dockerRunnerImpl) contextSupportCheck() error {
return dr.command(nil, ioutil.Discard, ioutil.Discard, "context", "ls")
return dr.command(nil, io.Discard, io.Discard, "context", "ls")
}
// builder ensure that a builder container exists or return an error.
@ -219,7 +218,7 @@ func (dr *dockerRunnerImpl) builder(ctx context.Context, dockerContext, builderI
// if we were given a context, we must find a builder and use it, or create one and use it
if dockerContext != "" {
// does the context exist?
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, "context", "inspect", dockerContext); err != nil {
if err := dr.command(nil, io.Discard, io.Discard, "context", "inspect", dockerContext); err != nil {
return nil, fmt.Errorf("provided docker context '%s' not found", dockerContext)
}
client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, platform, dockerContext, restart)
@ -231,7 +230,7 @@ func (dr *dockerRunnerImpl) builder(ctx context.Context, dockerContext, builderI
// no provided dockerContext, so look for one based on platform-specific name
dockerContext = fmt.Sprintf("%s-%s", "linuxkit", strings.ReplaceAll(platform, "/", "-"))
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, "context", "inspect", dockerContext); err == nil {
if err := dr.command(nil, io.Discard, io.Discard, "context", "inspect", dockerContext); err == nil {
// we found an appropriately named context, so let us try to use it or error out
if client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, platform, dockerContext, restart); err == nil {
return client, nil
@ -263,7 +262,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
b bytes.Buffer
)
if err := dr.command(nil, &b, ioutil.Discard, "--context", dockerContext, "container", "inspect", name); err == nil {
if err := dr.command(nil, &b, io.Discard, "--context", dockerContext, "container", "inspect", name); err == nil {
// we already have a container named "linuxkit-builder" in the provided context.
// get its state and config
var containerJSON []types.ContainerJSON
@ -300,7 +299,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
default:
// we have an existing container, but it isn't running, so start it
fmt.Printf("starting existing container %s\n", name)
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, "--context", dockerContext, "container", "start", name); err != nil {
if err := dr.command(nil, io.Discard, io.Discard, "--context", dockerContext, "container", "start", name); err != nil {
return nil, fmt.Errorf("failed to start existing container %s", name)
}
recreate = false
@ -311,12 +310,12 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
// if we made it here, we need to stop and remove the container, either because of a config mismatch,
// or because we received the CLI option
if stop {
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, "--context", dockerContext, "container", "stop", name); err != nil {
if err := dr.command(nil, io.Discard, io.Discard, "--context", dockerContext, "container", "stop", name); err != nil {
return nil, fmt.Errorf("failed to stop existing container %s", name)
}
}
if remove {
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, "--context", dockerContext, "container", "rm", name); err != nil {
if err := dr.command(nil, io.Discard, io.Discard, "--context", dockerContext, "container", "rm", name); err != nil {
return nil, fmt.Errorf("failed to remove existing container %s", name)
}
}
@ -325,7 +324,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
args := []string{"container", "run", "-d", "--name", name, "--privileged", image, "--allow-insecure-entitlement", "network.host", "--addr", fmt.Sprintf("unix://%s", buildkitSocketPath), "--debug"}
msg := fmt.Sprintf("creating builder container '%s' in context '%s'", name, dockerContext)
fmt.Println(msg)
if err := dr.command(nil, ioutil.Discard, ioutil.Discard, args...); err != nil {
if err := dr.command(nil, io.Discard, io.Discard, args...); err != nil {
return nil, err
}
}

View File

@ -4,7 +4,6 @@ import (
"crypto/sha1"
"flag"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
@ -148,7 +147,7 @@ func NewFromCLI(fs *flag.FlagSet, args ...string) ([]Pkg, error) {
return nil, err
}
b, err := ioutil.ReadFile(filepath.Join(pkgPath, buildYML))
b, err := os.ReadFile(filepath.Join(pkgPath, buildYML))
if err != nil {
return nil, err
}

View File

@ -2,7 +2,6 @@ package pkglib
import (
"flag"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@ -13,10 +12,10 @@ import (
)
func dummyPackage(t *testing.T, tmpDir, yml string) string {
d, err := ioutil.TempDir(tmpDir, "")
d, err := os.MkdirTemp(tmpDir, "")
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(d, "build.yml"), []byte(yml), 0644)
err = os.WriteFile(filepath.Join(d, "build.yml"), []byte(yml), 0644)
require.NoError(t, err)
return d

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
@ -74,7 +73,7 @@ func pushPacket(args []string) {
// Read kernel command line
var cmdline string
if c, err := ioutil.ReadFile(prefix + "-cmdline"); err != nil {
if c, err := os.ReadFile(prefix + "-cmdline"); err != nil {
log.Fatalf("Cannot open cmdline file: %v", err)
} else {
cmdline = string(c)
@ -113,7 +112,7 @@ func packetPushFile(dst *url.URL, decompress bool, name, cmdline, ipxeScript str
}
ipxeScriptName := fmt.Sprintf("%s-packet.ipxe", name)
if err := ioutil.WriteFile(filepath.Join(dstPath, ipxeScriptName), []byte(ipxeScript), 0644); err != nil {
if err := os.WriteFile(filepath.Join(dstPath, ipxeScriptName), []byte(ipxeScript), 0644); err != nil {
log.Fatalf("Error writing iPXE script: %v", err)
}
}

View File

@ -4,7 +4,6 @@ import (
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -63,7 +62,7 @@ func runAWS(args []string) {
}
if *dataPath != "" {
dataB, err := ioutil.ReadFile(*dataPath)
dataB, err := os.ReadFile(*dataPath)
if err != nil {
log.Fatalf("Unable to read metadata file: %v", err)
}

View File

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -71,7 +70,7 @@ func runGcp(args []string) {
}
if *dataPath != "" {
dataB, err := ioutil.ReadFile(*dataPath)
dataB, err := os.ReadFile(*dataPath)
if err != nil {
log.Fatalf("Unable to read metadata file: %v", err)
}

View File

@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
@ -166,11 +165,11 @@ func runHyperKit(args []string) {
vpnkitUUIDFile := filepath.Join(*state, "vpnkit.uuid")
if _, err := os.Stat(vpnkitUUIDFile); os.IsNotExist(err) {
*vpnkitUUID = uuid.New().String()
if err := ioutil.WriteFile(vpnkitUUIDFile, []byte(*vpnkitUUID), 0600); err != nil {
if err := os.WriteFile(vpnkitUUIDFile, []byte(*vpnkitUUID), 0600); err != nil {
log.Fatalf("Unable to write to %s: %v", vpnkitUUIDFile, err)
}
} else {
uuidBytes, err := ioutil.ReadFile(vpnkitUUIDFile)
uuidBytes, err := os.ReadFile(vpnkitUUIDFile)
if err != nil {
log.Fatalf("Unable to read VPNKit UUID from %s: %v", vpnkitUUIDFile, err)
}
@ -189,7 +188,7 @@ func runHyperKit(args []string) {
// Run
var cmdline string
if *kernelBoot || *squashFSBoot {
cmdlineBytes, err := ioutil.ReadFile(prefix + "-cmdline")
cmdlineBytes, err := os.ReadFile(prefix + "-cmdline")
if err != nil {
log.Fatalf("Cannot open cmdline file: %v", err)
}

View File

@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
@ -108,7 +107,7 @@ func runPacket(args []string) {
if *serveFlag != "" {
// Read kernel command line
var cmdline string
if c, err := ioutil.ReadFile(prefix + "-cmdline"); err != nil {
if c, err := os.ReadFile(prefix + "-cmdline"); err != nil {
log.Fatalf("Cannot open cmdline file: %v", err)
} else {
cmdline = string(c)
@ -368,7 +367,7 @@ func sshAgent() ssh.AuthMethod {
// This function returns the host key for a given host (the SOS server).
// If it can't be found, it errors
func sshHostKey(host string) (ssh.PublicKey, error) {
f, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts"))
f, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts"))
if err != nil {
return nil, fmt.Errorf("Can't read known_hosts file: %v", err)
}

View File

@ -4,7 +4,6 @@ import (
"crypto/rand"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
@ -88,14 +87,14 @@ func retrieveMAC(statePath string) net.HardwareAddr {
var mac net.HardwareAddr
fileName := filepath.Join(statePath, "mac-addr")
if macString, err := ioutil.ReadFile(fileName); err == nil {
if macString, err := os.ReadFile(fileName); err == nil {
if mac, err = net.ParseMAC(string(macString)); err != nil {
log.Fatalf("failed to parse mac-addr file: %s\n", macString)
}
} else {
// we did not generate a mac yet. generate one
mac = generateMAC()
if err = ioutil.WriteFile(fileName, []byte(mac.String()), 0640); err != nil {
if err = os.WriteFile(fileName, []byte(mac.String()), 0640); err != nil {
log.Fatalln("failed to write mac-addr file:", err)
}
}
@ -532,7 +531,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
qemuInitrdPath := config.Path + "-initrd.img"
qemuArgs = append(qemuArgs, "-kernel", qemuKernelPath)
qemuArgs = append(qemuArgs, "-initrd", qemuInitrdPath)
cmdlineBytes, err := ioutil.ReadFile(config.Path + "-cmdline")
cmdlineBytes, err := os.ReadFile(config.Path + "-cmdline")
if err != nil {
log.Errorf("Cannot open cmdline file: %v", err)
} else {
@ -541,7 +540,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
case config.SquashFS:
qemuKernelPath := config.Path + "-kernel"
qemuArgs = append(qemuArgs, "-kernel", qemuKernelPath)
cmdlineBytes, err := ioutil.ReadFile(config.Path + "-cmdline")
cmdlineBytes, err := os.ReadFile(config.Path + "-cmdline")
if err != nil {
log.Errorf("Cannot open cmdline file: %v", err)
} else {

View File

@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/signal"
@ -99,7 +98,7 @@ func runVirtualizationFramework(args []string) {
// Run
cmdlineBytes, err := ioutil.ReadFile(prefix + "-cmdline")
cmdlineBytes, err := os.ReadFile(prefix + "-cmdline")
if err != nil {
log.Fatalf("Cannot open cmdline file: %v", err)
}

View File

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -187,7 +186,7 @@ func runVMware(args []string) {
// Create the .vmx file
vmxPath := filepath.Join(*state, "linuxkit.vmx")
err := ioutil.WriteFile(vmxPath, []byte(vmx), 0644)
err := os.WriteFile(vmxPath, []byte(vmx), 0644)
if err != nil {
log.Fatalf("Error writing .vmx file: %v", err)
}

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
@ -279,7 +278,7 @@ func getSSHAuth(sshKeyPath string) (ssh.Signer, error) {
}
defer f.Close()
buf, err := ioutil.ReadAll(f)
buf, err := io.ReadAll(f)
if err != nil {
return nil, err
}
@ -345,7 +344,7 @@ func (s *ScalewayClient) CopyImageToInstance(instanceID, path, sshKeyPath string
defer f.Close()
// code taken from bramvdbogaerde/go-scp
contentBytes, err := ioutil.ReadAll(f)
contentBytes, err := io.ReadAll(f)
if err != nil {
return err
}

View File

@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
@ -294,7 +293,7 @@ func CreateMetadataISO(state, data string, dataPath string) ([]string, error) {
d = []byte(data)
case dataPath != "":
var err error
d, err = ioutil.ReadFile(dataPath)
d, err = os.ReadFile(dataPath)
if err != nil {
return nil, fmt.Errorf("Cannot read user data from path %s: %v", dataPath, err)
}