*: remove io/ioutil uses

Close #1764.
This commit is contained in:
Anna Shaleva 2022-02-22 19:27:32 +03:00 committed by AnnaShaleva
parent df3eb76aa2
commit 2096ad6e81
32 changed files with 134 additions and 159 deletions

View file

@ -9,7 +9,6 @@ import (
"go/token"
"go/types"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -156,7 +155,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) {
case string:
buf = []byte(s)
case io.Reader:
buf, err = ioutil.ReadAll(s)
buf, err = io.ReadAll(s)
if err != nil {
return nil, err
}
@ -164,10 +163,7 @@ func getBuildInfo(name string, src interface{}) (*buildInfo, error) {
panic(fmt.Sprintf("unsupported src type: %T", s))
}
if strings.HasPrefix(runtime.Version(), "go1.15") {
dir, err = ioutil.TempDir("", "*")
if err != nil {
return nil, err
}
dir = os.TempDir()
name = filepath.Join(dir, filepath.Base(name))
absName = name
names = append(names, "file="+name)
@ -259,7 +255,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
return nil, fmt.Errorf("error while serializing .nef file: %w", err)
}
out := fmt.Sprintf("%s.%s", o.Outfile, o.Ext)
err = ioutil.WriteFile(out, bytes, os.ModePerm)
err = os.WriteFile(out, bytes, os.ModePerm)
if err != nil {
return f.Script, err
}
@ -289,7 +285,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
if err != nil {
return f.Script, err
}
if err := ioutil.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
if err := os.WriteFile(o.DebugInfo, data, os.ModePerm); err != nil {
return f.Script, err
}
}
@ -311,7 +307,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("can't marshal bindings configuration: %w", err)
}
err = ioutil.WriteFile(o.BindingsFile, data, os.ModePerm)
err = os.WriteFile(o.BindingsFile, data, os.ModePerm)
if err != nil {
return nil, fmt.Errorf("can't write bindings configuration: %w", err)
}
@ -326,7 +322,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
if err != nil {
return f.Script, fmt.Errorf("failed to marshal manifest to JSON: %w", err)
}
return f.Script, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm)
return f.Script, os.WriteFile(o.ManifestFile, mData, os.ModePerm)
}
return f.Script, nil

View file

@ -2,7 +2,6 @@ package compiler_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -49,7 +48,7 @@ func TestCompiler(t *testing.T) {
{
name: "TestCompile",
function: func(t *testing.T) {
infos, err := ioutil.ReadDir(examplePath)
infos, err := os.ReadDir(examplePath)
require.NoError(t, err)
for _, info := range infos {
if !info.IsDir() {
@ -66,7 +65,7 @@ func TestCompiler(t *testing.T) {
{
name: "TestCompileAndSave",
function: func(t *testing.T) {
infos, err := ioutil.ReadDir(exampleCompilePath)
infos, err := os.ReadDir(exampleCompilePath)
require.NoError(t, err)
err = os.MkdirAll(exampleSavePath, os.ModePerm)
require.NoError(t, err)