Skip to content

Commit 2089a88

Browse files
authored
Merge pull request #7765 from ErikEk/retire-io-ioutil-dep
Remove io/ioutil package dependency
2 parents dcd8e16 + 0d94131 commit 2089a88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+101
-128
lines changed

cert/selfsigned.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"crypto/x509/pkix"
1010
"encoding/pem"
1111
"fmt"
12-
"io/ioutil"
1312
"math/big"
1413
"net"
1514
"os"
@@ -295,14 +294,14 @@ func GenCertPair(org string, tlsExtraIPs, tlsExtraDomains []string,
295294
func WriteCertPair(certFile, keyFile string, certBytes, keyBytes []byte) error {
296295
// Write cert and key files.
297296
if certFile != "" {
298-
err := ioutil.WriteFile(certFile, certBytes, 0644)
297+
err := os.WriteFile(certFile, certBytes, 0644)
299298
if err != nil {
300299
return err
301300
}
302301
}
303302

304303
if keyFile != "" {
305-
err := ioutil.WriteFile(keyFile, keyBytes, 0600)
304+
err := os.WriteFile(keyFile, keyBytes, 0600)
306305
if err != nil {
307306
os.Remove(certFile)
308307
return err

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
}

chainreg/chainregistry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net"
1010
"net/url"
1111
"os"
@@ -547,7 +547,7 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) {
547547
if err != nil {
548548
return nil, nil, err
549549
}
550-
rpcCert, err = ioutil.ReadAll(certFile)
550+
rpcCert, err = io.ReadAll(certFile)
551551
if err != nil {
552552
return nil, nil, err
553553
}

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) {

channeldb/migration/lnwire21/announcement_signatures.go

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

33
import (
44
"io"
5-
"io/ioutil"
65
)
76

87
// AnnounceSignatures is a direct message between two endpoints of a
@@ -66,7 +65,7 @@ func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error {
6665
// we'll collect the remainder into the ExtraOpaqueData field. If there
6766
// aren't any bytes, then we'll snip off the slice to avoid carrying
6867
// around excess capacity.
69-
a.ExtraOpaqueData, err = ioutil.ReadAll(r)
68+
a.ExtraOpaqueData, err = io.ReadAll(r)
7069
if err != nil {
7170
return err
7271
}

channeldb/migration/lnwire21/channel_announcement.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package lnwire
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76

87
"github.com/btcsuite/btcd/chaincfg/chainhash"
98
)
@@ -89,7 +88,7 @@ func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
8988
// we'll collect the remainder into the ExtraOpaqueData field. If there
9089
// aren't any bytes, then we'll snip off the slice to avoid carrying
9190
// around excess capacity.
92-
a.ExtraOpaqueData, err = ioutil.ReadAll(r)
91+
a.ExtraOpaqueData, err = io.ReadAll(r)
9392
if err != nil {
9493
return err
9594
}

channeldb/migration/lnwire21/channel_update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87

98
"github.com/btcsuite/btcd/chaincfg/chainhash"
109
)
@@ -160,7 +159,7 @@ func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error {
160159
// we'll collect the remainder into the ExtraOpaqueData field. If there
161160
// aren't any bytes, then we'll snip off the slice to avoid carrying
162161
// around excess capacity.
163-
a.ExtraOpaqueData, err = ioutil.ReadAll(r)
162+
a.ExtraOpaqueData, err = io.ReadAll(r)
164163
if err != nil {
165164
return err
166165
}

channeldb/migration/lnwire21/node_announcement.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"image/color"
77
"io"
8-
"io/ioutil"
98
"net"
109
"unicode/utf8"
1110
)
@@ -127,7 +126,7 @@ func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
127126
// we'll collect the remainder into the ExtraOpaqueData field. If there
128127
// aren't any bytes, then we'll snip off the slice to avoid carrying
129128
// around excess capacity.
130-
a.ExtraOpaqueData, err = ioutil.ReadAll(r)
129+
a.ExtraOpaqueData, err = io.ReadAll(r)
131130
if err != nil {
132131
return err
133132
}

0 commit comments

Comments
 (0)