Skip to content

Commit 994f003

Browse files
committed
Replace deprecated ioutil functions with their io or os equilvalents
1 parent e701253 commit 994f003

6 files changed

+19
-23
lines changed

check_depends.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package main
22

33
import (
44
"fmt"
5-
"golang.org/x/mod/modfile"
6-
"golang.org/x/tools/go/vcs"
7-
"io/ioutil"
85
"log"
96
"os"
107
"path/filepath"
11-
"pault.ag/go/debian/control"
128
"strings"
9+
10+
"golang.org/x/mod/modfile"
11+
"golang.org/x/tools/go/vcs"
12+
"pault.ag/go/debian/control"
1313
)
1414

1515
type dependency struct {
@@ -92,7 +92,7 @@ func execCheckDepends(args []string) {
9292
// i.e. it returns the one defined in go.mod as well as the transitively ones
9393
// TODO: this may not be the best way of doing thing since it requires the package to be converted to go module
9494
func parseGoModDependencies(directory string, goBinaries map[string]string) ([]dependency, error) {
95-
b, err := ioutil.ReadFile(filepath.Join(directory, "go.mod"))
95+
b, err := os.ReadFile(filepath.Join(directory, "go.mod"))
9696
if err != nil {
9797
return nil, err
9898
}

check_depends_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"reflect"
@@ -43,7 +42,7 @@ Description: read your RSS feeds from your terminal
4342
Terminews is a terminal based application (TUI)
4443
that allows you to manage RSS resources and display their news feeds.
4544
`
46-
tmpDir, err := ioutil.TempDir("", "dh-make-golang")
45+
tmpDir, err := os.MkdirTemp("", "dh-make-golang")
4746
if err != nil {
4847
t.Fatalf("Could not create temp dir: %v", err)
4948
}
@@ -52,7 +51,7 @@ Description: read your RSS feeds from your terminal
5251
if err := os.MkdirAll(filepath.Join(tmpDir, "dummy-package", "debian"), 0750); err != nil {
5352
t.Fatalf("Could not create dummy Debian package: %v", err)
5453
}
55-
if err := ioutil.WriteFile(filepath.Join(tmpDir, "dummy-package", "debian", "control"), []byte(f), 0640); err != nil {
54+
if err := os.WriteFile(filepath.Join(tmpDir, "dummy-package", "debian", "control"), []byte(f), 0640); err != nil {
5655
t.Fatalf("Could not create dummy Debian package: %v", err)
5756
}
5857

@@ -99,7 +98,7 @@ require (
9998
github.com/google/go-github/v38 v38.1.0
10099
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
101100
)`
102-
tmpDir, err := ioutil.TempDir("", "dh-make-golang")
101+
tmpDir, err := os.MkdirTemp("", "dh-make-golang")
103102
if err != nil {
104103
t.Fatalf("Could not create temp dir: %v", err)
105104
}
@@ -108,7 +107,7 @@ require (
108107
if err := os.MkdirAll(filepath.Join(tmpDir, "dummy-package"), 0750); err != nil {
109108
t.Fatalf("Could not create dummy Debian package: %v", err)
110109
}
111-
if err := ioutil.WriteFile(filepath.Join(tmpDir, "dummy-package", "go.mod"), []byte(f), 0640); err != nil {
110+
if err := os.WriteFile(filepath.Join(tmpDir, "dummy-package", "go.mod"), []byte(f), 0640); err != nil {
112111
t.Fatalf("Could not create dummy Debian package: %v", err)
113112
}
114113

create_salsa_project.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"log"
88
"net/http"
99
"net/url"
@@ -41,7 +41,7 @@ func execCreateSalsaProject(args []string) {
4141
log.Fatalf("http post: %s", err)
4242
}
4343
if got, want := resp.StatusCode, http.StatusOK; got != want {
44-
b, _ := ioutil.ReadAll(resp.Body)
44+
b, _ := io.ReadAll(resp.Body)
4545
log.Fatalf("unexpected HTTP status code: got %d, want %d (response: %s)", got, want, string(b))
4646
}
4747
}

estimate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"flag"
55
"fmt"
66
"go/build"
7-
"io/ioutil"
87
"log"
98
"os"
109
"os/exec"
@@ -59,7 +58,7 @@ func removeVendor(gopath string) (found bool, _ error) {
5958

6059
func estimate(importpath string) error {
6160
// construct a separate GOPATH in a temporary directory
62-
gopath, err := ioutil.TempDir("", "dh-make-golang")
61+
gopath, err := os.MkdirTemp("", "dh-make-golang")
6362
if err != nil {
6463
return fmt.Errorf("create temp dir: %w", err)
6564
}

make.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"log"
109
"net/http"
1110
"net/url"
@@ -174,7 +173,7 @@ func (u *upstream) tarballFromHoster() error {
174173
}
175174

176175
func (u *upstream) tar(gopath, repo string) error {
177-
f, err := ioutil.TempFile("", "dh-make-golang")
176+
f, err := os.CreateTemp("", "dh-make-golang")
178177
if err != nil {
179178
return fmt.Errorf("create temp file: %w", err)
180179
}
@@ -339,7 +338,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
339338
}
340339

341340
func makeUpstreamSourceTarball(repo, revision string, forcePrerelease bool) (*upstream, error) {
342-
gopath, err := ioutil.TempDir("", "dh-make-golang")
341+
gopath, err := os.MkdirTemp("", "dh-make-golang")
343342
if err != nil {
344343
return nil, fmt.Errorf("create tmp dir: %w", err)
345344
}
@@ -656,7 +655,7 @@ func getDebianEmail() string {
656655
if email := strings.TrimSpace(os.Getenv("DEBEMAIL")); email != "" {
657656
return email
658657
}
659-
mailname, err := ioutil.ReadFile("/etc/mailname")
658+
mailname, err := os.ReadFile("/etc/mailname")
660659
// By default, /etc/mailname contains "debian" which is not useful; check for ".".
661660
if err == nil && strings.Contains(string(mailname), ".") {
662661
if u, err := user.Current(); err == nil && u.Username != "" {

version_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
54
"os"
65
"os/exec"
76
"path/filepath"
@@ -22,14 +21,14 @@ func TestSnapshotVersion(t *testing.T) {
2221
os.Setenv("TZ", "UTC")
2322
defer os.Unsetenv("TZ")
2423

25-
tempdir, err := ioutil.TempDir("", "dh-make-golang")
24+
tempdir, err := os.MkdirTemp("", "dh-make-golang")
2625
if err != nil {
2726
t.Fatalf("Could not create temp dir: %v", err)
2827
}
2928
defer os.RemoveAll(tempdir)
3029

3130
tempfile := filepath.Join(tempdir, "test")
32-
if err := ioutil.WriteFile(tempfile, []byte("testcase"), 0644); err != nil {
31+
if err := os.WriteFile(tempfile, []byte("testcase"), 0644); err != nil {
3332
t.Fatalf("Could not write temp file %q: %v", tempfile, err)
3433
}
3534

@@ -64,7 +63,7 @@ func TestSnapshotVersion(t *testing.T) {
6463
t.Logf("got %q, want %q", got, want)
6564
}
6665

67-
if err := ioutil.WriteFile(tempfile, []byte("testcase 2"), 0644); err != nil {
66+
if err := os.WriteFile(tempfile, []byte("testcase 2"), 0644); err != nil {
6867
t.Fatalf("Could not write temp file %q: %v", tempfile, err)
6968
}
7069

@@ -84,7 +83,7 @@ func TestSnapshotVersion(t *testing.T) {
8483
t.Logf("got %q, want %q", got, want)
8584
}
8685

87-
if err := ioutil.WriteFile(tempfile, []byte("testcase 3"), 0644); err != nil {
86+
if err := os.WriteFile(tempfile, []byte("testcase 3"), 0644); err != nil {
8887
t.Fatalf("Could not write temp file %q: %v", tempfile, err)
8988
}
9089

0 commit comments

Comments
 (0)