From 4359978ef22a22ddd5a19adf18cbc80cb44244fb Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 23 Feb 2023 14:28:18 +0100 Subject: all: ioutil is deprecated in go1.19 (#3718) --- pkg/osutil/fileutil.go | 3 +-- pkg/osutil/osutil.go | 9 ++++----- pkg/osutil/osutil_linux.go | 3 +-- pkg/osutil/osutil_unix.go | 3 +-- 4 files changed, 7 insertions(+), 11 deletions(-) (limited to 'pkg/osutil') diff --git a/pkg/osutil/fileutil.go b/pkg/osutil/fileutil.go index f3bcf0e30..966560649 100644 --- a/pkg/osutil/fileutil.go +++ b/pkg/osutil/fileutil.go @@ -6,7 +6,6 @@ package osutil import ( "fmt" "io" - "io/ioutil" "os" ) @@ -54,7 +53,7 @@ func Rename(oldFile, newFile string) error { // WriteTempFile writes data to a temp file and returns its name. func WriteTempFile(data []byte) (string, error) { // Note: pkg/report knows about "syzkaller" prefix as it appears in crashes as process name. - f, err := ioutil.TempFile("", "syzkaller") + f, err := os.CreateTemp("", "syzkaller") if err != nil { return "", fmt.Errorf("failed to create a temp file: %v", err) } diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 6ac96b344..ba1fb8729 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -9,7 +9,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -235,7 +234,7 @@ func CopyDirRecursively(srcDir, dstDir string) error { if err := MkdirAll(dstDir); err != nil { return err } - files, err := ioutil.ReadDir(srcDir) + files, err := os.ReadDir(srcDir) if err != nil { return err } @@ -273,7 +272,7 @@ func MkdirAll(dir string) error { } func WriteFile(filename string, data []byte) error { - return ioutil.WriteFile(filename, data, DefaultFilePerm) + return os.WriteFile(filename, data, DefaultFilePerm) } func WriteGzipStream(filename string, reader io.Reader) error { @@ -290,13 +289,13 @@ func WriteGzipStream(filename string, reader io.Reader) error { func WriteExecFile(filename string, data []byte) error { os.Remove(filename) - return ioutil.WriteFile(filename, data, DefaultExecPerm) + return os.WriteFile(filename, data, DefaultExecPerm) } // TempFile creates a unique temp filename. // Note: the file already exists when the function returns. func TempFile(prefix string) (string, error) { - f, err := ioutil.TempFile("", prefix) + f, err := os.CreateTemp("", prefix) if err != nil { return "", fmt.Errorf("failed to create temp file: %v", err) } diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go index fb7a0670c..6585713ac 100644 --- a/pkg/osutil/osutil_linux.go +++ b/pkg/osutil/osutil_linux.go @@ -5,7 +5,6 @@ package osutil import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -20,7 +19,7 @@ import ( // RemoveAll is similar to os.RemoveAll, but can handle more cases. func RemoveAll(dir string) error { - files, _ := ioutil.ReadDir(dir) + files, _ := os.ReadDir(dir) for _, f := range files { name := filepath.Join(dir, f.Name()) if f.IsDir() { diff --git a/pkg/osutil/osutil_unix.go b/pkg/osutil/osutil_unix.go index 33cb09e40..5563fb5fd 100644 --- a/pkg/osutil/osutil_unix.go +++ b/pkg/osutil/osutil_unix.go @@ -9,7 +9,6 @@ package osutil import ( "fmt" "io" - "io/ioutil" "os" "os/signal" "path/filepath" @@ -54,7 +53,7 @@ func ProcessTempDir(where string) (string, error) { } func cleanupTempDir(path, pidfile string) bool { - data, err := ioutil.ReadFile(pidfile) + data, err := os.ReadFile(pidfile) if err == nil && len(data) > 0 { pid, err := strconv.Atoi(string(data)) if err == nil && pid > 1 { -- cgit mrf-deployment