Skip to content

Commit

Permalink
lxc: move from io/ioutil to io and os packages
Browse files Browse the repository at this point in the history
Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Oct 2, 2022
1 parent 6b101e5 commit 5a1cb68
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 81 deletions.
10 changes: 5 additions & 5 deletions lxc/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bufio"
"fmt"
"io/ioutil"
"io"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -633,7 +633,7 @@ func (c *cmdClusterEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -1009,12 +1009,12 @@ func (c *cmdClusterUpdateCertificate) Run(cmd *cobra.Command, args []string) err
return fmt.Errorf(i18n.G("Could not find certificate key file path: %s"), keyFile)
}

cert, err := ioutil.ReadFile(certFile)
cert, err := os.ReadFile(certFile)
if err != nil {
return fmt.Errorf(i18n.G("Could not read certificate file: %s with error: %v"), certFile, err)
}

key, err := ioutil.ReadFile(keyFile)
key, err := os.ReadFile(keyFile)
if err != nil {
return fmt.Errorf(i18n.G("Could not read certificate key file: %s with error: %v"), keyFile, err)
}
Expand All @@ -1031,7 +1031,7 @@ func (c *cmdClusterUpdateCertificate) Run(cmd *cobra.Command, args []string) err

certf := conf.ServerCertPath(resource.remote)
if shared.PathExists(certf) {
err = ioutil.WriteFile(certf, cert, 0644)
err = os.WriteFile(certf, cert, 0644)
if err != nil {
return fmt.Errorf(i18n.G("Could not write new remote certificate for remote '%s' with error: %v"), resource.remote, err)
}
Expand Down
4 changes: 2 additions & 2 deletions lxc/cluster_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -281,7 +281,7 @@ func (c *cmdClusterGroupEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions lxc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -154,7 +154,7 @@ func (c *cmdConfigEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func (c *cmdConfigEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions lxc/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -15,7 +14,7 @@ import (
// not exist, it returns a default configuration.
func LoadConfig(path string) (*Config, error) {
// Open the config file
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("Unable to read the configuration file: %w", err)
}
Expand All @@ -36,7 +35,7 @@ func LoadConfig(path string) (*Config, error) {

// Apply the global (system-wide) remotes
globalConf := NewConfig("", false)
content, err = ioutil.ReadFile(globalConf.GlobalConfigPath("config.yml"))
content, err = os.ReadFile(globalConf.GlobalConfigPath("config.yml"))
if err == nil {
err = yaml.Unmarshal(content, &globalConf)
if err != nil {
Expand Down
9 changes: 4 additions & 5 deletions lxc/config/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"net/url"
"os"
"runtime"
Expand Down Expand Up @@ -253,7 +252,7 @@ func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {

// Server certificate
if shared.PathExists(c.ServerCertPath(name)) {
content, err := ioutil.ReadFile(c.ServerCertPath(name))
content, err := os.ReadFile(c.ServerCertPath(name))
if err != nil {
return nil, err
}
Expand All @@ -268,7 +267,7 @@ func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {

// Client certificate
if shared.PathExists(c.ConfigPath("client.crt")) {
content, err := ioutil.ReadFile(c.ConfigPath("client.crt"))
content, err := os.ReadFile(c.ConfigPath("client.crt"))
if err != nil {
return nil, err
}
Expand All @@ -278,7 +277,7 @@ func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {

// Client CA
if shared.PathExists(c.ConfigPath("client.ca")) {
content, err := ioutil.ReadFile(c.ConfigPath("client.ca"))
content, err := os.ReadFile(c.ConfigPath("client.ca"))
if err != nil {
return nil, err
}
Expand All @@ -288,7 +287,7 @@ func (c *Config) getConnectionArgs(name string) (*lxd.ConnectionArgs, error) {

// Client key
if shared.PathExists(c.ConfigPath("client.key")) {
content, err := ioutil.ReadFile(c.ConfigPath("client.key"))
content, err := os.ReadFile(c.ConfigPath("client.key"))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions lxc/config_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *cmdConfigMetadataEdit) Run(cmd *cobra.Command, args []string) error {
// Edit the metadata
if !termios.IsTerminal(getStdinFd()) {
metadata := api.ImageMetadata{}
content, err := ioutil.ReadAll(os.Stdin)
content, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions lxc/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"sort"

Expand Down Expand Up @@ -187,7 +187,7 @@ func (c *cmdConfigTemplateEdit) Run(cmd *cobra.Command, args []string) error {
return err
}

content, err := ioutil.ReadAll(reader)
content, err := io.ReadAll(reader)
if err != nil {
return err
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func (c *cmdConfigTemplateShow) Run(cmd *cobra.Command, args []string) error {
return err
}

content, err := ioutil.ReadAll(template)
content, err := io.ReadAll(template)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions lxc/config_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -264,7 +264,7 @@ func (c *cmdConfigTrustEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions lxc/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -132,7 +131,7 @@ func (c *cmdConsole) Run(cmd *cobra.Command, args []string) error {
return err
}

stuff, err := ioutil.ReadAll(log)
stuff, err := io.ReadAll(log)
if err != nil {
return err
}
Expand Down Expand Up @@ -262,7 +261,7 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
}

// Generate a random file name.
path, err := ioutil.TempFile(conf.ConfigPath("sockets"), "*.spice")
path, err := os.CreateTemp(conf.ConfigPath("sockets"), "*.spice")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions lxc/console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
Expand All @@ -30,7 +30,7 @@ func (c *cmdConsole) findCommand(name string) string {
path, _ := exec.LookPath(name)
if path == "" {
// Let's see if it's not in the usual location.
programs, err := ioutil.ReadDir("\\Program Files")
programs, err := os.ReadDir("\\Program Files")
if err != nil {
return ""
}
Expand Down
3 changes: 1 addition & 2 deletions lxc/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -170,7 +169,7 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) error {
var stdin io.ReadCloser
stdin = os.Stdin
if c.flagDisableStdin {
stdin = ioutil.NopCloser(bytes.NewReader(nil))
stdin = io.NopCloser(bytes.NewReader(nil))
}

stdout := getStdout()
Expand Down
9 changes: 4 additions & 5 deletions lxc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -189,7 +188,7 @@ func (c *cmdFileEdit) Run(cmd *cobra.Command, args []string) error {
}

// Create temp file
f, err := ioutil.TempFile("", "lxd_file_edit_")
f, err := os.CreateTemp("", "lxd_file_edit_")
if err != nil {
return fmt.Errorf(i18n.G("Unable to create a temporary file: %v"), err)
}
Expand Down Expand Up @@ -345,7 +344,7 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {
logger.Infof("Pulling %s from %s (%s)", targetPath, pathSpec[1], resp.Type)

if resp.Type == "symlink" {
linkTarget, err := ioutil.ReadAll(buf)
linkTarget, err := io.ReadAll(buf)
if err != nil {
return err
}
Expand Down Expand Up @@ -765,7 +764,7 @@ func (c *cmdFile) recursivePullFile(d lxd.InstanceServer, inst string, p string,

progress.Done("")
} else if resp.Type == "symlink" {
linkTarget, err := ioutil.ReadAll(buf)
linkTarget, err := io.ReadAll(buf)
if err != nil {
return err
}
Expand Down Expand Up @@ -819,7 +818,7 @@ func (c *cmdFile) recursivePushFile(d lxd.InstanceServer, inst string, source st

args.Type = "symlink"
args.Content = bytes.NewReader([]byte(symlinkTarget))
readCloser = ioutil.NopCloser(args.Content)
readCloser = io.NopCloser(args.Content)
} else {
// File handling
f, err := os.Open(p)
Expand Down
5 changes: 2 additions & 3 deletions lxc/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -412,7 +411,7 @@ func (c *cmdImageEdit) Run(cmd *cobra.Command, args []string) error {

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -669,7 +668,7 @@ func (c *cmdImageImport) packImageDir(path string) (string, error) {
return "", fmt.Errorf(i18n.G("Must run as root to import from directory"))
}

outFile, err := ioutil.TempFile("", "lxd_image_")
outFile, err := os.CreateTemp("", "lxd_image_")
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions lxc/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"sort"
"strings"

Expand Down Expand Up @@ -705,7 +704,7 @@ func (c *cmdInfo) instanceInfo(d lxd.InstanceServer, remote config.Remote, name
return fmt.Errorf(i18n.G("Unsupported instance type: %s"), inst.Type)
}

stuff, err := ioutil.ReadAll(log)
stuff, err := io.ReadAll(log)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions lxc/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *cmdInit) create(conf *config.Config, args []string) (lxd.InstanceServer

// If stdin isn't a terminal, read text from it
if !termios.IsTerminal(getStdinFd()) {
contents, err := ioutil.ReadAll(os.Stdin)
contents, err := io.ReadAll(os.Stdin)
if err != nil {
return nil, "", err
}
Expand Down
Loading

0 comments on commit 5a1cb68

Please sign in to comment.