Skip to content

Commit 0d258bd

Browse files
authored
refactor: move from io/ioutil to io and os packages (#1759)
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. [1]: https://golang.org/doc/go1.16#ioutil Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
1 parent 05d696e commit 0d258bd

File tree

28 files changed

+48
-70
lines changed

28 files changed

+48
-70
lines changed

build/layerutils/manifests/manifests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package manifest
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
19+
"os"
2020
"path/filepath"
2121

2222
"github.com/sealerio/sealer/build/layerutils"
@@ -28,7 +28,7 @@ type Manifests struct{}
2828
func (manifests *Manifests) ListImages(yamlFile string) ([]string, error) {
2929
var list []string
3030

31-
yamlBytes, err := ioutil.ReadFile(filepath.Clean(yamlFile))
31+
yamlBytes, err := os.ReadFile(filepath.Clean(yamlFile))
3232
if err != nil {
3333
return nil, fmt.Errorf("failed to read file: %s", err)
3434
}

pkg/client/docker/auth/auth.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/base64"
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"path/filepath"
2524

@@ -79,7 +78,7 @@ func (s *DockerAuthService) SetAuthInfo(hostname, username, password string) err
7978
return err
8079
}
8180

82-
if err := ioutil.WriteFile(s.FilePath, data, common.FileMode0644); err != nil {
81+
if err := os.WriteFile(s.FilePath, data, common.FileMode0644); err != nil {
8382
return fmt.Errorf("write %s failed,%s", s.FilePath, err)
8483
}
8584
return nil
@@ -115,7 +114,7 @@ func NewDockerAuthService() (DockerAuthService, error) {
115114
return das, nil
116115
}
117116

118-
content, err := ioutil.ReadFile(filepath.Clean(authFile))
117+
content, err := os.ReadFile(filepath.Clean(authFile))
119118
if err != nil {
120119
return das, err
121120
}

pkg/clusterfile/clusterfile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package clusterfile
1717
import (
1818
"bytes"
1919
"fmt"
20-
"io/ioutil"
20+
"os"
2121
"path/filepath"
2222

2323
"github.com/sealerio/sealer/pkg/runtime/kubernetes/kubeadm"
@@ -62,7 +62,7 @@ func NewClusterFile(path string) (Interface, error) {
6262
return clusterFile, nil
6363
}
6464

65-
clusterFileData, err := ioutil.ReadFile(filepath.Clean(path))
65+
clusterFileData, err := os.ReadFile(filepath.Clean(path))
6666

6767
if err != nil {
6868
return nil, err

pkg/clusterfile/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package clusterfile
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"os"
2120
"path/filepath"
2221
"strings"
@@ -32,7 +31,7 @@ import (
3231
var ErrClusterNotExist = fmt.Errorf("no cluster exist")
3332

3433
func GetDefaultClusterName() (string, error) {
35-
files, err := ioutil.ReadDir(fmt.Sprintf("%s/.sealer", common.GetHomeDir()))
34+
files, err := os.ReadDir(fmt.Sprintf("%s/.sealer", common.GetHomeDir()))
3635
if err != nil {
3736
return "", err
3837
}

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package config
1717
import (
1818
"bytes"
1919
"fmt"
20-
"io/ioutil"
20+
stdos "os"
2121
"path/filepath"
2222
"strings"
2323

@@ -77,7 +77,7 @@ func (c *Dumper) WriteFiles(configs []v1.Config) error {
7777
}
7878
}
7979

80-
contents, err := ioutil.ReadFile(filepath.Clean(configPath))
80+
contents, err := stdos.ReadFile(filepath.Clean(configPath))
8181
if err != nil {
8282
return err
8383
}

pkg/filesystem/cloudfilesystem/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ package cloudfilesystem
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"net"
20+
"os"
2121
"path/filepath"
2222

2323
"github.com/sealerio/sealer/utils/os/fs"
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func copyFiles(sshEntry ssh.Interface, ip net.IP, src, target string) error {
33-
files, err := ioutil.ReadDir(src)
33+
files, err := os.ReadDir(src)
3434
if err != nil {
3535
return fmt.Errorf("failed to copy files: %s", err)
3636
}

pkg/filesystem/clusterimage/clusterimage.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package clusterimage
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"net"
2120
"os"
2221
"path/filepath"
@@ -61,7 +60,7 @@ func (m *mounter) umountImage(cluster *v2.Cluster) error {
6160
if !osi.IsFileExist(mountRootDir) {
6261
return nil
6362
}
64-
dir, err := ioutil.ReadDir(mountRootDir)
63+
dir, err := os.ReadDir(mountRootDir)
6564
if err != nil {
6665
return err
6766
}

pkg/image/save/filesystem.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"os"
2524
"path"
2625
"time"
@@ -138,7 +137,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
138137
}
139138
defer rc.Close()
140139

141-
p, err := ioutil.ReadAll(rc)
140+
p, err := io.ReadAll(rc)
142141
if err != nil {
143142
return nil, err
144143
}

pkg/imageengine/buildah/build.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ package buildah
1616

1717
import (
1818
"context"
19-
2019
"fmt"
21-
22-
"github.com/sealerio/sealer/pkg/define/options"
23-
2420
"io"
25-
"io/ioutil"
2621
"os"
2722
"path/filepath"
2823
"strings"
2924
"time"
3025

26+
"github.com/sealerio/sealer/pkg/define/options"
27+
3128
"github.com/containers/buildah/define"
3229
"github.com/containers/buildah/imagebuildah"
3330
buildahcli "github.com/containers/buildah/pkg/cli"
@@ -294,7 +291,7 @@ func (engine *Engine) wrapper2Options(opts *options.BuildOptions, wrapper *build
294291
}
295292

296293
if wrapper.Quiet {
297-
options.ReportWriter = ioutil.Discard
294+
options.ReportWriter = io.Discard
298295
}
299296

300297
return options, kubefiles, nil

pkg/imageengine/buildah/from.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ package buildah
1616

1717
import (
1818
"fmt"
19-
20-
"github.com/sealerio/sealer/pkg/define/options"
21-
2219
"io"
23-
"io/ioutil"
2420
"os"
2521
"strings"
2622

23+
"github.com/sealerio/sealer/pkg/define/options"
24+
2725
"github.com/containers/buildah"
2826
"github.com/containers/buildah/define"
2927
buildahcli "github.com/containers/buildah/pkg/cli"
@@ -243,7 +241,7 @@ func onBuild(builder *buildah.Builder, quiet bool) error {
243241
case "RUN":
244242
var stdout io.Writer
245243
if quiet {
246-
stdout = ioutil.Discard
244+
stdout = io.Discard
247245
}
248246
if err := builder.Run(args, buildah.RunOptions{Stdout: stdout}); err != nil {
249247
return err

0 commit comments

Comments
 (0)