all: replace uses of the deprecated ioutil

Now that we require Go 1.16, we can simplify code by removing ioutil.
pull/280/head
Daniel Martí 3 years ago committed by Andrew LeFevre
parent a328a487f8
commit 5d74ab07f5

@ -4,7 +4,6 @@
package main package main
import ( import (
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -23,13 +22,7 @@ import (
// At the moment, each iteration takes 1-2s on a laptop, so we can't make the // At the moment, each iteration takes 1-2s on a laptop, so we can't make the
// benchmark include any more features unless we make it significantly faster. // benchmark include any more features unless we make it significantly faster.
func BenchmarkBuild(b *testing.B) { func BenchmarkBuild(b *testing.B) {
tdir, err := ioutil.TempDir("", "garble-bench") garbleBin := filepath.Join(b.TempDir(), "garble")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(tdir)
garbleBin := filepath.Join(tdir, "garble")
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
garbleBin += ".exe" garbleBin += ".exe"
} }

@ -17,7 +17,6 @@ import (
"go/token" "go/token"
"go/types" "go/types"
"io" "io"
"io/ioutil"
"log" "log"
mathrand "math/rand" mathrand "math/rand"
"os" "os"
@ -444,7 +443,7 @@ func transformAsm(args []string) ([]string, error) {
// Read the entire file into memory. // Read the entire file into memory.
// If we find issues with large files, we can use bufio. // If we find issues with large files, we can use bufio.
content, err := ioutil.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -483,7 +482,7 @@ func transformAsm(args []string) ([]string, error) {
} }
// TODO: do the original asm filenames ever matter? // TODO: do the original asm filenames ever matter?
tempFile, err := ioutil.TempFile(sharedTempDir, "*.s") tempFile, err := os.CreateTemp(sharedTempDir, "*.s")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -686,7 +685,7 @@ func transformCompile(args []string) ([]string, error) {
// } // }
// } // }
tempFile, err := ioutil.TempFile(sharedTempDir, name+".*.go") tempFile, err := os.CreateTemp(sharedTempDir, name+".*.go")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -881,7 +880,7 @@ func processImportCfg(flags []string) (newImportCfg string, _ error) {
if importCfg == "" { if importCfg == "" {
return "", fmt.Errorf("could not find -importcfg argument") return "", fmt.Errorf("could not find -importcfg argument")
} }
data, err := ioutil.ReadFile(importCfg) data, err := os.ReadFile(importCfg)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -930,7 +929,7 @@ func processImportCfg(flags []string) (newImportCfg string, _ error) {
// This is mainly replacing the obfuscated paths. // This is mainly replacing the obfuscated paths.
// Note that we range over maps, so this is non-deterministic, but that // Note that we range over maps, so this is non-deterministic, but that
// should not matter as the file is treated like a lookup table. // should not matter as the file is treated like a lookup table.
newCfg, err := ioutil.TempFile(sharedTempDir, "importcfg") newCfg, err := os.CreateTemp(sharedTempDir, "importcfg")
if err != nil { if err != nil {
return "", err return "", err
} }

@ -8,7 +8,6 @@ import (
"encoding/gob" "encoding/gob"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -65,7 +64,7 @@ func saveSharedCache() (string, error) {
if cache == nil { if cache == nil {
panic("saving a missing cache?") panic("saving a missing cache?")
} }
dir, err := ioutil.TempDir("", "garble-shared") dir, err := os.MkdirTemp("", "garble-shared")
if err != nil { if err != nil {
return "", err return "", err
} }

Loading…
Cancel
Save