all: replace ioutil.{Read,Write}File with os.{Read,Write}File
sbinet opened this issue · 1 comments
sbinet commented
when we drop support of Go-1.15, we should replace all uses of ioutil.{Read,Write}File
with os.{Read,Write}File
.
$> git grep ReadFile
cmpimg/checkplot.go:69: got, err := ioutil.ReadFile(path)
cmpimg/checkplot.go:75: want, err := ioutil.ReadFile(golden)
cmpimg/cmpimg_test.go:21: got, err := ioutil.ReadFile(filepath.FromSlash("./testdata/failed_input.png"))
cmpimg/cmpimg_test.go:25: want, err := ioutil.ReadFile(filepath.FromSlash("./testdata/good_golden.png"))
cmpimg/cmpimg_test.go:57: got, err := ioutil.ReadFile("testdata/approx_got_golden.png")
cmpimg/cmpimg_test.go:72: got, err := ioutil.ReadFile("testdata/approx_got_golden.png")
cmpimg/cmpimg_test.go:77: want, err := ioutil.ReadFile("testdata/approx_want_golden.png")
plot_test.go:65: want, err := ioutil.ReadFile("testdata/legendAlignment_golden.png")
plot_test.go:194: want, err := ioutil.ReadFile("testdata/glyphbox_golden.png")
vg/fonts/mk-fonts.go:62: enc, err := ioutil.ReadFile(filepath.Join(fontsDir, "cp1252.map"))
vg/vg_test.go:66: want, err := ioutil.ReadFile(name)
vg/vgimg/vgimg_test.go:47: want, err := ioutil.ReadFile("testdata/issue179_golden.jpg")
vg/vgimg/vgimg_test.go:132: want, err := ioutil.ReadFile("testdata/issue540_golden.png")
vg/vgimg/vgimg_test.go:137: got, err := ioutil.ReadFile("testdata/issue540.png")
vg/vgpdf/vgpdf.go:465: z, err := ioutil.ReadFile(filepath.Join(outdir, "font.z"))
vg/vgpdf/vgpdf.go:472: j, err := ioutil.ReadFile(filepath.Join(outdir, "font.json"))
vg/vgpdf/vgpdf_test.go:72: want, err := ioutil.ReadFile(tc.name)
vg/vgpdf/vgpdf_test.go:134: want, err := ioutil.ReadFile("testdata/arc_golden.pdf")
vg/vgpdf/vgpdf_test.go:139: got, err := ioutil.ReadFile("testdata/arc.pdf")
vg/vgpdf/vgpdf_test.go:194: want, err := ioutil.ReadFile("testdata/issue540_golden.pdf")
vg/vgpdf/vgpdf_test.go:199: got, err := ioutil.ReadFile("testdata/issue540.pdf")
vg/vgpdf/vgpdf_test.go:246: raw, err := ioutil.ReadFile("../../plotter/testdata/gopher.png")
vg/vgsvg/vgsvg_test.go:44: want, err := ioutil.ReadFile("testdata/scatter_golden.svg")
vg/vgsvg/vgsvg_test.go:94: want, err := ioutil.ReadFile("testdata/scatter_line_golden.svg")
$> git grep WriteFile
plot_test.go:53: err := ioutil.WriteFile("testdata/legendAlignment_golden.png", buf.Bytes(), 0o644)
plot_test.go:60: err := ioutil.WriteFile("testdata/legendAlignment.png", buf.Bytes(), 0o644)
plot_test.go:180: err = ioutil.WriteFile("testdata/glyphbox.png", buf.Bytes(), 0644)
plot_test.go:187: err := ioutil.WriteFile("testdata/glyphbox_golden.png", buf.Bytes(), 0o644)
vg/fonts/liberation_fonts_generated.go:610: err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
vg/fonts/mk-fonts.go:66: err = ioutil.WriteFile(filepath.Join(tmpdir, fontsName, "cp1252.map"), enc, 0644)
vg/vg_test.go:78: _ = ioutil.WriteFile(got, buf.Bytes(), 0644)
vg/vgimg/vgimg_test.go:57: _ = ioutil.WriteFile("testdata/issue179.jpg", b.Bytes(), 0644)
vg/vgpdf/vgpdf.go:449: err = ioutil.WriteFile(fname, font, 0644)
vg/vgpdf/vgpdf.go:454: err = ioutil.WriteFile(encname, encoding, 0644)
vg/vgpdf/vgpdf_test.go:65: err = ioutil.WriteFile(tc.name, buf.Bytes(), 0o644)
vg/vgsvg/vgsvg_test.go:87: err = ioutil.WriteFile("testdata/scatter_line_golden.svg", b.Bytes(), 0o644)
sbinet commented
this can be addressed with:
$> eg -t write_file_template.go ./...
$> eg -t read_file_template.go ./...
with:
// read_file_template.go
package P
import (
"io/ioutil"
"os"
)
func before(s string) ([]byte, error) { return ioutil.ReadFile(s) }
func after(s string) ([]byte, error) { return os.ReadFile(s) }
// write_file_template.go
package P
import (
"io/ioutil"
"os"
)
func before(filename string, data []byte, perm os.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
}
func after(filename string, data []byte, perm os.FileMode) error {
return os.WriteFile(filename, data, perm)
}