tree-wide: rewrite ioutil functions to their replacements
The ioutil package has been deprecated in Go 1.16 [1]. This CL removes
all our own users of that package and rewrites them to use their
replacements in the os package. I initially wanted to do this with a
gofix but because all replacements were signature-compatible I just
did it with a few string replaces and then ran goimports to fix up the
imports.
I intentionally didn't rewrite the patches as that would require a
different process and is IMO of less value.
[1] https://github.com/golang/go/issues/42026
Change-Id: Iac6663a1f1ee49f9b1c6e4b3d97e73f2c3b54a13
Reviewed-on: https://review.monogon.dev/c/monogon/+/449
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/build/bazel_cc_fix/main.go b/build/bazel_cc_fix/main.go
index 1be47f7..611f1eb 100644
--- a/build/bazel_cc_fix/main.go
+++ b/build/bazel_cc_fix/main.go
@@ -34,7 +34,6 @@
"encoding/json"
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"path/filepath"
@@ -179,7 +178,7 @@
func (m rewriteMetadata) fixIncludesAndGetRefs(filePath string, quoteIncludes, systemIncludes []string, spec *ccfixspec.CCFixSpec, isGeneratedFile map[string]bool) []string {
meta, ok := m[filePath]
if !ok {
- cSourceRaw, err := ioutil.ReadFile(filePath)
+ cSourceRaw, err := os.ReadFile(filePath)
if err != nil {
log.Printf("failed to open source file: %v", err)
return nil
@@ -328,7 +327,7 @@
if err := json.NewDecoder(compilationDBFile).Decode(&compilationDB); err != nil {
log.Fatalf("failed to read compilation db: %v", err)
}
- specRaw, err := ioutil.ReadFile(*specPath)
+ specRaw, err := os.ReadFile(*specPath)
var spec ccfixspec.CCFixSpec
if err := proto.UnmarshalText(string(specRaw), &spec); err != nil {
log.Fatalf("failed to load spec: %v", err)
diff --git a/build/fietsje/deps_monogon.go b/build/fietsje/deps_monogon.go
index 54e7d94..0abcd66 100644
--- a/build/fietsje/deps_monogon.go
+++ b/build/fietsje/deps_monogon.go
@@ -7,7 +7,7 @@
import (
"bytes"
"fmt"
- "io/ioutil"
+ "os"
)
// Monogon runs fietsje for all Monogon transitive dependencies.
@@ -134,7 +134,7 @@
return fmt.Errorf("could not render deps: %w", err)
}
- err = ioutil.WriteFile(repositoriesBzlPath, buf.Bytes(), 0666)
+ err = os.WriteFile(repositoriesBzlPath, buf.Bytes(), 0666)
if err != nil {
return fmt.Errorf("could not write deps: %w", err)
}
diff --git a/build/fietsje/shelf.go b/build/fietsje/shelf.go
index 807ee44..c377186 100644
--- a/build/fietsje/shelf.go
+++ b/build/fietsje/shelf.go
@@ -19,7 +19,6 @@
import (
"bytes"
"fmt"
- "io/ioutil"
"log"
"os"
"sort"
@@ -69,7 +68,7 @@
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Printf("Creating new shelf file at %q, this run will be slow.", path)
} else {
- data, err = ioutil.ReadFile(path)
+ data, err = os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("could not read shelf: %v", err)
}
@@ -154,7 +153,7 @@
}
// And write it out.
- err = ioutil.WriteFile(s.path, buf.Bytes(), 0644)
+ err = os.WriteFile(s.path, buf.Bytes(), 0644)
if err != nil {
return fmt.Errorf("could not write shelf: %v", err)
}
diff --git a/build/fietsje/transitive.go b/build/fietsje/transitive.go
index 2e2a9f7..6ffd594 100644
--- a/build/fietsje/transitive.go
+++ b/build/fietsje/transitive.go
@@ -18,7 +18,6 @@
import (
"fmt"
- "io/ioutil"
"log"
"os"
"strings"
@@ -61,7 +60,7 @@
read := func(p string) []byte {
full := fmt.Sprintf("%s/%s", path, p)
- data, err := ioutil.ReadFile(full)
+ data, err := os.ReadFile(full)
if err != nil {
panic(fmt.Sprintf("reading file %q: %v", full, err))
}
diff --git a/build/static_binary_tarball/main.go b/build/static_binary_tarball/main.go
index 72ee5d0..b7b3612 100644
--- a/build/static_binary_tarball/main.go
+++ b/build/static_binary_tarball/main.go
@@ -20,7 +20,6 @@
"archive/tar"
"flag"
"io"
- "io/ioutil"
"log"
"os"
"path"
@@ -39,7 +38,7 @@
func main() {
flag.Parse()
var spec spec.Spec
- specRaw, err := ioutil.ReadFile(*specPath)
+ specRaw, err := os.ReadFile(*specPath)
if err != nil {
log.Fatalf("failed to open spec file: %v", err)
}