Skip to content

Commit ab83343

Browse files
committed
multi: repleace ioutil.ReadFile
1 parent 619c8f4 commit ab83343

23 files changed

+55
-62
lines changed

cert/selfsigned_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cert_test
22

33
import (
4-
"io/ioutil"
4+
"os"
55
"path/filepath"
66
"testing"
77
"time"
@@ -42,10 +42,10 @@ func TestIsOutdatedCert(t *testing.T) {
4242
// number of IPs and domains.
4343
for numIPs := 1; numIPs <= len(extraIPs); numIPs++ {
4444
for numDomains := 1; numDomains <= len(extraDomains); numDomains++ {
45-
certBytes, err := ioutil.ReadFile(certPath)
45+
certBytes, err := os.ReadFile(certPath)
4646
require.NoError(t, err)
4747

48-
keyBytes, err := ioutil.ReadFile(keyPath)
48+
keyBytes, err := os.ReadFile(keyPath)
4949
require.NoError(t, err)
5050

5151
_, parsedCert, err := cert.LoadCertFromBytes(
@@ -98,10 +98,10 @@ func TestIsOutdatedPermutation(t *testing.T) {
9898
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
9999
require.NoError(t, err)
100100

101-
certBytes, err = ioutil.ReadFile(certPath)
101+
certBytes, err = os.ReadFile(certPath)
102102
require.NoError(t, err)
103103

104-
keyBytes, err = ioutil.ReadFile(keyPath)
104+
keyBytes, err = os.ReadFile(keyPath)
105105
require.NoError(t, err)
106106

107107
_, parsedCert, err := cert.LoadCertFromBytes(certBytes, keyBytes)
@@ -171,10 +171,10 @@ func TestTLSDisableAutofill(t *testing.T) {
171171
require.NoError(t, err)
172172

173173
// Read certs from disk.
174-
certBytes, err = ioutil.ReadFile(certPath)
174+
certBytes, err = os.ReadFile(certPath)
175175
require.NoError(t, err)
176176

177-
keyBytes, err = ioutil.ReadFile(keyPath)
177+
keyBytes, err = os.ReadFile(keyPath)
178178
require.NoError(t, err)
179179

180180
// Load the certificate.
@@ -230,10 +230,10 @@ func TestTLSConfig(t *testing.T) {
230230
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
231231
require.NoError(t, err)
232232

233-
certBytes, err = ioutil.ReadFile(certPath)
233+
certBytes, err = os.ReadFile(certPath)
234234
require.NoError(t, err)
235235

236-
keyBytes, err = ioutil.ReadFile(keyPath)
236+
keyBytes, err = os.ReadFile(keyPath)
237237
require.NoError(t, err)
238238

239239
// Load the certificate.

cert/tls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cert
33
import (
44
"crypto/tls"
55
"crypto/x509"
6-
"io/ioutil"
6+
"os"
77
"sync"
88
)
99

@@ -31,11 +31,11 @@ var (
3131
func GetCertBytesFromPath(certPath, keyPath string) (certBytes,
3232
keyBytes []byte, err error) {
3333

34-
certBytes, err = ioutil.ReadFile(certPath)
34+
certBytes, err = os.ReadFile(certPath)
3535
if err != nil {
3636
return nil, nil, err
3737
}
38-
keyBytes, err = ioutil.ReadFile(keyPath)
38+
keyBytes, err = os.ReadFile(keyPath)
3939
if err != nil {
4040
return nil, nil, err
4141
}

chanbackup/backupfile.go

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

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path/filepath"
87

@@ -138,7 +137,7 @@ func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) {
138137
// Now that we've confirmed the target file is populated, we'll read
139138
// all the contents of the file. This function ensures that file is
140139
// always closed, even if we can't read the contents.
141-
multiBytes, err := ioutil.ReadFile(b.fileName)
140+
multiBytes, err := os.ReadFile(b.fileName)
142141
if err != nil {
143142
return nil, err
144143
}

chanbackup/backupfile_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package chanbackup
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"math/rand"
87
"os"
98
"path/filepath"
@@ -27,7 +26,7 @@ func assertBackupMatches(t *testing.T, filePath string,
2726

2827
t.Helper()
2928

30-
packedBackup, err := ioutil.ReadFile(filePath)
29+
packedBackup, err := os.ReadFile(filePath)
3130
require.NoError(t, err, "unable to test file")
3231

3332
if !bytes.Equal(packedBackup, currentBackup) {

cmd/lncli/cmd_macaroon.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io/ioutil"
88
"net"
9+
"os"
910
"strconv"
1011
"strings"
1112
"unicode"
@@ -352,7 +353,7 @@ func printMacaroon(ctx *cli.Context) error {
352353
macPath := lncfg.CleanAndExpandPath(ctx.String("macaroon_file"))
353354

354355
// Load the specified macaroon file.
355-
macBytes, err = ioutil.ReadFile(macPath)
356+
macBytes, err = os.ReadFile(macPath)
356357
if err != nil {
357358
return fmt.Errorf("unable to read macaroon path %v: %v",
358359
macPath, err)
@@ -441,7 +442,7 @@ func constrainMacaroon(ctx *cli.Context) error {
441442
sourceMacFile := lncfg.CleanAndExpandPath(args.First())
442443
args = args.Tail()
443444

444-
sourceMacBytes, err := ioutil.ReadFile(sourceMacFile)
445+
sourceMacBytes, err := os.ReadFile(sourceMacFile)
445446
if err != nil {
446447
return fmt.Errorf("error trying to read source macaroon file "+
447448
"%s: %v", sourceMacFile, err)

cmd/lncli/cmd_open_channel.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"os"
1413
"strconv"
1514
"strings"
@@ -1016,7 +1015,7 @@ func readTerminalOrFile(quit chan struct{}) (string, error) {
10161015

10171016
// If it's a path to an existing file and it's small enough, let's try
10181017
// to read its content now.
1019-
content, err := ioutil.ReadFile(maybeFile)
1018+
content, err := os.ReadFile(maybeFile)
10201019
if err != nil {
10211020
return "", err
10221021
}

cmd/lncli/cmd_profile.go

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

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"path"
87
"strings"
@@ -423,7 +422,7 @@ func profileAddMacaroon(ctx *cli.Context) error {
423422

424423
// Now load and possibly encrypt the macaroon file.
425424
macPath := lncfg.CleanAndExpandPath(ctx.GlobalString("macaroonpath"))
426-
macBytes, err := ioutil.ReadFile(macPath)
425+
macBytes, err := os.ReadFile(macPath)
427426
if err != nil {
428427
return fmt.Errorf("unable to read macaroon path: %w", err)
429428
}

cmd/lncli/cmd_walletunlocker.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"encoding/hex"
77
"fmt"
8-
"io/ioutil"
98
"os"
109
"strconv"
1110
"strings"
@@ -712,7 +711,7 @@ func createWatchOnly(ctx *cli.Context) error {
712711
}
713712

714713
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
715-
jsonBytes, err := ioutil.ReadFile(jsonFile)
714+
jsonBytes, err := os.ReadFile(jsonFile)
716715
if err != nil {
717716
return fmt.Errorf("error reading JSON from file %v: %v",
718717
jsonFile, err)

cmd/lncli/commands.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"math"
1413
"os"
1514
"strconv"
@@ -2833,7 +2832,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error)
28332832
}, nil
28342833

28352834
case ctx.IsSet("multi_file"):
2836-
packedMulti, err := ioutil.ReadFile(ctx.String("multi_file"))
2835+
packedMulti, err := os.ReadFile(ctx.String("multi_file"))
28372836
if err != nil {
28382837
return nil, fmt.Errorf("unable to decode multi packed "+
28392838
"backup: %v", err)

cmd/lncli/profile.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io/ioutil"
10+
"os"
1011
"path"
1112
"strings"
1213

@@ -129,7 +130,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) (
129130
var tlsCert []byte
130131
if tlsCertPath != "" && !insecure {
131132
var err error
132-
tlsCert, err = ioutil.ReadFile(tlsCertPath)
133+
tlsCert, err = os.ReadFile(tlsCertPath)
133134
if err != nil {
134135
return nil, fmt.Errorf("could not load TLS cert "+
135136
"file: %v", err)
@@ -167,7 +168,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) (
167168
}
168169

169170
// Now load and possibly encrypt the macaroon file.
170-
macBytes, err := ioutil.ReadFile(macPath)
171+
macBytes, err := os.ReadFile(macPath)
171172
if err != nil {
172173
return nil, fmt.Errorf("unable to read macaroon path (check "+
173174
"the network setting!): %v", err)
@@ -222,7 +223,7 @@ func loadProfileFile(file string) (*profileFile, error) {
222223
return nil, errNoProfileFile
223224
}
224225

225-
content, err := ioutil.ReadFile(file)
226+
content, err := os.ReadFile(file)
226227
if err != nil {
227228
return nil, fmt.Errorf("could not load profile file %s: %w",
228229
file, err)

0 commit comments

Comments
 (0)