mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-04 08:26:42 +00:00
Remove 99% of deprecated ioutil usage
Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user