Merge pull request #3847 from dgageot/remove-ioutil-pkg

Remove 99% of deprecated ioutil usage (packages)
This commit is contained in:
Avi Deitcher 2022-10-09 15:52:27 +03:00 committed by GitHub
commit b1dda052db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 78 additions and 89 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -74,13 +73,13 @@ func main() {
}
defer syscall.Unmount(mount, 0)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
log.Fatalf("Cannot read directory %s: %s", dir, err)
}
for _, file := range files {
contents, err := ioutil.ReadFile(filepath.Join(dir, file.Name()))
contents, err := os.ReadFile(filepath.Join(dir, file.Name()))
if err != nil {
log.Fatalf("Cannot read file %s: %s", file.Name(), err)
}

View File

@ -3,7 +3,6 @@ package main
import (
"bufio"
"encoding/csv"
"io/ioutil"
"log"
"os"
"os/exec"
@ -109,7 +108,7 @@ func cgroupList() []string {
// write a file, eg sysfs
func write(path string, value string) {
err := ioutil.WriteFile(path, []byte(value), 0600)
err := os.WriteFile(path, []byte(value), 0600)
if err != nil {
log.Printf("cannot write to %s: %v", path, err)
}
@ -117,7 +116,7 @@ func write(path string, value string) {
// read a file, eg sysfs, strip whitespace, empty string if does not exist
func read(path string) string {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return ""
}
@ -127,7 +126,7 @@ func read(path string) string {
// read a directory
func readdir(path string) []string {
names := []string{}
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
log.Printf("cannot read directory %s: %v", path, err)
return names

View File

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -47,7 +46,7 @@ type Interface struct {
func getRuntimeConfig(path string) Runtime {
var runtime Runtime
conf, err := ioutil.ReadFile(filepath.Join(path, "runtime.json"))
conf, err := os.ReadFile(filepath.Join(path, "runtime.json"))
if err != nil {
// if it does not exist it is fine to return an empty runtime, to not do anything
if os.IsNotExist(err) {
@ -134,7 +133,7 @@ func newCgroup(cgroup string) error {
return nil
}
// a cgroupv1 cgroup is a directory under all directories in /sys/fs/cgroup
dirs, err := ioutil.ReadDir("/sys/fs/cgroup")
dirs, err := os.ReadDir("/sys/fs/cgroup")
if err != nil {
return err
}

View File

@ -2,7 +2,6 @@ package main
import (
"io"
"io/ioutil"
"os"
"os/exec"
"path"
@ -38,12 +37,12 @@ func runcInit(rootPath, serviceType string) int {
}
// get files; note ReadDir already sorts them
files, err := ioutil.ReadDir(rootPath)
files, err := os.ReadDir(rootPath)
if err != nil {
log.Fatalf("Cannot read files in %s: %v", rootPath, err)
}
tmpdir, err := ioutil.TempDir("", filepath.Base(rootPath))
tmpdir, err := os.MkdirTemp("", filepath.Base(rootPath))
if err != nil {
log.Fatalf("Cannot create temporary directory: %v", err)
}
@ -105,7 +104,7 @@ func runcInit(rootPath, serviceType string) int {
// skip cleanup on error for debug
continue
}
pf, err := ioutil.ReadFile(pidfile)
pf, err := os.ReadFile(pidfile)
if err != nil {
log.Printf("Cannot read pidfile: %v", err)
status = 1

View File

@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -91,7 +90,7 @@ func systemInitCmd(ctx context.Context, args []string) {
stderr io.Writer = os.Stderr
stdout io.Writer = os.Stdout
)
if b, err := ioutil.ReadFile(containerdOptsFile); err == nil {
if b, err := os.ReadFile(containerdOptsFile); err == nil {
config, err := toml.LoadBytes(b)
if err != nil {
log.Fatalf("error reading toml file %s: %v", containerdOptsFile, err)
@ -173,7 +172,7 @@ func systemInitCmd(ctx context.Context, args []string) {
}
// Start up containers
files, err := ioutil.ReadDir(*path)
files, err := os.ReadDir(*path)
// just skip if there is an error, eg no such path
if err != nil {
return

View File

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"flag"
"io/ioutil"
"os"
"path"
"strconv"
@ -160,7 +159,7 @@ func main() {
log.Printf("Error during metadata probe: %s", err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, "provider"), []byte(p.String()), 0644)
err = os.WriteFile(path.Join(ConfigPath, "provider"), []byte(p.String()), 0644)
if err != nil {
log.Printf("Error writing metadata provider: %s", err)
}
@ -173,7 +172,7 @@ func main() {
// Handle setting the hostname as a special case. We want to
// do this early and don't really want another container for it.
hostname, err := ioutil.ReadFile(path.Join(ConfigPath, Hostname))
hostname, err := os.ReadFile(path.Join(ConfigPath, Hostname))
if err == nil {
err := syscall.Sethostname(hostname)
if err != nil {
@ -196,7 +195,7 @@ func main() {
// Will create foobar/foo with mode 0644 and content "hello"
func processUserData(basePath string, data []byte) error {
// Always write the raw data to a file
err := ioutil.WriteFile(path.Join(basePath, "userdata"), data, 0644)
err := os.WriteFile(path.Join(basePath, "userdata"), data, 0644)
if err != nil {
log.Printf("Could not write userdata: %s", err)
return err
@ -223,7 +222,7 @@ func writeConfigFiles(target string, current Entry) {
log.Printf("Failed to parse permission %+v: %s", current, err)
return
}
if err := ioutil.WriteFile(target, []byte(*current.Content), filemode); err != nil {
if err := os.WriteFile(target, []byte(*current.Content), filemode); err != nil {
log.Printf("Failed to write %s: %s", target, err)
return
}

View File

@ -3,14 +3,13 @@ package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"path"
"testing"
)
func TestSampleConfig(t *testing.T) {
basePath, err := ioutil.TempDir("", "metadata")
basePath, err := os.MkdirTemp("", "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -82,7 +81,7 @@ func TestSerialization(t *testing.T) {
}
func TestWriteSingleFile(t *testing.T) {
basePath, err := ioutil.TempDir(os.TempDir(), "metadata")
basePath, err := os.MkdirTemp(os.TempDir(), "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -98,7 +97,7 @@ func TestWriteSingleFile(t *testing.T) {
}
func TestWriteEmptyFile(t *testing.T) {
basePath, err := ioutil.TempDir(os.TempDir(), "metadata")
basePath, err := os.MkdirTemp(os.TempDir(), "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -114,7 +113,7 @@ func TestWriteEmptyFile(t *testing.T) {
}
func TestWriteEmptyDirectory(t *testing.T) {
basePath, err := ioutil.TempDir(os.TempDir(), "metadata")
basePath, err := os.MkdirTemp(os.TempDir(), "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -132,7 +131,7 @@ func TestWriteEmptyDirectory(t *testing.T) {
}
func TestSetPermission(t *testing.T) {
basePath, err := ioutil.TempDir(os.TempDir(), "metadata")
basePath, err := os.MkdirTemp(os.TempDir(), "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -155,7 +154,7 @@ func TestSetPermission(t *testing.T) {
}
func TestDeepTree(t *testing.T) {
basePath, err := ioutil.TempDir("", "metadata")
basePath, err := os.MkdirTemp("", "metadata")
if err != nil {
t.Fatalf("can't make a temp rootdir %v", err)
}
@ -207,7 +206,7 @@ func assertPermission(t *testing.T, path string, expected os.FileMode) {
}
func assertContent(t *testing.T, path, expected string) {
file, err := ioutil.ReadFile(path)
file, err := os.ReadFile(path)
if err != nil {
t.Fatalf("can't read %v: %v", path, err)
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -37,7 +37,7 @@ func (p *ProviderAWS) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("AWS: Failed to write hostname: %s", err)
}
@ -79,7 +79,7 @@ func (p *ProviderAWS) Extract() ([]byte, error) {
func awsMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := awsGet(metaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("AWS: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -108,7 +108,7 @@ func awsGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("AWS: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("AWS: Failed to read http response: %s", err)
}
@ -126,7 +126,7 @@ func (p *ProviderAWS) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
@ -100,14 +100,14 @@ func FindCIs() []string {
// NewCDROM returns a new ProviderCDROM
func NewCDROM(device string) *ProviderCDROM {
mountPoint, err := ioutil.TempDir("", "cd")
mountPoint, err := os.MkdirTemp("", "cd")
p := ProviderCDROM{device, mountPoint, err, []byte{}, []byte{}}
if err == nil {
if p.err = p.mount(); p.err == nil {
// read the userdata - we read the spec file and the fallback, but eventually
// will remove the fallback
for _, f := range userdataFiles {
userdata, err := ioutil.ReadFile(path.Join(p.mountPoint, f))
userdata, err := os.ReadFile(path.Join(p.mountPoint, f))
// did we find a file?
if err == nil && userdata != nil {
p.userdata = userdata
@ -118,7 +118,7 @@ func NewCDROM(device string) *ProviderCDROM {
p.err = fmt.Errorf("no userdata file found at any of %v", userdataFiles)
}
// read the metadata
metadata, err := ioutil.ReadFile(path.Join(p.mountPoint, metadataFile))
metadata, err := os.ReadFile(path.Join(p.mountPoint, metadataFile))
// did we find a file?
if err == nil && metadata != nil {
p.metadata = metadata

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -41,7 +41,7 @@ func (p *ProviderDigitalOcean) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("DigitalOcean: Failed to write hostname: %s", err)
}
@ -77,7 +77,7 @@ func (p *ProviderDigitalOcean) Extract() ([]byte, error) {
func digitalOceanMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := digitalOceanGet(digitalOceanMetaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("DigitalOcean: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -106,7 +106,7 @@ func digitalOceanGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("DigitalOcean: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("DigitalOcean: Failed to read http response: %s", err)
}
@ -124,7 +124,7 @@ func (p *ProviderDigitalOcean) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -1,7 +1,6 @@
package main
import (
"io/ioutil"
"os"
)
@ -17,5 +16,5 @@ func (p fileProvider) Probe() bool {
}
func (p fileProvider) Extract() ([]byte, error) {
return ioutil.ReadFile(string(p))
return os.ReadFile(string(p))
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -43,7 +43,7 @@ func (p *ProviderGCP) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("GCP: Failed to write hostname: %s", err)
}
@ -81,7 +81,7 @@ func gcpGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("GCP: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("GCP: Failed to read http response: %s", err)
}
@ -116,7 +116,7 @@ func (p *ProviderGCP) handleSSH() error {
rootKeys = rootKeys + parts[1] + "\n"
}
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -38,7 +38,7 @@ func (p *ProviderHetzner) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("Hetzner: Failed to write hostname: %s", err)
}
@ -74,7 +74,7 @@ func (p *ProviderHetzner) Extract() ([]byte, error) {
func hetznerMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := hetznerGet(metaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("Hetzner: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -103,7 +103,7 @@ func hetznerGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Hetzner: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Hetzner: Failed to read http response: %s", err)
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -43,7 +43,7 @@ func (p *ProviderMetaldata) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("Metaldata: Failed to write hostname: %s", err)
}
@ -82,7 +82,7 @@ func (p *ProviderMetaldata) Extract() ([]byte, error) {
func metaldataMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := metaldataGet(metaldataMetaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("Metaldata: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -111,7 +111,7 @@ func metaldataGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Metaldata: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Metaldata: Failed to read http response: %s", err)
}
@ -129,7 +129,7 @@ func (p *ProviderMetaldata) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -37,7 +37,7 @@ func (p *ProviderOpenstack) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("OpenStack: Failed to write hostname: %s", err)
}
@ -79,7 +79,7 @@ func (p *ProviderOpenstack) Extract() ([]byte, error) {
func openstackMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := openstackGet(metaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("OpenStack: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -108,7 +108,7 @@ func openstackGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("OpenStack: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("OpenStack: Failed to read http response: %s", err)
}
@ -126,7 +126,7 @@ func (p *ProviderOpenstack) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -2,7 +2,6 @@ package main
import (
"fmt"
"io/ioutil"
"net"
"os"
"path"
@ -47,7 +46,7 @@ func (p *ProviderPacket) Extract() ([]byte, error) {
return nil, p.err
}
if err := ioutil.WriteFile(path.Join(ConfigPath, Hostname), []byte(p.metadata.Hostname), 0644); err != nil {
if err := os.WriteFile(path.Join(ConfigPath, Hostname), []byte(p.metadata.Hostname), 0644); err != nil {
return nil, fmt.Errorf("Packet: Failed to write hostname: %s", err)
}
@ -57,7 +56,7 @@ func (p *ProviderPacket) Extract() ([]byte, error) {
sshKeys := strings.Join(p.metadata.SSHKeys, "\n")
if err := ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(sshKeys), 0600); err != nil {
if err := os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(sshKeys), 0600); err != nil {
return nil, fmt.Errorf("Failed to write ssh keys: %s", err)
}
@ -125,7 +124,7 @@ func networkConfig(ni metadata.NetworkInfo) error {
// weirdly creating a bind always seems to return EEXIST
fmt.Fprintf(os.Stderr, "Error adding bond0: %v (ignoring)", err)
}
if err := ioutil.WriteFile("/sys/class/net/bond0/bonding/mode", []byte(strconv.Itoa(int(ni.Bonding.Mode))), 0); err != nil {
if err := os.WriteFile("/sys/class/net/bond0/bonding/mode", []byte(strconv.Itoa(int(ni.Bonding.Mode))), 0); err != nil {
return fmt.Errorf("Cannot write to /sys/class/net/bond0/bonding/mode: %v", err)
}
if err := netlink.LinkSetUp(bond); err != nil {

View File

@ -5,7 +5,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
@ -62,7 +62,7 @@ func (p *ProviderScaleway) Extract() ([]byte, error) {
return nil, fmt.Errorf("Scaleway: Failed to get hostname: %s", err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to write hostname: %s", err)
}
@ -72,7 +72,7 @@ func (p *ProviderScaleway) Extract() ([]byte, error) {
return nil, fmt.Errorf("Scaleway: Failed to get instanceID: %s", err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, instanceIDFile), instanceID, 0644)
err = os.WriteFile(path.Join(ConfigPath, instanceIDFile), instanceID, 0644)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to write instance_id: %s", err)
}
@ -82,7 +82,7 @@ func (p *ProviderScaleway) Extract() ([]byte, error) {
return nil, fmt.Errorf("Scaleway: Failed to get instanceLocation: %s", err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, instanceLocationFile), instanceLocation, 0644)
err = os.WriteFile(path.Join(ConfigPath, instanceLocationFile), instanceLocation, 0644)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to write instance_location: %s", err)
}
@ -92,7 +92,7 @@ func (p *ProviderScaleway) Extract() ([]byte, error) {
// not an error
log.Printf("Scaleway: Failed to get publicIP: %s", err)
} else {
err = ioutil.WriteFile(path.Join(ConfigPath, publicIPFile), publicIP, 0644)
err = os.WriteFile(path.Join(ConfigPath, publicIPFile), publicIP, 0644)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to write public_ip: %s", err)
}
@ -104,7 +104,7 @@ func (p *ProviderScaleway) Extract() ([]byte, error) {
return nil, fmt.Errorf("Scaleway: Failed to get privateIP: %s", err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, privateIPFile), privateIP, 0644)
err = os.WriteFile(path.Join(ConfigPath, privateIPFile), privateIP, 0644)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to write private_ip: %s", err)
}
@ -152,7 +152,7 @@ func scalewayGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Scaleway: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Scaleway: Failed to read http response: %s", err)
}
@ -192,7 +192,7 @@ func scalewayGetUserdata() ([]byte, error) {
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@ -225,7 +225,7 @@ func (p *ProviderScaleway) handleSSH(metadata []byte) error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), []byte(rootKeys), 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@ -41,7 +41,7 @@ func (p *ProviderVultr) Extract() ([]byte, error) {
if err != nil {
return nil, err
}
err = ioutil.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
err = os.WriteFile(path.Join(ConfigPath, Hostname), hostname, 0644)
if err != nil {
return nil, fmt.Errorf("Vultr: Failed to write hostname: %s", err)
}
@ -73,7 +73,7 @@ func (p *ProviderVultr) Extract() ([]byte, error) {
func vultrMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
if lookupValue, err := vultrGet(vultrMetaDataURL + lookupName); err == nil {
// we got a value from the metadata server, now save to filesystem
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
err = os.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
if err != nil {
// we couldn't save the file for some reason
log.Printf("Vultr: Failed to write %s:%s %s", fileName, lookupValue, err)
@ -102,7 +102,7 @@ func vultrGet(url string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Vultr: Status not ok: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Vultr: Failed to read http response: %s", err)
}
@ -120,7 +120,7 @@ func (p *ProviderVultr) handleSSH() error {
return fmt.Errorf("Failed to create %s: %s", SSH, err)
}
err = ioutil.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
err = os.WriteFile(path.Join(ConfigPath, SSH, "authorized_keys"), sshKeys, 0600)
if err != nil {
return fmt.Errorf("Failed to write ssh keys: %s", err)
}

View File

@ -129,7 +129,7 @@ func makeDevLinks() error {
}
}
devs, err := ioutil.ReadDir("/sys/class/block")
devs, err := os.ReadDir("/sys/class/block")
if err != nil {
return err
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -54,13 +53,13 @@ func splitKv(r rune) bool {
func main() {
flag.Parse()
files, err := ioutil.ReadDir(configDir)
files, err := os.ReadDir(configDir)
if err != nil {
log.Fatalf("Cannot read directory %s: %s", configDir, err)
}
for _, file := range files {
contents, err := ioutil.ReadFile(filepath.Join(configDir, file.Name()))
contents, err := os.ReadFile(filepath.Join(configDir, file.Name()))
if err != nil {
log.Fatalf("Cannot read file %s: %s", file.Name(), err)
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -48,13 +47,13 @@ func sysfs(line []byte) error {
func main() {
flag.Parse()
files, err := ioutil.ReadDir(configDir)
files, err := os.ReadDir(configDir)
if err != nil {
log.Fatalf("Cannot read directory %s: %s", configDir, err)
}
for _, file := range files {
contents, err := ioutil.ReadFile(filepath.Join(configDir, file.Name()))
contents, err := os.ReadFile(filepath.Join(configDir, file.Name()))
if err != nil {
log.Fatalf("Cannot read file %s: %s", file.Name(), err)
}