Skip to content

Commit 3b4ebc9

Browse files
committed
Migrate deprecated methods from ioutil package
1 parent 627267a commit 3b4ebc9

File tree

84 files changed

+200
-248
lines changed

Some content is hidden

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

84 files changed

+200
-248
lines changed

components/blobserve/cmd/root.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package cmd
77
import (
88
"encoding/json"
99
"fmt"
10-
"io/ioutil"
1110
"os"
1211

1312
"github.com/spf13/cobra"
@@ -61,7 +60,7 @@ type Config struct {
6160

6261
// getConfig loads and validates the configuration
6362
func getConfig(fn string) (*Config, error) {
64-
fc, err := ioutil.ReadFile(fn)
63+
fc, err := os.ReadFile(fn)
6564
if err != nil {
6665
return nil, err
6766
}

components/blobserve/pkg/blobserve/blobspace.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"context"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"net/http"
1413
"os"
1514
"os/exec"
@@ -77,7 +76,7 @@ func (b *diskBlobspace) collectGarbage(interval time.Duration) {
7776
totalSize int64
7877
)
7978

80-
files, err := ioutil.ReadDir(b.Location)
79+
files, err := os.ReadDir(b.Location)
8180
if err != nil {
8281
log.WithError(err).WithField("location", b.Location).Error("blobspace cannot list files in working area")
8382
}
@@ -141,18 +140,20 @@ type gcBlob struct {
141140
Size int64
142141
}
143142

144-
func getGCBlob(wd string, f os.FileInfo) (blob gcBlob) {
143+
func getGCBlob(wd string, f os.DirEntry) (blob gcBlob) {
144+
finfo, _ := f.Info()
145+
145146
fn := filepath.Join(wd, f.Name())
146147
blob = gcBlob{
147148
F: fn,
148-
LastUsed: f.ModTime(),
149+
LastUsed: finfo.ModTime(),
149150
Size: 0,
150151
}
151152
if _, err := os.Stat(fmt.Sprintf("%s.ready", fn)); os.IsNotExist(err) {
152153
return
153154
}
154155

155-
if rawSize, err := ioutil.ReadFile(fmt.Sprintf("%s.size", fn)); err == nil {
156+
if rawSize, err := os.ReadFile(fmt.Sprintf("%s.size", fn)); err == nil {
156157
if size, err := strconv.ParseInt(string(rawSize), 10, 64); err == nil {
157158
blob.Size = size
158159
}
@@ -174,7 +175,7 @@ func (b *diskBlobspace) Get(name string) (fs http.FileSystem, state blobstate) {
174175
return nil, blobUnready
175176
}
176177

177-
ioutil.WriteFile(fmt.Sprintf("%s.used", fn), nil, 0644)
178+
os.WriteFile(fmt.Sprintf("%s.used", fn), nil, 0644)
178179
return http.Dir(fn), blobReady
179180
}
180181

@@ -207,9 +208,9 @@ func (b *diskBlobspace) AddFromTar(ctx context.Context, name string, in io.Reade
207208
return xerrors.Errorf("cannot untar: %w: %s", err, string(out))
208209
}
209210

210-
ioutil.WriteFile(fmt.Sprintf("%s.size", fn), []byte(fmt.Sprintf("%d", cw.C)), 0644)
211-
ioutil.WriteFile(fmt.Sprintf("%s.used", fn), nil, 0644)
212-
ioutil.WriteFile(fmt.Sprintf("%s.ready", fn), nil, 0644)
211+
os.WriteFile(fmt.Sprintf("%s.size", fn), []byte(fmt.Sprintf("%d", cw.C)), 0644)
212+
os.WriteFile(fmt.Sprintf("%s.used", fn), nil, 0644)
213+
os.WriteFile(fmt.Sprintf("%s.ready", fn), nil, 0644)
213214

214215
return nil
215216
}

components/blobserve/pkg/blobserve/refstore_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"encoding/json"
1313
"fmt"
1414
"io"
15-
"io/ioutil"
1615
"net/http"
1716
"sync"
1817
"testing"
@@ -492,5 +491,5 @@ func (f *fakeFetcher) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.Read
492491
return nil, err
493492
}
494493

495-
return ioutil.NopCloser(bytes.NewReader(c)), nil
494+
return io.NopCloser(bytes.NewReader(c)), nil
496495
}

components/common-go/testing/fixtures.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/json"
1010
"flag"
1111
"fmt"
12-
"io/ioutil"
1312
"os"
1413
"path/filepath"
1514
"reflect"
@@ -48,7 +47,7 @@ func (ft *FixtureTest) Run() {
4847

4948
for _, fn := range fixtures {
5049
t.Run(fn, func(t *testing.T) {
51-
fd, err := ioutil.ReadFile(fn)
50+
fd, err := os.ReadFile(fn)
5251
if err != nil {
5352
t.Errorf("cannot read %s: %v", fn, err)
5453
return
@@ -89,7 +88,7 @@ func (ft *FixtureTest) Run() {
8988
goldenFilePath := fmt.Sprintf("%s.golden", strings.TrimSuffix(fn, filepath.Ext(fn)))
9089
if *update {
9190
if _, err := os.Stat(goldenFilePath); *force || os.IsNotExist(err) {
92-
err = ioutil.WriteFile(goldenFilePath, actual, 0644)
91+
err = os.WriteFile(goldenFilePath, actual, 0644)
9392
if err != nil {
9493
t.Errorf("cannot write gold standard %s: %v", goldenFilePath, err)
9594
return
@@ -101,7 +100,7 @@ func (ft *FixtureTest) Run() {
101100
}
102101
}
103102

104-
expected, err := ioutil.ReadFile(goldenFilePath)
103+
expected, err := os.ReadFile(goldenFilePath)
105104
if err != nil {
106105
t.Errorf("cannot read golden file %s: %v", goldenFilePath, err)
107106
return

components/content-service/cmd/root.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"crypto/x509"
1010
"encoding/json"
1111
"fmt"
12-
"io/ioutil"
1312
"os"
1413

1514
"github.com/spf13/cobra"
@@ -53,7 +52,7 @@ func Execute() {
5352
}
5453

5554
func getConfig() *config {
56-
ctnt, err := ioutil.ReadFile(configFile)
55+
ctnt, err := os.ReadFile(configFile)
5756
if err != nil {
5857
log.WithError(xerrors.Errorf("cannot read config: %w", err)).Error("cannot read configuration. Maybe missing --config?")
5958
os.Exit(1)
@@ -109,7 +108,7 @@ func (c *tlsConfig) ServerOption() (grpc.ServerOption, error) {
109108

110109
// Create a certificate pool from the certificate authority
111110
certPool := x509.NewCertPool()
112-
ca, err := ioutil.ReadFile(c.Authority)
111+
ca, err := os.ReadFile(c.Authority)
113112
if err != nil {
114113
return nil, xerrors.Errorf("cannot not read ca certificate: %w", err)
115114
}

components/content-service/pkg/archive/tar_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"archive/tar"
99
"bytes"
1010
"context"
11-
"io/ioutil"
1211
"os"
1312
"path/filepath"
1413
"syscall"
@@ -64,7 +63,7 @@ func TestExtractTarbal(t *testing.T) {
6463
tw.Flush()
6564
tw.Close()
6665

67-
wd, err := ioutil.TempDir("", "")
66+
wd, err := os.MkdirTemp("", "")
6867
defer os.RemoveAll(wd)
6968
if err != nil {
7069
t.Fatalf("cannot prepare test: %v", err)

components/content-service/pkg/git/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"bytes"
99
"context"
1010
"fmt"
11-
"io/ioutil"
11+
"io"
1212
"os"
1313
"os/exec"
1414
"path/filepath"
@@ -222,7 +222,7 @@ func (c *Client) Status(ctx context.Context) (res *Status, err error) {
222222
return nil, err
223223
}
224224
if gitout != nil {
225-
out, err := ioutil.ReadAll(bytes.NewReader(gitout))
225+
out, err := io.ReadAll(bytes.NewReader(gitout))
226226
if err != nil {
227227
return nil, xerrors.Errorf("cannot determine unpushed commits: %w", err)
228228
}

components/content-service/pkg/git/git_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package git
66

77
import (
88
"context"
9-
"io/ioutil"
109
"os"
1110
"path/filepath"
1211
"testing"
@@ -62,7 +61,7 @@ func TestGitStatus(t *testing.T) {
6261
if err := initFromRemote(ctx, c); err != nil {
6362
return err
6463
}
65-
if err := ioutil.WriteFile(filepath.Join(c.Location, "another-file"), []byte{}, 0755); err != nil {
64+
if err := os.WriteFile(filepath.Join(c.Location, "another-file"), []byte{}, 0755); err != nil {
6665
return err
6766
}
6867
return nil
@@ -83,7 +82,7 @@ func TestGitStatus(t *testing.T) {
8382
if err := initFromRemote(ctx, c); err != nil {
8483
return err
8584
}
86-
if err := ioutil.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
85+
if err := os.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
8786
return err
8887
}
8988
return nil
@@ -104,7 +103,7 @@ func TestGitStatus(t *testing.T) {
104103
if err := initFromRemote(ctx, c); err != nil {
105104
return err
106105
}
107-
if err := ioutil.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
106+
if err := os.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
108107
return err
109108
}
110109
if err := c.Git(ctx, "commit", "-a", "-m", "foo"); err != nil {
@@ -131,7 +130,7 @@ func TestGitStatus(t *testing.T) {
131130
if err := c.Git(ctx, "checkout", "-b", "otherbranch"); err != nil {
132131
return err
133132
}
134-
if err := ioutil.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
133+
if err := os.WriteFile(filepath.Join(c.Location, "first-file"), []byte("foobar"), 0755); err != nil {
135134
return err
136135
}
137136
if err := c.Git(ctx, "commit", "-a", "-m", "foo"); err != nil {
@@ -159,7 +158,7 @@ func TestGitStatus(t *testing.T) {
159158
if err := os.MkdirAll(filepath.Join(c.Location, "this/is/a/nested/test"), 0755); err != nil {
160159
return err
161160
}
162-
if err := ioutil.WriteFile(filepath.Join(c.Location, "this/is/a/nested/test/first-file"), []byte("foobar"), 0755); err != nil {
161+
if err := os.WriteFile(filepath.Join(c.Location, "this/is/a/nested/test/first-file"), []byte("foobar"), 0755); err != nil {
163162
return err
164163
}
165164
return nil
@@ -226,7 +225,7 @@ func TestGitStatus(t *testing.T) {
226225
}
227226

228227
func newGitClient(ctx context.Context) (*Client, error) {
229-
loc, err := ioutil.TempDir("", "gittest")
228+
loc, err := os.MkdirTemp("", "gittest")
230229
if err != nil {
231230
return nil, err
232231
}
@@ -254,7 +253,7 @@ func initFromRemote(ctx context.Context, c *Client) error {
254253
if err := remote.Git(ctx, "config", "--local", "user.name", "foo bar"); err != nil {
255254
return err
256255
}
257-
if err := ioutil.WriteFile(filepath.Join(remote.Location, "first-file"), []byte{}, 0755); err != nil {
256+
if err := os.WriteFile(filepath.Join(remote.Location, "first-file"), []byte{}, 0755); err != nil {
258257
return err
259258
}
260259
if err := remote.Git(ctx, "add", "first-file"); err != nil {

components/content-service/pkg/initializer/initializer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"context"
99
"encoding/json"
1010
"fmt"
11-
"io/ioutil"
11+
"io"
1212
"net/http"
1313
"os"
1414
"path/filepath"
@@ -199,7 +199,7 @@ func downloadOTS(ctx context.Context, url string) (user, pwd string, err error)
199199
return "", "", xerrors.Errorf("non-OK OTS response: %s", resp.Status)
200200
}
201201

202-
secret, err := ioutil.ReadAll(resp.Body)
202+
secret, err := io.ReadAll(resp.Body)
203203
if err != nil {
204204
return "", "", err
205205
}
@@ -308,7 +308,7 @@ func InitializeWorkspace(ctx context.Context, location string, remoteStorage sto
308308
return src, xerrors.Errorf("cannot create workspace: %w", err)
309309
}
310310
}
311-
fs, err := ioutil.ReadDir(location)
311+
fs, err := os.ReadDir(location)
312312
if err != nil {
313313
return src, xerrors.Errorf("cannot clean workspace folder: %w", err)
314314
}
@@ -372,7 +372,7 @@ func PlaceWorkspaceReadyFile(ctx context.Context, wspath string, initsrc csapi.W
372372

373373
tempWorkspaceReadyFile := WorkspaceReadyFile + ".tmp"
374374
fn := filepath.Join(wspath, tempWorkspaceReadyFile)
375-
err = ioutil.WriteFile(fn, []byte(fc), 0644)
375+
err = os.WriteFile(fn, []byte(fc), 0644)
376376
if err != nil {
377377
return xerrors.Errorf("cannot write workspace ready file: %w", err)
378378
}

components/content-service/pkg/layer/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"context"
1111
"encoding/json"
1212
"fmt"
13-
"io/ioutil"
13+
"io"
1414
"net/http"
1515
"strings"
1616

@@ -96,7 +96,7 @@ func (s *Provider) downloadContentManifest(ctx context.Context, bkt, obj string)
9696
}
9797
defer mfresp.Body.Close()
9898

99-
mfr, err := ioutil.ReadAll(mfresp.Body)
99+
mfr, err := io.ReadAll(mfresp.Body)
100100
if err != nil {
101101
return
102102
}

components/content-service/pkg/layer/provider_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"encoding/json"
1111
"flag"
1212
"fmt"
13-
"io/ioutil"
13+
"io"
1414
"net/http"
1515
"os"
1616
"strings"
@@ -132,7 +132,7 @@ func TestGetContentLayer(t *testing.T) {
132132
return &http.Response{
133133
StatusCode: http.StatusOK,
134134
Header: make(http.Header),
135-
Body: ioutil.NopCloser(bytes.NewReader(mf)),
135+
Body: io.NopCloser(bytes.NewReader(mf)),
136136
}
137137
default:
138138
return &http.Response{
@@ -174,13 +174,13 @@ func TestGetContentLayer(t *testing.T) {
174174
t.Fatalf("fixture %s exists already - not overwriting", fixfn)
175175
}
176176

177-
err = ioutil.WriteFile(fixfn, fixc, 0644)
177+
err = os.WriteFile(fixfn, fixc, 0644)
178178
if err != nil {
179179
t.Fatalf("cannot write fixture: %q", err)
180180
return
181181
}
182182
} else {
183-
fixc, err := ioutil.ReadFile(fixfn)
183+
fixc, err := os.ReadFile(fixfn)
184184
if os.IsNotExist(err) && !*update {
185185
t.Fatalf("no fixture %s. Run test with -update", fixfn)
186186
return

components/content-service/pkg/storage/gcloud.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"hash/crc32"
1111
"io"
12-
"io/ioutil"
1312
"math/rand"
1413
"net/http"
1514
"os"
@@ -237,7 +236,7 @@ func (rs *DirectGCPStorage) fixLegacyFilenames(ctx context.Context, destination
237236
* Using mv here is difficult as the wildcard expansion is done by the shell and not mv,
238237
* thus we'd need to wrap the mv call in a sh call -> too many dependencies to the outside world.
239238
*/
240-
fis, err := ioutil.ReadDir(legacyPath)
239+
fis, err := os.ReadDir(legacyPath)
241240
if err != nil {
242241
return err
243242
}
@@ -698,7 +697,7 @@ func newPresignedGCPAccess(config GCPConfig, stage Stage) (*PresignedGCPStorage,
698697
credfile = filepath.Join(tproot, credfile)
699698
}
700699

701-
jsonKey, err := ioutil.ReadFile(credfile)
700+
jsonKey, err := os.ReadFile(credfile)
702701
if err != nil {
703702
return nil, xerrors.Errorf("cannot read private key: %w", err)
704703
}

components/docker-up/docker-up/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package main
77
import (
88
"context"
99
"fmt"
10-
"io/ioutil"
1110
"os"
1211
"os/exec"
1312
"path/filepath"
@@ -155,7 +154,7 @@ func runOutsideNetns() error {
155154
}
156155
defer pipeW.Close()
157156

158-
slirpAPI, err := ioutil.TempFile("", "slirp4netns-api")
157+
slirpAPI, err := os.CreateTemp("", "slirp4netns-api")
159158
if err != nil {
160159
return err
161160
}

0 commit comments

Comments
 (0)