From 241f89fd3a653380d5d75f0fa33e05218373be36 Mon Sep 17 00:00:00 2001 From: ginglis13 Date: Sat, 14 Oct 2023 10:19:38 -0700 Subject: [PATCH] refactor: rm io/ioutil funcs io/ioutil has been deprecated since Go 1.16 https://pkg.go.dev/io/ioutil Signed-off-by: ginglis13 --- builder/env.go | 5 ++--- loader/goroot.go | 5 ++--- main.go | 11 ++++++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/builder/env.go b/builder/env.go index d60861317d..726450b3a0 100644 --- a/builder/env.go +++ b/builder/env.go @@ -3,7 +3,6 @@ package builder import ( "errors" "io/fs" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -49,11 +48,11 @@ func getClangHeaderPath(TINYGOROOT string) string { // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ llvmRoot := filepath.Dir(filepath.Dir(binpath)) clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") - dirs64, err64 := ioutil.ReadDir(clangVersionRoot) + dirs64, err64 := os.ReadDir(clangVersionRoot) // Example include path: // /usr/lib/llvm-9/lib/clang/9.0.1/include/ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") - dirs32, err32 := ioutil.ReadDir(clangVersionRoot) + dirs32, err32 := os.ReadDir(clangVersionRoot) if err64 != nil && err32 != nil { // Unexpected. continue diff --git a/loader/goroot.go b/loader/goroot.go index c1479b642f..0da8afa0c7 100644 --- a/loader/goroot.go +++ b/loader/goroot.go @@ -18,7 +18,6 @@ import ( "errors" "io" "io/fs" - "io/ioutil" "os" "os/exec" "path" @@ -157,7 +156,7 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool) // Add files from TinyGo. tinygoDir := filepath.Join(tinygoSrc, dir) - tinygoEntries, err := ioutil.ReadDir(tinygoDir) + tinygoEntries, err := os.ReadDir(tinygoDir) if err != nil { return nil, err } @@ -177,7 +176,7 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool) // Add all directories from $GOROOT that are not part of the TinyGo // overrides. goDir := filepath.Join(goSrc, dir) - goEntries, err := ioutil.ReadDir(goDir) + goEntries, err := os.ReadDir(goDir) if err != nil { return nil, err } diff --git a/main.go b/main.go index 0a8a652b74..b374d3af65 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,6 @@ import ( "go/scanner" "go/types" "io" - "io/ioutil" "os" "os/exec" "os/signal" @@ -1741,14 +1740,20 @@ func main() { handleCompilerError(err) case "targets": dir := filepath.Join(goenv.Get("TINYGOROOT"), "targets") - entries, err := ioutil.ReadDir(dir) + entries, err := os.ReadDir(dir) if err != nil { fmt.Fprintln(os.Stderr, "could not list targets:", err) os.Exit(1) return } for _, entry := range entries { - if !entry.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") { + entryInfo, err := entry.Info() + if err != nil { + fmt.Fprintln(os.Stderr, "could not get entry info:", err) + os.Exit(1) + return + } + if !entryInfo.Mode().IsRegular() || !strings.HasSuffix(entry.Name(), ".json") { // Only inspect JSON files. continue }