Skip to content

Commit 79c5ac1

Browse files
authored
many: remove usages of deprecated io/ioutil package (canonical#13768)
* many: remove usages of deprecated io/ioutil package Signed-off-by: Miguel Pires <miguel.pires@canonical.com> * .golangci.yml: remove errcheck ignore rule for io/ioutil Signed-off-by: Miguel Pires <miguel.pires@canonical.com> * run-checks: prevent new usages of io/ioutil Signed-off-by: Miguel Pires <miguel.pires@canonical.com> --------- Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
1 parent 3307fea commit 79c5ac1

File tree

199 files changed

+730
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+730
-771
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ linters-settings:
8383
# [deprecated] comma-separated list of pairs of the form pkg:regex
8484
# the regex is used to ignore names within pkg. (default "fmt:.*").
8585
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
86-
ignore: fmt:.*,io/ioutil:^Read.*
86+
ignore: fmt:.*
8787

8888
# path to a file containing a list of functions to exclude from checking
8989
# see https://github.com/kisielk/errcheck#excluding-functions for details

asserts/database_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"encoding/base64"
2626
"errors"
2727
"fmt"
28-
"io/ioutil"
2928
"os"
3029
"path/filepath"
3130
"regexp"
@@ -137,7 +136,7 @@ func (dbs *databaseSuite) TestImportKey(c *C) {
137136
c.Check(info.Mode().Perm(), Equals, os.FileMode(0600)) // secret
138137
// too much "clear box" testing? ok at least until we have
139138
// more functionality
140-
privKey, err := ioutil.ReadFile(keyPath)
139+
privKey, err := os.ReadFile(keyPath)
141140
c.Assert(err, IsNil)
142141

143142
privKeyFromDisk, err := asserts.DecodePrivateKeyInTest(privKey)

asserts/fsentryutils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package asserts
2121

2222
import (
2323
"fmt"
24-
"io/ioutil"
2524
"os"
2625
"path/filepath"
2726

@@ -66,7 +65,7 @@ func entryExists(top string, subpath ...string) bool {
6665

6766
func readEntry(top string, subpath ...string) ([]byte, error) {
6867
fpath := filepath.Join(top, filepath.Join(subpath...))
69-
return ioutil.ReadFile(fpath)
68+
return os.ReadFile(fpath)
7069
}
7170

7271
func removeEntry(top string, subpath ...string) error {

boot/flags.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package boot
2222
import (
2323
"encoding/json"
2424
"fmt"
25-
"io/ioutil"
2625
"os"
2726
"path/filepath"
2827
"strings"
@@ -224,7 +223,7 @@ func BootFlags(dev snap.Device) ([]string, error) {
224223
// bootenv are for this boot or the next one, but the initramfs will always
225224
// copy the flags that were set into /run, so we always know the current
226225
// boot's flags are written in /run
227-
b, err := ioutil.ReadFile(snapBootFlagsFile)
226+
b, err := os.ReadFile(snapBootFlagsFile)
228227
if err != nil {
229228
return nil, err
230229
}
@@ -314,7 +313,7 @@ func HostUbuntuDataForMode(mode string, mod gadget.Model) ([]string, error) {
314313
// host mount is snap-bootstrap's /run/snapd/snap-bootstrap/degraded.json, so
315314
// we have to go parse that
316315
degradedJSONFile := filepath.Join(dirs.SnapBootstrapRunDir, "degraded.json")
317-
b, err := ioutil.ReadFile(degradedJSONFile)
316+
b, err := os.ReadFile(degradedJSONFile)
318317
if err != nil {
319318
return nil, err
320319
}

boot/modeenv_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"bytes"
2424
"encoding/json"
2525
"fmt"
26-
"io/ioutil"
2726
"os"
2827
"path/filepath"
2928
"strings"
@@ -209,7 +208,7 @@ base_status=try
209208
err = dupDiskModeenv.Write()
210209
c.Assert(err, IsNil)
211210
c.Assert(dirs.SnapModeenvFileUnder(s.tmpdir), testutil.FilePresent)
212-
origBytes, err := ioutil.ReadFile(dirs.SnapModeenvFileUnder(s.tmpdir) + ".orig")
211+
origBytes, err := os.ReadFile(dirs.SnapModeenvFileUnder(s.tmpdir) + ".orig")
213212
c.Assert(err, IsNil)
214213
// the files should be the same
215214
c.Assert(dirs.SnapModeenvFileUnder(s.tmpdir), testutil.FileEquals, string(origBytes))

bootloader/assets/genasset/main_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package main_test
2222
import (
2323
"bytes"
2424
"fmt"
25-
"io/ioutil"
2625
"os"
2726
"os/exec"
2827
"path/filepath"
@@ -84,7 +83,7 @@ func (s *generateAssetsTestSuite) TestSimpleAsset(c *C) {
8483
c.Assert(err, IsNil)
8584
err = generate.Run("asset-name", filepath.Join(d, "in"), filepath.Join(d, "out"))
8685
c.Assert(err, IsNil)
87-
data, err := ioutil.ReadFile(filepath.Join(d, "out"))
86+
data, err := os.ReadFile(filepath.Join(d, "out"))
8887
c.Assert(err, IsNil)
8988

9089
const exp = `// -*- Mode: Go; indent-tabs-mode: t -*-

bootloader/assets/grub_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ package assets_test
2222
import (
2323
"bytes"
2424
"fmt"
25-
"io/ioutil"
25+
"os"
2626
"testing"
2727

2828
. "gopkg.in/check.v1"
@@ -160,7 +160,7 @@ func (s *grubAssetsTestSuite) TestGrubAssetsWereRegenerated(c *C) {
160160
} {
161161
assetData := assets.Internal(tc.asset)
162162
c.Assert(assetData, NotNil)
163-
data, err := ioutil.ReadFile(tc.file)
163+
data, err := os.ReadFile(tc.file)
164164
c.Assert(err, IsNil)
165165
c.Check(assetData, DeepEquals, data, Commentf("asset %q has not been updated", tc.asset))
166166
}

bootloader/efi/efi.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"errors"
2727
"fmt"
2828
"io"
29-
"io/ioutil"
3029
"os"
3130
"path/filepath"
3231
"unicode/utf16"
@@ -113,7 +112,7 @@ func ReadVarBytes(name string) ([]byte, VariableAttr, error) {
113112
return nil, 0, cannotReadError(name, err)
114113
}
115114
defer varf.Close()
116-
b, err := ioutil.ReadAll(varf)
115+
b, err := io.ReadAll(varf)
117116
if err != nil {
118117
return nil, 0, cannotReadError(name, err)
119118
}
@@ -173,7 +172,7 @@ func MockVars(vars map[string][]byte, attrs map[string]VariableAttr) (restore fu
173172
if !ok {
174173
attr = VariableRuntimeAccess | VariableBootServiceAccess
175174
}
176-
return ioutil.NopCloser(bytes.NewBuffer(val)), attr, int64(len(val)), nil
175+
return io.NopCloser(bytes.NewBuffer(val)), attr, int64(len(val)), nil
177176
}
178177
return nil, 0, 0, fmt.Errorf("EFI variable %s not mocked", name)
179178
}

bootloader/grubenv/grubenv.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package grubenv
2222
import (
2323
"bytes"
2424
"fmt"
25-
"io/ioutil"
2625
"os"
2726

2827
"github.com/snapcore/snapd/strutil"
@@ -56,7 +55,7 @@ func (g *Env) Set(key, value string) {
5655
}
5756

5857
func (g *Env) Load() error {
59-
buf, err := ioutil.ReadFile(g.path)
58+
buf, err := os.ReadFile(g.path)
6059
if err != nil {
6160
return err
6261
}

bootloader/lk.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package bootloader
2222
import (
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"os"
2726
"path/filepath"
2827

@@ -444,7 +443,7 @@ func (l *lk) ExtractKernelAssets(s snap.PlaceInfo, snapf snap.Container) error {
444443
// this is live system, extracted bootimg needs to be flashed to
445444
// free bootimg partition and env has to be updated with
446445
// new kernel snap to bootimg partition mapping
447-
tmpdir, err := ioutil.TempDir("", "bootimg")
446+
tmpdir, err := os.MkdirTemp("", "bootimg")
448447
if err != nil {
449448
return fmt.Errorf("cannot create temp directory: %v", err)
450449
}

0 commit comments

Comments
 (0)