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/pkg/efivarfs/efivarfs.go b/metropolis/pkg/efivarfs/efivarfs.go
index fc6100e..e731069 100644
--- a/metropolis/pkg/efivarfs/efivarfs.go
+++ b/metropolis/pkg/efivarfs/efivarfs.go
@@ -22,7 +22,6 @@
import (
"bytes"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -64,7 +63,7 @@
func ReadLoaderDevicePartUUID() (string, error) {
// Read the EFI variable file containing the ESP UUID.
espUuidPath := filepath.Join(Path, "LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f")
- efiVar, err := ioutil.ReadFile(espUuidPath)
+ efiVar, err := os.ReadFile(espUuidPath)
if err != nil {
return "", fmt.Errorf("couldn't read the LoaderDevicePartUUID file at %q: %w", espUuidPath, err)
}
@@ -98,7 +97,7 @@
if err != nil {
return -1, fmt.Errorf("while marshaling the EFI boot entry: %w", err)
}
- if err := ioutil.WriteFile(ep, bem, 0644); err != nil {
+ if err := os.WriteFile(ep, bem, 0644); err != nil {
return -1, fmt.Errorf("while creating a boot entry variable: %w", err)
}
return n, nil
@@ -108,7 +107,7 @@
// specified in ord. It may return an io error.
func SetBootOrder(ord *BootOrder) error {
op := filepath.Join(Path, fmt.Sprintf("BootOrder-%s", GlobalGuid))
- if err := ioutil.WriteFile(op, ord.Marshal(), 0644); err != nil {
+ if err := os.WriteFile(op, ord.Marshal(), 0644); err != nil {
return fmt.Errorf("while creating a boot order variable: %w", err)
}
return nil