Skip to content

Commit 5121ef6

Browse files
authored
chore: remove refs to deprecated io/ioutil (#378)
Signed-off-by: guoguangwu <[email protected]>
1 parent 408c451 commit 5121ef6

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

cmd/container-structure-test/app/cmd/test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package cmd
1717
import (
1818
"fmt"
1919
"io"
20-
"io/ioutil"
21-
2220
"os"
2321

2422
"github.com/GoogleContainerTools/container-structure-test/cmd/container-structure-test/app/cmd/test"
@@ -78,7 +76,7 @@ func NewCmdTest(out io.Writer) *cobra.Command {
7876
}
7977

8078
if opts.Quiet {
81-
out = ioutil.Discard
79+
out = io.Discard
8280
}
8381

8482
color.NoColor = opts.NoColor

cmd/container-structure-test/app/cmd/test/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"io"
21-
"io/ioutil"
21+
"os"
2222
"strings"
2323
"time"
2424

@@ -55,7 +55,7 @@ func ValidateArgs(opts *config.StructureTestOptions) error {
5555
}
5656

5757
func Parse(fp string, args *drivers.DriverConfig, driverImpl func(drivers.DriverConfig) (drivers.Driver, error)) (types.StructureTest, error) {
58-
testContents, err := ioutil.ReadFile(fp)
58+
testContents, err := os.ReadFile(fp)
5959
if err != nil {
6060
return nil, err
6161
}

pkg/drivers/host_driver.go

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

1717
import (
1818
"encoding/json"
19-
"io/ioutil"
19+
"io/fs"
2020
"os"
2121
"os/exec"
2222
"strings"
@@ -144,15 +144,27 @@ func (d *HostDriver) StatFile(path string) (os.FileInfo, error) {
144144
}
145145

146146
func (d *HostDriver) ReadFile(path string) ([]byte, error) {
147-
return ioutil.ReadFile(path)
147+
return os.ReadFile(path)
148148
}
149149

150150
func (d *HostDriver) ReadDir(path string) ([]os.FileInfo, error) {
151-
return ioutil.ReadDir(path)
151+
entries, err := os.ReadDir(path)
152+
if err != nil {
153+
return nil, err
154+
}
155+
infos := make([]fs.FileInfo, 0, len(entries))
156+
for _, entry := range entries {
157+
info, err := entry.Info()
158+
if err != nil {
159+
return nil, err
160+
}
161+
infos = append(infos, info)
162+
}
163+
return infos, nil
152164
}
153165

154166
func (d *HostDriver) GetConfig() (unversioned.Config, error) {
155-
file, err := ioutil.ReadFile(d.ConfigPath)
167+
file, err := os.ReadFile(d.ConfigPath)
156168
if err != nil {
157169
return unversioned.Config{}, errors.Wrap(err, "Error retrieving config")
158170
}

pkg/drivers/tar_driver.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package drivers
1616

1717
import (
18-
"io/ioutil"
18+
"io/fs"
1919
"os"
2020
"path/filepath"
2121
"strings"
@@ -143,11 +143,23 @@ func (d *TarDriver) StatFile(path string) (os.FileInfo, error) {
143143
}
144144

145145
func (d *TarDriver) ReadFile(path string) ([]byte, error) {
146-
return ioutil.ReadFile(filepath.Join(d.Image.FSPath, path))
146+
return os.ReadFile(filepath.Join(d.Image.FSPath, path))
147147
}
148148

149149
func (d *TarDriver) ReadDir(path string) ([]os.FileInfo, error) {
150-
return ioutil.ReadDir(filepath.Join(d.Image.FSPath, path))
150+
entries, err := os.ReadDir(filepath.Join(d.Image.FSPath, path))
151+
if err != nil {
152+
return nil, err
153+
}
154+
infos := make([]fs.FileInfo, 0, len(entries))
155+
for _, entry := range entries {
156+
info, err := entry.Info()
157+
if err != nil {
158+
return nil, err
159+
}
160+
infos = append(infos, info)
161+
}
162+
return infos, nil
151163
}
152164

153165
func (d *TarDriver) GetConfig() (unversioned.Config, error) {

0 commit comments

Comments
 (0)