From 619c8f4eb84eee8337909f9f112d49c997910693 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 13 Jun 2023 20:17:03 +0700 Subject: [PATCH 1/7] multi: repleace ioutil.ReadAll --- chainreg/chainregistry.go | 4 ++-- channeldb/migration/lnwire21/announcement_signatures.go | 3 +-- channeldb/migration/lnwire21/channel_announcement.go | 3 +-- channeldb/migration/lnwire21/channel_update.go | 3 +-- channeldb/migration/lnwire21/node_announcement.go | 3 +-- cmd/lncli/cmd_payments.go | 4 ++-- config.go | 5 +++-- contractcourt/htlc_incoming_contest_resolver_test.go | 3 +-- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index 036da71a5..8b562e87a 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/url" "os" @@ -547,7 +547,7 @@ func NewPartialChainControl(cfg *Config) (*PartialChainControl, func(), error) { if err != nil { return nil, nil, err } - rpcCert, err = ioutil.ReadAll(certFile) + rpcCert, err = io.ReadAll(certFile) if err != nil { return nil, nil, err } diff --git a/channeldb/migration/lnwire21/announcement_signatures.go b/channeldb/migration/lnwire21/announcement_signatures.go index 639704de0..4c2166a8d 100644 --- a/channeldb/migration/lnwire21/announcement_signatures.go +++ b/channeldb/migration/lnwire21/announcement_signatures.go @@ -2,7 +2,6 @@ package lnwire import ( "io" - "io/ioutil" ) // AnnounceSignatures is a direct message between two endpoints of a @@ -66,7 +65,7 @@ func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error { // we'll collect the remainder into the ExtraOpaqueData field. If there // aren't any bytes, then we'll snip off the slice to avoid carrying // around excess capacity. - a.ExtraOpaqueData, err = ioutil.ReadAll(r) + a.ExtraOpaqueData, err = io.ReadAll(r) if err != nil { return err } diff --git a/channeldb/migration/lnwire21/channel_announcement.go b/channeldb/migration/lnwire21/channel_announcement.go index 46efeed88..897844fb1 100644 --- a/channeldb/migration/lnwire21/channel_announcement.go +++ b/channeldb/migration/lnwire21/channel_announcement.go @@ -3,7 +3,6 @@ package lnwire import ( "bytes" "io" - "io/ioutil" "github.com/btcsuite/btcd/chaincfg/chainhash" ) @@ -89,7 +88,7 @@ func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error { // we'll collect the remainder into the ExtraOpaqueData field. If there // aren't any bytes, then we'll snip off the slice to avoid carrying // around excess capacity. - a.ExtraOpaqueData, err = ioutil.ReadAll(r) + a.ExtraOpaqueData, err = io.ReadAll(r) if err != nil { return err } diff --git a/channeldb/migration/lnwire21/channel_update.go b/channeldb/migration/lnwire21/channel_update.go index 6d19e3e4c..77e65e76b 100644 --- a/channeldb/migration/lnwire21/channel_update.go +++ b/channeldb/migration/lnwire21/channel_update.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "github.com/btcsuite/btcd/chaincfg/chainhash" ) @@ -160,7 +159,7 @@ func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error { // we'll collect the remainder into the ExtraOpaqueData field. If there // aren't any bytes, then we'll snip off the slice to avoid carrying // around excess capacity. - a.ExtraOpaqueData, err = ioutil.ReadAll(r) + a.ExtraOpaqueData, err = io.ReadAll(r) if err != nil { return err } diff --git a/channeldb/migration/lnwire21/node_announcement.go b/channeldb/migration/lnwire21/node_announcement.go index 8550fddd3..51cf7367b 100644 --- a/channeldb/migration/lnwire21/node_announcement.go +++ b/channeldb/migration/lnwire21/node_announcement.go @@ -5,7 +5,6 @@ import ( "fmt" "image/color" "io" - "io/ioutil" "net" "unicode/utf8" ) @@ -127,7 +126,7 @@ func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error { // we'll collect the remainder into the ExtraOpaqueData field. If there // aren't any bytes, then we'll snip off the slice to avoid carrying // around excess capacity. - a.ExtraOpaqueData, err = ioutil.ReadAll(r) + a.ExtraOpaqueData, err = io.ReadAll(r) if err != nil { return err } diff --git a/cmd/lncli/cmd_payments.go b/cmd/lncli/cmd_payments.go index 550bb8f3e..f9d01ad60 100644 --- a/cmd/lncli/cmd_payments.go +++ b/cmd/lncli/cmd_payments.go @@ -7,7 +7,7 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" + "io" "os" "runtime" "strconv" @@ -987,7 +987,7 @@ func sendToRoute(ctx *cli.Context) error { // The user is signalling that we should read stdin in order to parse // the set of target routes. case args.Present() && args.First() == "-": - b, err := ioutil.ReadAll(os.Stdin) + b, err := io.ReadAll(os.Stdin) if err != nil { return err } diff --git a/config.go b/config.go index f746be041..8a347948b 100644 --- a/config.go +++ b/config.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "errors" "fmt" + "io" "io/ioutil" "net" "os" @@ -2006,7 +2007,7 @@ func extractBtcdRPCParams(btcdConfigPath string) (string, string, error) { // With the file open extract the contents of the configuration file so // we can attempt to locate the RPC credentials. - configContents, err := ioutil.ReadAll(btcdConfigFile) + configContents, err := io.ReadAll(btcdConfigFile) if err != nil { return "", "", err } @@ -2056,7 +2057,7 @@ func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath, // With the file open extract the contents of the configuration file so // we can attempt to locate the RPC credentials. - configContents, err := ioutil.ReadAll(bitcoindConfigFile) + configContents, err := io.ReadAll(bitcoindConfigFile) if err != nil { return "", "", "", "", err } diff --git a/contractcourt/htlc_incoming_contest_resolver_test.go b/contractcourt/htlc_incoming_contest_resolver_test.go index a87b1991c..6c4ba6bc4 100644 --- a/contractcourt/htlc_incoming_contest_resolver_test.go +++ b/contractcourt/htlc_incoming_contest_resolver_test.go @@ -3,7 +3,6 @@ package contractcourt import ( "bytes" "io" - "io/ioutil" "testing" sphinx "github.com/lightningnetwork/lightning-onion" @@ -291,7 +290,7 @@ type mockOnionProcessor struct { func (o *mockOnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte, _ hop.ReconstructBlindingInfo) (hop.Iterator, error) { - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { return nil, err } From ab83343c8718e292c8e392949318678e93df3e56 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 13 Jun 2023 21:22:44 +0700 Subject: [PATCH 2/7] multi: repleace ioutil.ReadFile --- cert/selfsigned_test.go | 18 +++++++++--------- cert/tls.go | 6 +++--- chanbackup/backupfile.go | 3 +-- chanbackup/backupfile_test.go | 3 +-- cmd/lncli/cmd_macaroon.go | 5 +++-- cmd/lncli/cmd_open_channel.go | 3 +-- cmd/lncli/cmd_profile.go | 3 +-- cmd/lncli/cmd_walletunlocker.go | 3 +-- cmd/lncli/commands.go | 3 +-- cmd/lncli/profile.go | 7 ++++--- config.go | 5 ++--- config_builder.go | 3 +-- itest/lnd_channel_backup_test.go | 13 ++++++------- itest/lnd_misc_test.go | 6 +++--- kvdb/backend.go | 2 +- lnd.go | 3 +-- lntest/node/harness_node.go | 2 +- lnwallet/rpcwallet/rpcwallet.go | 6 +++--- lnwallet/transactions_test.go | 4 ++-- routing/pathfind_test.go | 4 ++-- tls_manager_test.go | 9 +++++---- tor/cmd_onion.go | 2 +- tor/controller.go | 4 ++-- 23 files changed, 55 insertions(+), 62 deletions(-) diff --git a/cert/selfsigned_test.go b/cert/selfsigned_test.go index 614225a5a..ca55c2772 100644 --- a/cert/selfsigned_test.go +++ b/cert/selfsigned_test.go @@ -1,7 +1,7 @@ package cert_test import ( - "io/ioutil" + "os" "path/filepath" "testing" "time" @@ -42,10 +42,10 @@ func TestIsOutdatedCert(t *testing.T) { // number of IPs and domains. for numIPs := 1; numIPs <= len(extraIPs); numIPs++ { for numDomains := 1; numDomains <= len(extraDomains); numDomains++ { - certBytes, err := ioutil.ReadFile(certPath) + certBytes, err := os.ReadFile(certPath) require.NoError(t, err) - keyBytes, err := ioutil.ReadFile(keyPath) + keyBytes, err := os.ReadFile(keyPath) require.NoError(t, err) _, parsedCert, err := cert.LoadCertFromBytes( @@ -98,10 +98,10 @@ func TestIsOutdatedPermutation(t *testing.T) { err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes) require.NoError(t, err) - certBytes, err = ioutil.ReadFile(certPath) + certBytes, err = os.ReadFile(certPath) require.NoError(t, err) - keyBytes, err = ioutil.ReadFile(keyPath) + keyBytes, err = os.ReadFile(keyPath) require.NoError(t, err) _, parsedCert, err := cert.LoadCertFromBytes(certBytes, keyBytes) @@ -171,10 +171,10 @@ func TestTLSDisableAutofill(t *testing.T) { require.NoError(t, err) // Read certs from disk. - certBytes, err = ioutil.ReadFile(certPath) + certBytes, err = os.ReadFile(certPath) require.NoError(t, err) - keyBytes, err = ioutil.ReadFile(keyPath) + keyBytes, err = os.ReadFile(keyPath) require.NoError(t, err) // Load the certificate. @@ -230,10 +230,10 @@ func TestTLSConfig(t *testing.T) { err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes) require.NoError(t, err) - certBytes, err = ioutil.ReadFile(certPath) + certBytes, err = os.ReadFile(certPath) require.NoError(t, err) - keyBytes, err = ioutil.ReadFile(keyPath) + keyBytes, err = os.ReadFile(keyPath) require.NoError(t, err) // Load the certificate. diff --git a/cert/tls.go b/cert/tls.go index 4e5d7c81e..6f60ae198 100644 --- a/cert/tls.go +++ b/cert/tls.go @@ -3,7 +3,7 @@ package cert import ( "crypto/tls" "crypto/x509" - "io/ioutil" + "os" "sync" ) @@ -31,11 +31,11 @@ var ( func GetCertBytesFromPath(certPath, keyPath string) (certBytes, keyBytes []byte, err error) { - certBytes, err = ioutil.ReadFile(certPath) + certBytes, err = os.ReadFile(certPath) if err != nil { return nil, nil, err } - keyBytes, err = ioutil.ReadFile(keyPath) + keyBytes, err = os.ReadFile(keyPath) if err != nil { return nil, nil, err } diff --git a/chanbackup/backupfile.go b/chanbackup/backupfile.go index 9c1e788c1..5ba6aa756 100644 --- a/chanbackup/backupfile.go +++ b/chanbackup/backupfile.go @@ -2,7 +2,6 @@ package chanbackup import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -138,7 +137,7 @@ func (b *MultiFile) ExtractMulti(keyChain keychain.KeyRing) (*Multi, error) { // Now that we've confirmed the target file is populated, we'll read // all the contents of the file. This function ensures that file is // always closed, even if we can't read the contents. - multiBytes, err := ioutil.ReadFile(b.fileName) + multiBytes, err := os.ReadFile(b.fileName) if err != nil { return nil, err } diff --git a/chanbackup/backupfile_test.go b/chanbackup/backupfile_test.go index fbd0cc7dd..b0d3ba66f 100644 --- a/chanbackup/backupfile_test.go +++ b/chanbackup/backupfile_test.go @@ -3,7 +3,6 @@ package chanbackup import ( "bytes" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -27,7 +26,7 @@ func assertBackupMatches(t *testing.T, filePath string, t.Helper() - packedBackup, err := ioutil.ReadFile(filePath) + packedBackup, err := os.ReadFile(filePath) require.NoError(t, err, "unable to test file") if !bytes.Equal(packedBackup, currentBackup) { diff --git a/cmd/lncli/cmd_macaroon.go b/cmd/lncli/cmd_macaroon.go index 54e03057a..894e8da6b 100644 --- a/cmd/lncli/cmd_macaroon.go +++ b/cmd/lncli/cmd_macaroon.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "net" + "os" "strconv" "strings" "unicode" @@ -352,7 +353,7 @@ func printMacaroon(ctx *cli.Context) error { macPath := lncfg.CleanAndExpandPath(ctx.String("macaroon_file")) // Load the specified macaroon file. - macBytes, err = ioutil.ReadFile(macPath) + macBytes, err = os.ReadFile(macPath) if err != nil { return fmt.Errorf("unable to read macaroon path %v: %v", macPath, err) @@ -441,7 +442,7 @@ func constrainMacaroon(ctx *cli.Context) error { sourceMacFile := lncfg.CleanAndExpandPath(args.First()) args = args.Tail() - sourceMacBytes, err := ioutil.ReadFile(sourceMacFile) + sourceMacBytes, err := os.ReadFile(sourceMacFile) if err != nil { return fmt.Errorf("error trying to read source macaroon file "+ "%s: %v", sourceMacFile, err) diff --git a/cmd/lncli/cmd_open_channel.go b/cmd/lncli/cmd_open_channel.go index 74cb1668a..e3044c835 100644 --- a/cmd/lncli/cmd_open_channel.go +++ b/cmd/lncli/cmd_open_channel.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "strconv" "strings" @@ -1016,7 +1015,7 @@ func readTerminalOrFile(quit chan struct{}) (string, error) { // If it's a path to an existing file and it's small enough, let's try // to read its content now. - content, err := ioutil.ReadFile(maybeFile) + content, err := os.ReadFile(maybeFile) if err != nil { return "", err } diff --git a/cmd/lncli/cmd_profile.go b/cmd/lncli/cmd_profile.go index 21666be96..3b1bf6487 100644 --- a/cmd/lncli/cmd_profile.go +++ b/cmd/lncli/cmd_profile.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "path" "strings" @@ -423,7 +422,7 @@ func profileAddMacaroon(ctx *cli.Context) error { // Now load and possibly encrypt the macaroon file. macPath := lncfg.CleanAndExpandPath(ctx.GlobalString("macaroonpath")) - macBytes, err := ioutil.ReadFile(macPath) + macBytes, err := os.ReadFile(macPath) if err != nil { return fmt.Errorf("unable to read macaroon path: %w", err) } diff --git a/cmd/lncli/cmd_walletunlocker.go b/cmd/lncli/cmd_walletunlocker.go index 9227d10d4..650ef80ea 100644 --- a/cmd/lncli/cmd_walletunlocker.go +++ b/cmd/lncli/cmd_walletunlocker.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/hex" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -712,7 +711,7 @@ func createWatchOnly(ctx *cli.Context) error { } jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First()) - jsonBytes, err := ioutil.ReadFile(jsonFile) + jsonBytes, err := os.ReadFile(jsonFile) if err != nil { return fmt.Errorf("error reading JSON from file %v: %v", jsonFile, err) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 5ffca5c73..a510138eb 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math" "os" "strconv" @@ -2833,7 +2832,7 @@ func parseChanBackups(ctx *cli.Context) (*lnrpc.RestoreChanBackupRequest, error) }, nil case ctx.IsSet("multi_file"): - packedMulti, err := ioutil.ReadFile(ctx.String("multi_file")) + packedMulti, err := os.ReadFile(ctx.String("multi_file")) if err != nil { return nil, fmt.Errorf("unable to decode multi packed "+ "backup: %v", err) diff --git a/cmd/lncli/profile.go b/cmd/lncli/profile.go index 90ac69c0e..75dc9ab72 100644 --- a/cmd/lncli/profile.go +++ b/cmd/lncli/profile.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io/ioutil" + "os" "path" "strings" @@ -129,7 +130,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) ( var tlsCert []byte if tlsCertPath != "" && !insecure { var err error - tlsCert, err = ioutil.ReadFile(tlsCertPath) + tlsCert, err = os.ReadFile(tlsCertPath) if err != nil { return nil, fmt.Errorf("could not load TLS cert "+ "file: %v", err) @@ -167,7 +168,7 @@ func profileFromContext(ctx *cli.Context, store, skipMacaroons bool) ( } // Now load and possibly encrypt the macaroon file. - macBytes, err := ioutil.ReadFile(macPath) + macBytes, err := os.ReadFile(macPath) if err != nil { return nil, fmt.Errorf("unable to read macaroon path (check "+ "the network setting!): %v", err) @@ -222,7 +223,7 @@ func loadProfileFile(file string) (*profileFile, error) { return nil, errNoProfileFile } - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { return nil, fmt.Errorf("could not load profile file %s: %w", file, err) diff --git a/config.go b/config.go index 8a347948b..7084500b4 100644 --- a/config.go +++ b/config.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "os" "os/user" @@ -1846,7 +1845,7 @@ func parseRPCParams(cConfig *lncfg.Chain, nodeConfig interface{}, // We convert the cookie into a user name and password. if conf.RPCCookie != "" { - cookie, err := ioutil.ReadFile(conf.RPCCookie) + cookie, err := os.ReadFile(conf.RPCCookie) if err != nil { return fmt.Errorf("cannot read cookie file: %w", err) @@ -2119,7 +2118,7 @@ func extractBitcoindRPCParams(networkName, bitcoindDataDir, bitcoindConfigPath, if rpcCookiePath != "" { cookiePath = rpcCookiePath } - cookie, err := ioutil.ReadFile(cookiePath) + cookie, err := os.ReadFile(cookiePath) if err == nil { splitCookie := strings.Split(string(cookie), ":") if len(splitCookie) == 2 { diff --git a/config_builder.go b/config_builder.go index bbf291506..895f7e4ad 100644 --- a/config_builder.go +++ b/config_builder.go @@ -6,7 +6,6 @@ import ( "database/sql" "errors" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -329,7 +328,7 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context, case d.cfg.WalletUnlockPasswordFile != "" && walletExists: d.logger.Infof("Attempting automatic wallet unlock with " + "password provided in file") - pwBytes, err := ioutil.ReadFile(d.cfg.WalletUnlockPasswordFile) + pwBytes, err := os.ReadFile(d.cfg.WalletUnlockPasswordFile) if err != nil { return nil, nil, nil, fmt.Errorf("error reading "+ "password from file %s: %v", diff --git a/itest/lnd_channel_backup_test.go b/itest/lnd_channel_backup_test.go index c29859e32..0e7393dc3 100644 --- a/itest/lnd_channel_backup_test.go +++ b/itest/lnd_channel_backup_test.go @@ -3,7 +3,6 @@ package itest import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "strconv" @@ -285,7 +284,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) { // Read the entire Multi backup stored within // this node's channel.backup file. - multi, err := ioutil.ReadFile(backupFilePath) + multi, err := os.ReadFile(backupFilePath) require.NoError(st, err) // Now that we have Dave's backup file, we'll @@ -376,7 +375,7 @@ func testChannelBackupRestoreBasic(ht *lntest.HarnessTest) { // Read the entire Multi backup stored within // this node's channel.backup file. - multi, err := ioutil.ReadFile(backupFilePath) + multi, err := os.ReadFile(backupFilePath) require.NoError(st, err) // Now that we have Dave's backup file, we'll @@ -501,7 +500,7 @@ func runChanRestoreScenarioUnConfirmed(ht *lntest.HarnessTest, useFile bool) { backupFilePath := dave.Cfg.ChanBackupPath() // Read the entire Multi backup stored within this node's // channel.backup file. - multi, err = ioutil.ReadFile(backupFilePath) + multi, err = os.ReadFile(backupFilePath) require.NoError(ht, err) } else { // For this restoration method, we'll grab the current @@ -646,7 +645,7 @@ func runChanRestoreScenarioCommitTypes(ht *lntest.HarnessTest, // Read the entire Multi backup stored within this node's // channels.backup file. - multi, err := ioutil.ReadFile(backupFilePath) + multi, err := os.ReadFile(backupFilePath) require.NoError(ht, err) // If this was a zero conf taproot channel, then since it's private, @@ -774,7 +773,7 @@ func runChanRestoreScenarioForceClose(ht *lntest.HarnessTest, zeroConf bool) { // Read the entire Multi backup stored within this node's // channel.backup file. - multi, err := ioutil.ReadFile(backupFilePath) + multi, err := os.ReadFile(backupFilePath) require.NoError(ht, err) // Now that we have Dave's backup file, we'll create a new nodeRestorer @@ -907,7 +906,7 @@ func testChannelBackupUpdates(ht *lntest.HarnessTest) { // the on disk back up file to our currentBackup pointer above. assertBackupFileState := func() { err := wait.NoError(func() error { - packedBackup, err := ioutil.ReadFile(backupFilePath) + packedBackup, err := os.ReadFile(backupFilePath) if err != nil { return fmt.Errorf("unable to read backup "+ "file: %v", err) diff --git a/itest/lnd_misc_test.go b/itest/lnd_misc_test.go index 7124f1488..163fc436d 100644 --- a/itest/lnd_misc_test.go +++ b/itest/lnd_misc_test.go @@ -4,7 +4,7 @@ import ( "context" "encoding/hex" "fmt" - "io/ioutil" + "os" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/txscript" @@ -708,7 +708,7 @@ func testAbandonChannel(ht *lntest.HarnessTest) { // To make sure the channel is removed from the backup file as well // when being abandoned, grab a backup snapshot so we can compare it // with the later state. - bkupBefore, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath()) + bkupBefore, err := os.ReadFile(alice.Cfg.ChanBackupPath()) require.NoError(ht, err, "channel backup before abandoning channel") // Send request to abandon channel. @@ -733,7 +733,7 @@ func testAbandonChannel(ht *lntest.HarnessTest) { // Make sure the channel is no longer in the channel backup list. err = wait.NoError(func() error { - bkupAfter, err := ioutil.ReadFile(alice.Cfg.ChanBackupPath()) + bkupAfter, err := os.ReadFile(alice.Cfg.ChanBackupPath()) if err != nil { return fmt.Errorf("could not get channel backup "+ "before abandoning channel: %v", err) diff --git a/kvdb/backend.go b/kvdb/backend.go index f034cee7e..c115c4f7d 100644 --- a/kvdb/backend.go +++ b/kvdb/backend.go @@ -218,7 +218,7 @@ func lastCompactionDate(dbFile string) (time.Time, error) { return zeroTime, nil } - tsBytes, err := ioutil.ReadFile(tsFile) + tsBytes, err := os.ReadFile(tsFile) if err != nil { return zeroTime, err } diff --git a/lnd.go b/lnd.go index f4ef03a07..0a85e1bf3 100644 --- a/lnd.go +++ b/lnd.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net" "net/http" "net/http/pprof" @@ -83,7 +82,7 @@ func AdminAuthOptions(cfg *Config, skipMacaroons bool) ([]grpc.DialOption, // Get the admin macaroon if macaroons are active. if !skipMacaroons && !cfg.NoMacaroons { // Load the admin macaroon file. - macBytes, err := ioutil.ReadFile(cfg.AdminMacPath) + macBytes, err := os.ReadFile(cfg.AdminMacPath) if err != nil { return nil, fmt.Errorf("unable to read macaroon "+ "path (check the network setting!): %v", err) diff --git a/lntest/node/harness_node.go b/lntest/node/harness_node.go index de6f40a77..1afb095d8 100644 --- a/lntest/node/harness_node.go +++ b/lntest/node/harness_node.go @@ -297,7 +297,7 @@ func (hn *HarnessNode) ReadMacaroon(macPath string, timeout time.Duration) ( // using it. var mac *macaroon.Macaroon err := wait.NoError(func() error { - macBytes, err := ioutil.ReadFile(macPath) + macBytes, err := os.ReadFile(macPath) if err != nil { return fmt.Errorf("error reading macaroon file: %w", err) diff --git a/lnwallet/rpcwallet/rpcwallet.go b/lnwallet/rpcwallet/rpcwallet.go index 5a16490e5..13f435579 100644 --- a/lnwallet/rpcwallet/rpcwallet.go +++ b/lnwallet/rpcwallet/rpcwallet.go @@ -7,7 +7,7 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" + "os" "time" "github.com/btcsuite/btcd/btcec/v2" @@ -1259,7 +1259,7 @@ func extractSignature(in *psbt.PInput, func connectRPC(hostPort, tlsCertPath, macaroonPath string, timeout time.Duration) (*grpc.ClientConn, error) { - certBytes, err := ioutil.ReadFile(tlsCertPath) + certBytes, err := os.ReadFile(tlsCertPath) if err != nil { return nil, fmt.Errorf("error reading TLS cert file %v: %w", tlsCertPath, err) @@ -1271,7 +1271,7 @@ func connectRPC(hostPort, tlsCertPath, macaroonPath string, "certificate") } - macBytes, err := ioutil.ReadFile(macaroonPath) + macBytes, err := os.ReadFile(macaroonPath) if err != nil { return nil, fmt.Errorf("error reading macaroon file %v: %w", macaroonPath, err) diff --git a/lnwallet/transactions_test.go b/lnwallet/transactions_test.go index ab0ef7328..1f15523c4 100644 --- a/lnwallet/transactions_test.go +++ b/lnwallet/transactions_test.go @@ -8,8 +8,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" + "os" "sort" "strings" "testing" @@ -229,7 +229,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) { var testCases []testCase - jsonText, err := ioutil.ReadFile(set.jsonFile) + jsonText, err := os.ReadFile(set.jsonFile) require.NoError(t, err) err = json.Unmarshal(jsonText, &testCases) diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index de4935a81..57f723ce6 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -8,9 +8,9 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math" "net" + "os" "reflect" "strings" "testing" @@ -183,7 +183,7 @@ func makeTestGraph(t *testing.T, useCache bool) (*channeldb.ChannelGraph, func parseTestGraph(t *testing.T, useCache bool, path string) ( *testGraphInstance, error) { - graphJSON, err := ioutil.ReadFile(path) + graphJSON, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/tls_manager_test.go b/tls_manager_test.go index 935834971..348f095bc 100644 --- a/tls_manager_test.go +++ b/tls_manager_test.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "math/big" "net" + "os" "testing" "time" @@ -199,7 +200,7 @@ func TestGenerateEphemeralCert(t *testing.T) { keyBytes, err := tlsManager.loadEphemeralCertificate() require.NoError(t, err, "failed to generate new certificate") - certBytes, err := ioutil.ReadFile(tmpCertPath) + certBytes, err := os.ReadFile(tmpCertPath) require.NoError(t, err) tlsr, err := cert.NewTLSReloader(certBytes, keyBytes) @@ -207,15 +208,15 @@ func TestGenerateEphemeralCert(t *testing.T) { tlsManager.tlsReloader = tlsr // Make sure .tmp file is created at the tmp cert path. - _, err = ioutil.ReadFile(tmpCertPath) + _, err = os.ReadFile(tmpCertPath) require.NoError(t, err, "couldn't find temp cert file") // But no key should be stored. - _, err = ioutil.ReadFile(cfg.TLSKeyPath) + _, err = os.ReadFile(cfg.TLSKeyPath) require.Error(t, err, "shouldn't have found file") // And no permanent cert file should be stored. - _, err = ioutil.ReadFile(cfg.TLSCertPath) + _, err = os.ReadFile(cfg.TLSCertPath) require.Error(t, err, "shouldn't have found a permanent cert file") // Now test that when we reload the certificate it generates the new diff --git a/tor/cmd_onion.go b/tor/cmd_onion.go index 72f508fc0..3ac928b40 100644 --- a/tor/cmd_onion.go +++ b/tor/cmd_onion.go @@ -124,7 +124,7 @@ func (f *OnionFile) PrivateKey() ([]byte, error) { } // Try to read the Tor private key to pass into the AddOnion call. - privateKeyContent, err := ioutil.ReadFile(f.privateKeyPath) + privateKeyContent, err := os.ReadFile(f.privateKeyPath) if err != nil { return nil, err } diff --git a/tor/controller.go b/tor/controller.go index 241b3ddbe..47ea6e129 100644 --- a/tor/controller.go +++ b/tor/controller.go @@ -8,8 +8,8 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" "net/textproto" + "os" "regexp" "strconv" "strings" @@ -597,7 +597,7 @@ func (c *Controller) getAuthCookie(info protocolInfo) ([]byte, error) { cookieFilePath = strings.Trim(cookieFilePath, "\"") // Read the cookie from the file and ensure it has the correct length. - cookie, err := ioutil.ReadFile(cookieFilePath) + cookie, err := os.ReadFile(cookieFilePath) if err != nil { return nil, err } From 789c6bac8ca4b75d15e9e40f8ded8e394df518bb Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 14 Jun 2023 11:33:44 +0200 Subject: [PATCH 3/7] multi: replace ioutil.WriteFile --- cert/selfsigned.go | 5 ++--- cmd/lncli/cmd_macaroon.go | 5 ++--- cmd/lncli/profile.go | 4 ++-- internal/musig2v040/musig2_test.go | 8 ++++---- kvdb/backend.go | 3 +-- lnrpc/chainrpc/chain_server.go | 3 +-- lnrpc/invoicesrpc/invoices_server.go | 3 +-- lnrpc/routerrpc/router_server.go | 3 +-- lnrpc/signrpc/signer_server.go | 3 +-- lnrpc/walletrpc/walletkit_server.go | 3 +-- tls_manager.go | 3 +-- tls_manager_test.go | 5 ++--- tor/cmd_onion.go | 3 +-- 13 files changed, 20 insertions(+), 31 deletions(-) diff --git a/cert/selfsigned.go b/cert/selfsigned.go index c956afb00..80fe42106 100644 --- a/cert/selfsigned.go +++ b/cert/selfsigned.go @@ -9,7 +9,6 @@ import ( "crypto/x509/pkix" "encoding/pem" "fmt" - "io/ioutil" "math/big" "net" "os" @@ -295,14 +294,14 @@ func GenCertPair(org string, tlsExtraIPs, tlsExtraDomains []string, func WriteCertPair(certFile, keyFile string, certBytes, keyBytes []byte) error { // Write cert and key files. if certFile != "" { - err := ioutil.WriteFile(certFile, certBytes, 0644) + err := os.WriteFile(certFile, certBytes, 0644) if err != nil { return err } } if keyFile != "" { - err := ioutil.WriteFile(keyFile, keyBytes, 0600) + err := os.WriteFile(keyFile, keyBytes, 0600) if err != nil { os.Remove(certFile) return err diff --git a/cmd/lncli/cmd_macaroon.go b/cmd/lncli/cmd_macaroon.go index 894e8da6b..deea4e7ad 100644 --- a/cmd/lncli/cmd_macaroon.go +++ b/cmd/lncli/cmd_macaroon.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/hex" "fmt" - "io/ioutil" "net" "os" "strconv" @@ -193,7 +192,7 @@ func bakeMacaroon(ctx *cli.Context) error { // a file or write to the standard output using hex encoding. switch { case savePath != "": - err = ioutil.WriteFile(savePath, macBytes, 0644) + err = os.WriteFile(savePath, macBytes, 0644) if err != nil { return err } @@ -472,7 +471,7 @@ func constrainMacaroon(ctx *cli.Context) error { } // Now we can output the result. - err = ioutil.WriteFile(destMacFile, destMacBytes, 0644) + err = os.WriteFile(destMacFile, destMacBytes, 0644) if err != nil { return fmt.Errorf("error writing destination macaroon file "+ "%s: %v", destMacFile, err) diff --git a/cmd/lncli/profile.go b/cmd/lncli/profile.go index 75dc9ab72..efbdfc147 100644 --- a/cmd/lncli/profile.go +++ b/cmd/lncli/profile.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path" "strings" @@ -244,7 +243,8 @@ func saveProfileFile(file string, f *profileFile) error { if err != nil { return fmt.Errorf("could not marshal profile: %w", err) } - return ioutil.WriteFile(file, content, 0644) + + return os.WriteFile(file, content, 0644) } // profileFile is a struct that represents the whole content of a profile file. diff --git a/internal/musig2v040/musig2_test.go b/internal/musig2v040/musig2_test.go index 9ba74f417..47fd71c76 100644 --- a/internal/musig2v040/musig2_test.go +++ b/internal/musig2v040/musig2_test.go @@ -10,7 +10,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "os" "sync" "testing" @@ -256,7 +256,7 @@ func TestMuSig2KeyAggTestVectors(t *testing.T) { var formattedJson bytes.Buffer json.Indent(&formattedJson, jsonBytes, "", "\t") - err = ioutil.WriteFile( + err = os.WriteFile( keyAggTestVectorName, formattedJson.Bytes(), 0644, ) if err != nil { @@ -656,7 +656,7 @@ func TestMuSig2SigningTestVectors(t *testing.T) { var formattedJson bytes.Buffer json.Indent(&formattedJson, jsonBytes, "", "\t") - err = ioutil.WriteFile( + err = os.WriteFile( signTestVectorName, formattedJson.Bytes(), 0644, ) if err != nil { @@ -1540,7 +1540,7 @@ func TestMusig2AggregateNoncesTestVectors(t *testing.T) { var formattedJson bytes.Buffer json.Indent(&formattedJson, jsonBytes, "", "\t") - err = ioutil.WriteFile( + err = os.WriteFile( nonceAggTestVectorName, formattedJson.Bytes(), 0644, ) if err != nil { diff --git a/kvdb/backend.go b/kvdb/backend.go index c115c4f7d..e42c02233 100644 --- a/kvdb/backend.go +++ b/kvdb/backend.go @@ -9,7 +9,6 @@ import ( "encoding/binary" "encoding/hex" "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -235,7 +234,7 @@ func updateLastCompactionDate(dbFile string) error { byteOrder.PutUint64(tsBytes[:], uint64(time.Now().UnixNano())) tsFile := fmt.Sprintf("%s%s", dbFile, LastCompactionFileNameSuffix) - return ioutil.WriteFile(tsFile, tsBytes[:], 0600) + return os.WriteFile(tsFile, tsBytes[:], 0600) } // GetTestBackend opens (or creates if doesn't exist) a bbolt or etcd diff --git a/lnrpc/chainrpc/chain_server.go b/lnrpc/chainrpc/chain_server.go index 00a30c07c..1defadafc 100644 --- a/lnrpc/chainrpc/chain_server.go +++ b/lnrpc/chainrpc/chain_server.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "errors" - "io/ioutil" "os" "path/filepath" "sync" @@ -153,7 +152,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) { if err != nil { return nil, nil, err } - err = ioutil.WriteFile(macFilePath, chainNotifierMacBytes, 0644) + err = os.WriteFile(macFilePath, chainNotifierMacBytes, 0644) if err != nil { _ = os.Remove(macFilePath) return nil, nil, err diff --git a/lnrpc/invoicesrpc/invoices_server.go b/lnrpc/invoicesrpc/invoices_server.go index b62538543..23b8722ca 100644 --- a/lnrpc/invoicesrpc/invoices_server.go +++ b/lnrpc/invoicesrpc/invoices_server.go @@ -7,7 +7,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "path/filepath" @@ -132,7 +131,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) { if err != nil { return nil, nil, err } - err = ioutil.WriteFile(macFilePath, invoicesMacBytes, 0644) + err = os.WriteFile(macFilePath, invoicesMacBytes, 0644) if err != nil { _ = os.Remove(macFilePath) return nil, nil, err diff --git a/lnrpc/routerrpc/router_server.go b/lnrpc/routerrpc/router_server.go index 194bdc996..090fef0ed 100644 --- a/lnrpc/routerrpc/router_server.go +++ b/lnrpc/routerrpc/router_server.go @@ -6,7 +6,6 @@ import ( crand "crypto/rand" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "sync/atomic" @@ -216,7 +215,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) { if err != nil { return nil, nil, err } - err = ioutil.WriteFile(macFilePath, routerMacBytes, 0644) + err = os.WriteFile(macFilePath, routerMacBytes, 0644) if err != nil { _ = os.Remove(macFilePath) return nil, nil, err diff --git a/lnrpc/signrpc/signer_server.go b/lnrpc/signrpc/signer_server.go index c29d495eb..4b2ac2c6a 100644 --- a/lnrpc/signrpc/signer_server.go +++ b/lnrpc/signrpc/signer_server.go @@ -8,7 +8,6 @@ import ( "context" "crypto/sha256" "fmt" - "io/ioutil" "os" "path/filepath" @@ -167,7 +166,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) { if err != nil { return nil, nil, err } - err = ioutil.WriteFile(macFilePath, signerMacBytes, 0644) + err = os.WriteFile(macFilePath, signerMacBytes, 0644) if err != nil { _ = os.Remove(macFilePath) return nil, nil, err diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index d3f5131b0..a00c38207 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -10,7 +10,6 @@ import ( "encoding/binary" "errors" "fmt" - "io/ioutil" "math" "os" "path/filepath" @@ -289,7 +288,7 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) { if err != nil { return nil, nil, err } - err = ioutil.WriteFile(macFilePath, walletKitMacBytes, 0644) + err = os.WriteFile(macFilePath, walletKitMacBytes, 0644) if err != nil { _ = os.Remove(macFilePath) return nil, nil, err diff --git a/tls_manager.go b/tls_manager.go index 7801279fa..076cf44bc 100644 --- a/tls_manager.go +++ b/tls_manager.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "errors" "fmt" - "io/ioutil" "net" "net/http" "os" @@ -279,7 +278,7 @@ func (t *TLSManager) ensureEncryption(keyRing keychain.SecretKeyRing) error { if err != nil { return err } - err = ioutil.WriteFile( + err = os.WriteFile( t.cfg.TLSKeyPath, b.Bytes(), modifyFilePermissions, ) if err != nil { diff --git a/tls_manager_test.go b/tls_manager_test.go index 348f095bc..42f010411 100644 --- a/tls_manager_test.go +++ b/tls_manager_test.go @@ -9,7 +9,6 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/pem" - "io/ioutil" "math/big" "net" "os" @@ -351,9 +350,9 @@ func writeTestCertFiles(t *testing.T, expiredCert, encryptTLSKey bool, require.NoError(t, err, "failed to encrypt private key") } - err = ioutil.WriteFile(tempDir+"/tls.cert", certBuf.Bytes(), 0644) + err = os.WriteFile(tempDir+"/tls.cert", certBuf.Bytes(), 0644) require.NoError(t, err, "failed to write cert file") - err = ioutil.WriteFile(tempDir+"/tls.key", keyBuf.Bytes(), 0600) + err = os.WriteFile(tempDir+"/tls.key", keyBuf.Bytes(), 0600) require.NoError(t, err, "failed to write key file") return certPath, keyPath, parsedCert diff --git a/tor/cmd_onion.go b/tor/cmd_onion.go index 3ac928b40..6e60504a9 100644 --- a/tor/cmd_onion.go +++ b/tor/cmd_onion.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" ) @@ -105,7 +104,7 @@ func (f *OnionFile) StorePrivateKey(privateKey []byte) error { privateKeyContent = b.Bytes() } - err := ioutil.WriteFile( + err := os.WriteFile( f.privateKeyPath, privateKeyContent, f.privateKeyPerm, ) if err != nil { From c7f81d314230c11ab3d5333340b652336bb03302 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 14 Jun 2023 11:40:27 +0200 Subject: [PATCH 4/7] multi: replace ioutil.Discard --- lnwire/onion_error.go | 3 +-- tlv/stream.go | 3 +-- watchtower/tlv_bench_test.go | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lnwire/onion_error.go b/lnwire/onion_error.go index 8b7fc733b..66db6a9f5 100644 --- a/lnwire/onion_error.go +++ b/lnwire/onion_error.go @@ -7,7 +7,6 @@ import ( "encoding/binary" "fmt" "io" - "io/ioutil" "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" @@ -1304,7 +1303,7 @@ func DecodeFailure(r io.Reader, pver uint32) (FailureMessage, error) { return nil, fmt.Errorf("unable to read pad len: %w", err) } - if _, err := io.CopyN(ioutil.Discard, r, int64(padLength)); err != nil { + if _, err := io.CopyN(io.Discard, r, int64(padLength)); err != nil { return nil, fmt.Errorf("unable to read padding %w", err) } diff --git a/tlv/stream.go b/tlv/stream.go index 3d353ad22..70fade22d 100644 --- a/tlv/stream.go +++ b/tlv/stream.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "math" ) @@ -262,7 +261,7 @@ func (s *Stream) decode(r io.Reader, parsedTypes TypeMap, p2p bool) (TypeMap, // If the caller provided an initialized TypeMap, record // the encoded bytes. var b *bytes.Buffer - writer := ioutil.Discard + writer := io.Discard if parsedTypes != nil { b = bytes.NewBuffer(make([]byte, 0, length)) writer = b diff --git a/watchtower/tlv_bench_test.go b/watchtower/tlv_bench_test.go index 5ffabde08..e6d8decd7 100644 --- a/watchtower/tlv_bench_test.go +++ b/watchtower/tlv_bench_test.go @@ -3,7 +3,6 @@ package watchtower_test import ( "bytes" "io" - "io/ioutil" "testing" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -104,7 +103,7 @@ func BenchmarkEncodeCreateSession(t *testing.B) { var err error for i := 0; i < t.N; i++ { - err = m.Encode(ioutil.Discard, 0) + err = m.Encode(io.Discard, 0) } require.NoError(t, err) } @@ -118,7 +117,7 @@ func BenchmarkEncodeCreateSessionTLV(t *testing.B) { var err error for i := 0; i < t.N; i++ { - err = m.Encode(ioutil.Discard) + err = m.Encode(io.Discard) } require.NoError(t, err) } From caf2419ff603c90527d1e5a96d653596c116acaa Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 14 Jun 2023 11:43:51 +0200 Subject: [PATCH 5/7] multi: replace ioutil.ReadDir --- lntest/btcd.go | 3 +-- lntest/harness_miner.go | 3 +-- lntest/node/harness_node.go | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lntest/btcd.go b/lntest/btcd.go index 09f33472b..2d735fa2b 100644 --- a/lntest/btcd.go +++ b/lntest/btcd.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "io/ioutil" "os" "strings" @@ -135,7 +134,7 @@ func NewBackend(miner string, netParams *chaincfg.Params) ( // the log files, including any compressed log files from // logrorate, before deleting the temporary log dir. logDir := fmt.Sprintf("%s/%s", baseLogDir, netParams.Name) - files, err := ioutil.ReadDir(logDir) + files, err := os.ReadDir(logDir) if err != nil { errStr += fmt.Sprintf( "unable to read log directory: %v\n", err, diff --git a/lntest/harness_miner.go b/lntest/harness_miner.go index a28715321..f6348c078 100644 --- a/lntest/harness_miner.go +++ b/lntest/harness_miner.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -121,7 +120,7 @@ func (h *HarnessMiner) saveLogs() { // After shutting down the miner, we'll make a copy of the log files // before deleting the temporary log dir. path := fmt.Sprintf("%s/%s", h.logPath, harnessNetParams.Name) - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) require.NoError(h, err, "unable to read log directory") for _, file := range files { diff --git a/lntest/node/harness_node.go b/lntest/node/harness_node.go index 1afb095d8..629497367 100644 --- a/lntest/node/harness_node.go +++ b/lntest/node/harness_node.go @@ -1032,7 +1032,7 @@ func addLogFile(hn *HarnessNode) error { // copyAll copies all files and directories from srcDir to dstDir recursively. // Note that this function does not support links. func copyAll(dstDir, srcDir string) error { - entries, err := ioutil.ReadDir(srcDir) + entries, err := os.ReadDir(srcDir) if err != nil { return err } From df4ddcc57377fa1a0ccafe37e7ecb42f34147211 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 14 Jun 2023 11:45:56 +0200 Subject: [PATCH 6/7] multi: replace ioutil.TempDir --- htlcswitch/mock.go | 3 +-- lntest/bitcoind_common.go | 3 +-- lntest/node/harness_node.go | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index a0f38c74f..dfa834c58 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -7,7 +7,6 @@ import ( "encoding/binary" "fmt" "io" - "io/ioutil" "net" "os" "path/filepath" @@ -947,7 +946,7 @@ var _ ChannelLink = (*mockChannelLink)(nil) func newDB() (*channeldb.DB, func(), error) { // First, create a temporary directory to be used for the duration of // this test. - tempDirName, err := ioutil.TempDir("", "channeldb") + tempDirName, err := os.MkdirTemp("", "channeldb") if err != nil { return nil, nil, err } diff --git a/lntest/bitcoind_common.go b/lntest/bitcoind_common.go index 657da7cd3..9cbcd23fd 100644 --- a/lntest/bitcoind_common.go +++ b/lntest/bitcoind_common.go @@ -6,7 +6,6 @@ package lntest import ( "errors" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -105,7 +104,7 @@ func newBackend(miner string, netParams *chaincfg.Params, extraArgs []string, return nil, nil, err } - tempBitcoindDir, err := ioutil.TempDir("", "bitcoind") + tempBitcoindDir, err := os.MkdirTemp("", "bitcoind") if err != nil { return nil, nil, fmt.Errorf("unable to create temp directory: %w", err) diff --git a/lntest/node/harness_node.go b/lntest/node/harness_node.go index 629497367..3df5a8e64 100644 --- a/lntest/node/harness_node.go +++ b/lntest/node/harness_node.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -824,7 +823,7 @@ func (hn *HarnessNode) BackupDB() error { } } else { // Backup files. - tempDir, err := ioutil.TempDir("", "past-state") + tempDir, err := os.MkdirTemp("", "past-state") if err != nil { return fmt.Errorf("unable to create temp db folder: %w", err) From 0d94131fca691596e4c46c3c07eb34879baf7dc7 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 14 Jun 2023 11:48:44 +0200 Subject: [PATCH 7/7] doc: release note --- docs/release-notes/release-notes-0.18.0.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/release-notes-0.18.0.md b/docs/release-notes/release-notes-0.18.0.md index f59ae179b..b70cbfac2 100644 --- a/docs/release-notes/release-notes-0.18.0.md +++ b/docs/release-notes/release-notes-0.18.0.md @@ -389,7 +389,10 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor In particular, the complexity involved in the lifecycle loop has been decoupled into logical steps, with each step having its own responsibility, making it easier to reason about the payment flow. - + +* [Remove io/ioutil package + dependence](https://github.com/lightningnetwork/lnd/pull/7765). + * [Add a watchtower tower client multiplexer](https://github.com/lightningnetwork/lnd/pull/7702) to manage tower clients of different types.