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
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -23,13 +22,7 @@ import (
// 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.
func BenchmarkBuild(b *testing.B) {
tdir, err := ioutil.TempDir("", "garble-bench")
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(tdir)
garbleBin := filepath.Join(tdir, "garble")
garbleBin := filepath.Join(b.TempDir(), "garble")
if runtime.GOOS == "windows" {
garbleBin += ".exe"
}

@ -17,7 +17,6 @@ import (
"go/token"
"go/types"
"io"
"io/ioutil"
"log"
mathrand "math/rand"
"os"
@ -444,7 +443,7 @@ func transformAsm(args []string) ([]string, error) {
// Read the entire file into memory.
// If we find issues with large files, we can use bufio.
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return nil, err
}
@ -483,7 +482,7 @@ func transformAsm(args []string) ([]string, error) {
}
// TODO: do the original asm filenames ever matter?
tempFile, err := ioutil.TempFile(sharedTempDir, "*.s")
tempFile, err := os.CreateTemp(sharedTempDir, "*.s")
if err != nil {
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 {
return nil, err
}
@ -881,7 +880,7 @@ func processImportCfg(flags []string) (newImportCfg string, _ error) {
if importCfg == "" {
return "", fmt.Errorf("could not find -importcfg argument")
}
data, err := ioutil.ReadFile(importCfg)
data, err := os.ReadFile(importCfg)
if err != nil {
return "", err
}
@ -930,7 +929,7 @@ func processImportCfg(flags []string) (newImportCfg string, _ error) {
// This is mainly replacing the obfuscated paths.
// 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.
newCfg, err := ioutil.TempFile(sharedTempDir, "importcfg")
newCfg, err := os.CreateTemp(sharedTempDir, "importcfg")
if err != nil {
return "", err
}

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

Loading…
Cancel
Save