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/metropolis/node/build/genosrelease/main.go b/metropolis/node/build/genosrelease/main.go
index ad6e3e2..adb8202 100644
--- a/metropolis/node/build/genosrelease/main.go
+++ b/metropolis/node/build/genosrelease/main.go
@@ -23,7 +23,6 @@
import (
"flag"
"fmt"
- "io/ioutil"
"os"
"strings"
@@ -40,7 +39,7 @@
func main() {
flag.Parse()
- statusFileContent, err := ioutil.ReadFile(*flagStatusFile)
+ statusFileContent, err := os.ReadFile(*flagStatusFile)
if err != nil {
fmt.Printf("Failed to open bazel workspace status file: %v\n", err)
os.Exit(1)
@@ -73,7 +72,7 @@
fmt.Printf("Failed to encode os-release file: %v\n", err)
os.Exit(1)
}
- if err := ioutil.WriteFile(*flagOutFile, []byte(osReleaseContent), 0644); err != nil {
+ if err := os.WriteFile(*flagOutFile, []byte(osReleaseContent), 0644); err != nil {
fmt.Printf("Failed to write os-release file: %v\n", err)
os.Exit(1)
}
diff --git a/metropolis/node/build/mkerofs/main.go b/metropolis/node/build/mkerofs/main.go
index ea89d67..d4e9d4d 100644
--- a/metropolis/node/build/mkerofs/main.go
+++ b/metropolis/node/build/mkerofs/main.go
@@ -22,7 +22,6 @@
import (
"flag"
"io"
- "io/ioutil"
"log"
"os"
"path"
@@ -132,7 +131,7 @@
func main() {
flag.Parse()
- specRaw, err := ioutil.ReadFile(*specPath)
+ specRaw, err := os.ReadFile(*specPath)
if err != nil {
log.Fatalf("failed to open spec: %v", err)
}
diff --git a/metropolis/node/build/mkimage/osimage/osimage.go b/metropolis/node/build/mkimage/osimage/osimage.go
index 4ad2d5f..2f000a6 100644
--- a/metropolis/node/build/mkimage/osimage/osimage.go
+++ b/metropolis/node/build/mkimage/osimage/osimage.go
@@ -21,7 +21,6 @@
import (
"fmt"
"io"
- "io/ioutil"
"os"
diskfs "github.com/diskfs/go-diskfs"
@@ -58,7 +57,7 @@
// If this is streamed (e.g. using io.Copy) it exposes a bug in diskfs, so
// do it in one go.
// TODO(mateusz@monogon.tech): Investigate the bug.
- data, err := ioutil.ReadAll(src)
+ data, err := io.ReadAll(src)
if err != nil {
return fmt.Errorf("while reading %q: %w", src, err)
}