Skip to content

Commit 432887f

Browse files
IND-1809 Replaced io/ioutil as its deprecated
1 parent a3a84e3 commit 432887f

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

addlicense/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"flag"
2424
"fmt"
25-
"io/ioutil"
2625
"log"
2726
"os"
2827
"path/filepath"
@@ -321,7 +320,7 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data Li
321320
return false, err
322321
}
323322

324-
b, err := ioutil.ReadFile(path)
323+
b, err := os.ReadFile(path)
325324
if err != nil {
326325
return false, err
327326
}
@@ -338,12 +337,12 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data Li
338337
lic = append(line, lic...)
339338
}
340339
b = append(lic, b...)
341-
return true, ioutil.WriteFile(path, b, fmode)
340+
return true, os.WriteFile(path, b, fmode)
342341
}
343342

344343
// fileHasLicense reports whether the file at path contains a license header.
345344
func fileHasLicense(path string) (bool, error) {
346-
b, err := ioutil.ReadFile(path)
345+
b, err := os.ReadFile(path)
347346
if err != nil {
348347
return false, err
349348
}

addlicense/main_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package addlicense
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"os/exec"
2120
"path/filepath"
@@ -33,7 +32,7 @@ func run(t *testing.T, name string, args ...string) {
3332
}
3433

3534
func tempDir(t *testing.T) string {
36-
dir, err := ioutil.TempDir("", "addlicense")
35+
dir, err := os.MkdirTemp("", "addlicense")
3736
if err != nil {
3837
t.Fatal(err)
3938
}
@@ -209,12 +208,12 @@ func TestMPL(t *testing.T) {
209208
}
210209

211210
func createTempFile(contents string, pattern string) (*os.File, error) {
212-
f, err := ioutil.TempFile("", pattern)
211+
f, err := os.CreateTemp("", pattern)
213212
if err != nil {
214213
return nil, err
215214
}
216215

217-
if err := ioutil.WriteFile(f.Name(), []byte(contents), 0644); err != nil {
216+
if err := os.WriteFile(f.Name(), []byte(contents), 0644); err != nil {
218217
return nil, err
219218
}
220219

@@ -275,7 +274,7 @@ func TestAddLicense(t *testing.T) {
275274
if updated != tt.wantUpdated {
276275
t.Errorf("addLicense with contents %q returned updated: %t, want %t", tt.contents, updated, tt.wantUpdated)
277276
}
278-
gotContents, err := ioutil.ReadFile(f.Name())
277+
gotContents, err := os.ReadFile(f.Name())
279278
if err != nil {
280279
t.Error(err)
281280
}

addlicense/tmpl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"bufio"
1919
"bytes"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"strings"
2323
"text/template"
2424
"unicode"
@@ -55,7 +55,7 @@ func fetchTemplate(license string, templateFile string, spdx spdxFlag) (string,
5555
if spdx == spdxOnly {
5656
t = tmplSPDX
5757
} else if templateFile != "" {
58-
d, err := ioutil.ReadFile(templateFile)
58+
d, err := os.ReadFile(templateFile)
5959
if err != nil {
6060
return "", fmt.Errorf("license file: %w", err)
6161
}

0 commit comments

Comments
 (0)