Merge pull request #3842 from dgageot/remove-ioutil

Remove 99% of deprecated ioutil usage (src/cmd/linuxkit)
This commit is contained in:
Avi Deitcher 2022-10-09 15:53:57 +03:00 committed by GitHub
commit a3f3f5630b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 65 additions and 87 deletions

View File

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

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"strings" "strings"
"github.com/containerd/containerd/reference" "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) return ImageSource{}, fmt.Errorf("invalid hash filename for %s: %v", filename, err)
} }
log.Debugf("writing %s as hash %s", filename, hash) 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) 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 { if err != nil {
return ImageSource{}, fmt.Errorf("error calculating hash of index json: %v", err) 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) return ImageSource{}, fmt.Errorf("error writing new index to json: %v", err)
} }
// finally update the descriptor in the root // finally update the descriptor in the root

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ import (
_ "embed" _ "embed"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -52,7 +51,7 @@ func ensureLinuxkitImage(name, cache string) error {
// Might as well just use our local one. // Might as well just use our local one.
arch := runtime.GOARCH arch := runtime.GOARCH
// TODO pass through --pull to here // TODO pass through --pull to here
tf, err := ioutil.TempFile("", "") tf, err := os.CreateTemp("", "")
if err != nil { if err != nil {
return err return err
} }
@ -77,21 +76,21 @@ func ensureLinuxkitImage(name, cache string) error {
} }
func writeKernelInitrd(filename string, kernel []byte, initrd []byte, cmdline 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 { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filename+"-initrd.img", initrd, 0600) err = os.WriteFile(filename+"-initrd.img", initrd, 0600)
if err != nil { if err != nil {
return err 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 { 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) 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 { if err != nil {
return err return err
} }

View File

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

View File

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

View File

@ -12,7 +12,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path" "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. // 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 // See https://github.community/t/what-really-is-docker-3-0-6/16171
func (dr *dockerRunnerImpl) contextSupportCheck() error { 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. // 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 we were given a context, we must find a builder and use it, or create one and use it
if dockerContext != "" { if dockerContext != "" {
// does the context exist? // 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) return nil, fmt.Errorf("provided docker context '%s' not found", dockerContext)
} }
client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, platform, dockerContext, restart) 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 // no provided dockerContext, so look for one based on platform-specific name
dockerContext = fmt.Sprintf("%s-%s", "linuxkit", strings.ReplaceAll(platform, "/", "-")) 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 // 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 { if client, err := dr.builderEnsureContainer(ctx, buildkitBuilderName, builderImage, platform, dockerContext, restart); err == nil {
return client, nil return client, nil
@ -263,7 +262,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
b bytes.Buffer 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. // we already have a container named "linuxkit-builder" in the provided context.
// get its state and config // get its state and config
var containerJSON []types.ContainerJSON var containerJSON []types.ContainerJSON
@ -300,7 +299,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
default: default:
// we have an existing container, but it isn't running, so start it // we have an existing container, but it isn't running, so start it
fmt.Printf("starting existing container %s\n", name) 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) return nil, fmt.Errorf("failed to start existing container %s", name)
} }
recreate = false 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, // 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 // or because we received the CLI option
if stop { 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) return nil, fmt.Errorf("failed to stop existing container %s", name)
} }
} }
if remove { 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) 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"} 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) msg := fmt.Sprintf("creating builder container '%s' in context '%s'", name, dockerContext)
fmt.Println(msg) 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 return nil, err
} }
} }

View File

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

View File

@ -2,7 +2,6 @@ package pkglib
import ( import (
"flag" "flag"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -13,10 +12,10 @@ import (
) )
func dummyPackage(t *testing.T, tmpDir, yml string) string { func dummyPackage(t *testing.T, tmpDir, yml string) string {
d, err := ioutil.TempDir(tmpDir, "") d, err := os.MkdirTemp(tmpDir, "")
require.NoError(t, err) 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) require.NoError(t, err)
return d return d

View File

@ -4,7 +4,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -74,7 +73,7 @@ func pushPacket(args []string) {
// Read kernel command line // Read kernel command line
var cmdline string 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) log.Fatalf("Cannot open cmdline file: %v", err)
} else { } else {
cmdline = string(c) 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) 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) log.Fatalf("Error writing iPXE script: %v", err)
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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