Skip to content

Commit 14d354b

Browse files
committed
Replace deprecated ioutil functions
Signed-off-by: Stephen Kitt <skitt@redhat.com>
1 parent 4c210f1 commit 14d354b

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

internal/license/resolve.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package license
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
6+
"os"
67
"path/filepath"
78
"regexp"
89
"strings"
@@ -21,7 +22,7 @@ func Resolve(modules []model.Module, threshold float64) ([]model.Module, error)
2122
return nil, fmt.Errorf("failed to open license databse: %w", err)
2223
}
2324
defer f.Close()
24-
return ioutil.ReadAll(f)
25+
return io.ReadAll(f)
2526
})
2627

2728
lc, err := licenseclassifier.New(threshold, archiveFn)
@@ -55,7 +56,7 @@ var fileRgx = regexp.MustCompile(`(?i)^(li[cs]en[cs]e|copying)`)
5556

5657
// locateLicenses searches for license files
5758
func locateLicenses(path string) (lp []string, err error) {
58-
files, err := ioutil.ReadDir(path)
59+
files, err := os.ReadDir(path)
5960
if err != nil {
6061
return nil, err
6162
}
@@ -71,7 +72,7 @@ func locateLicenses(path string) (lp []string, err error) {
7172
func classify(lc *licenseclassifier.License, paths []string) ([]model.License, error) {
7273
licenses := make([]model.License, 0)
7374
for _, p := range paths {
74-
content, err := ioutil.ReadFile(p)
75+
content, err := os.ReadFile(p)
7576
if err != nil {
7677
return nil, err
7778
}

internal/module/extract.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package module
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"os/exec"
98

@@ -50,7 +49,7 @@ func goVersion(ctx context.Context, paths []string) (string, error) {
5049
return "", err
5150
}
5251

53-
tempDir, err := ioutil.TempDir("", "lichen")
52+
tempDir, err := os.MkdirTemp("", "lichen")
5453
if err != nil {
5554
return "", fmt.Errorf("failed to create temp directory: %w", err)
5655
}

internal/module/fetch.go

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

@@ -25,7 +24,7 @@ func Fetch(ctx context.Context, refs []model.ModuleReference) ([]model.Module, e
2524
return nil, err
2625
}
2726

28-
tempDir, err := ioutil.TempDir("", "lichen")
27+
tempDir, err := os.MkdirTemp("", "lichen")
2928
if err != nil {
3029
return nil, fmt.Errorf("failed to create temp directory: %w", err)
3130
}

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"io/ioutil"
87
"log"
98
"os"
109
"path/filepath"
@@ -101,7 +100,7 @@ func run(c *cli.Context) error {
101100
func parseConfig(path string) (scan.Config, error) {
102101
var conf scan.Config
103102
if path != "" {
104-
b, err := ioutil.ReadFile(path)
103+
b, err := os.ReadFile(path)
105104
if err != nil {
106105
return scan.Config{}, fmt.Errorf("failed to read file %q: %w", path, err)
107106
}

0 commit comments

Comments
 (0)