mirror of
https://github.com/btcsuite/btcd.git
synced 2024-11-19 01:40:07 +01:00
multi: fix ioutil deprecated function
update i/o functions to use os / io package functions instead
This commit is contained in:
parent
447c95c9c2
commit
b66f5b8379
@ -1,7 +1,6 @@
|
||||
package addrmgr
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
@ -108,7 +107,7 @@ func TestAddrManagerSerialization(t *testing.T) {
|
||||
|
||||
// We'll start by creating our address manager backed by a temporary
|
||||
// directory.
|
||||
tempDir, err := ioutil.TempDir("", "addrmgr")
|
||||
tempDir, err := os.MkdirTemp("", "addrmgr")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
@ -148,7 +147,7 @@ func TestAddrManagerV1ToV2(t *testing.T) {
|
||||
|
||||
// We'll start by creating our address manager backed by a temporary
|
||||
// directory.
|
||||
tempDir, err := ioutil.TempDir("", "addrmgr")
|
||||
tempDir, err := os.MkdirTemp("", "addrmgr")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp dir: %v", err)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package txsort_test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -64,7 +64,7 @@ func TestSort(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
// Load and deserialize the test transaction.
|
||||
filePath := filepath.Join("testdata", test.hexFile)
|
||||
txHexBytes, err := ioutil.ReadFile(filePath)
|
||||
txHexBytes, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
t.Errorf("ReadFile (%s): failed to read test file: %v",
|
||||
test.name, err)
|
||||
|
@ -6,9 +6,10 @@ import (
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/go-socks/socks"
|
||||
@ -37,7 +38,7 @@ func newHTTPClient(cfg *config) (*http.Client, error) {
|
||||
// Configure TLS if needed.
|
||||
var tlsConfig *tls.Config
|
||||
if !cfg.NoTLS && cfg.RPCCert != "" {
|
||||
pem, err := ioutil.ReadFile(cfg.RPCCert)
|
||||
pem, err := os.ReadFile(cfg.RPCCert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -95,7 +96,7 @@ func sendPostRequest(marshalledJSON []byte, cfg *config) ([]byte, error) {
|
||||
}
|
||||
|
||||
// Read the raw bytes and close the response.
|
||||
respBytes, err := ioutil.ReadAll(httpResponse.Body)
|
||||
respBytes, err := io.ReadAll(httpResponse.Body)
|
||||
httpResponse.Body.Close()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error reading json reply: %v", err)
|
||||
|
@ -6,7 +6,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -65,11 +64,11 @@ func main() {
|
||||
}
|
||||
|
||||
// Write cert and key files.
|
||||
if err = ioutil.WriteFile(certFile, cert, 0666); err != nil {
|
||||
if err = os.WriteFile(certFile, cert, 0666); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cannot write cert: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err = ioutil.WriteFile(keyFile, key, 0600); err != nil {
|
||||
if err = os.WriteFile(keyFile, key, 0600); err != nil {
|
||||
os.Remove(certFile)
|
||||
fmt.Fprintf(os.Stderr, "cannot write key: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@ -23,14 +22,14 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
||||
sampleConfigFile := filepath.Join(filepath.Dir(path), "sample-btcd.conf")
|
||||
|
||||
// Setup a temporary directory
|
||||
tmpDir, err := ioutil.TempDir("", "btcd")
|
||||
tmpDir, err := os.MkdirTemp("", "btcd")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed creating a temporary directory: %v", err)
|
||||
}
|
||||
testpath := filepath.Join(tmpDir, "test.conf")
|
||||
|
||||
// copy config file to location of btcd binary
|
||||
data, err := ioutil.ReadFile(sampleConfigFile)
|
||||
data, err := os.ReadFile(sampleConfigFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed reading sample config file: %v", err)
|
||||
}
|
||||
@ -39,7 +38,7 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
||||
t.Fatalf("Failed obtaining app path: %v", err)
|
||||
}
|
||||
tmpConfigFile := filepath.Join(appPath, "sample-btcd.conf")
|
||||
err = ioutil.WriteFile(tmpConfigFile, data, 0644)
|
||||
err = os.WriteFile(tmpConfigFile, data, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed copying sample config file: %v", err)
|
||||
}
|
||||
@ -57,7 +56,7 @@ func TestCreateDefaultConfigFile(t *testing.T) {
|
||||
t.Fatalf("Failed to create a default config file: %v", err)
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadFile(testpath)
|
||||
content, err := os.ReadFile(testpath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read generated default config file: %v", err)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package database_test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -123,7 +122,7 @@ func Example_blockStorageAndRetrieval() {
|
||||
// Typically you wouldn't want to remove the database right away like
|
||||
// this, nor put it in the temp directory, but it's done here to ensure
|
||||
// the example cleans up after itself.
|
||||
dbPath, err := ioutil.TempDir("", "exampleblkstorage")
|
||||
dbPath, err := os.MkdirTemp("", "exampleblkstorage")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -1121,7 +1121,7 @@ func main() {
|
||||
// generated by btcd when it starts the RPC server and doesn't already
|
||||
// have one.
|
||||
btcdHomeDir := btcutil.AppDataDir("btcd", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
certs, err := os.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -1185,7 +1185,7 @@ func main() {
|
||||
// generated by btcd when it starts the RPC server and doesn't already
|
||||
// have one.
|
||||
btcdHomeDir := btcutil.AppDataDir("btcd", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
certs, err := os.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -1288,7 +1288,7 @@ func main() {
|
||||
// generated by btcd when it starts the RPC server and doesn't already
|
||||
// have one.
|
||||
btcdHomeDir := btcutil.AppDataDir("btcd", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
certs, err := os.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -33,7 +33,7 @@ func main() {
|
||||
|
||||
// Connect to local btcd RPC server using websockets.
|
||||
btcdHomeDir := btcutil.AppDataDir("btcd", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
certs, err := os.ReadFile(filepath.Join(btcdHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -29,7 +29,7 @@ func main() {
|
||||
|
||||
// Connect to local btcwallet RPC server using websockets.
|
||||
certHomeDir := btcutil.AppDataDir("btcwallet", false)
|
||||
certs, err := ioutil.ReadFile(filepath.Join(certHomeDir, "rpc.cert"))
|
||||
certs, err := os.ReadFile(filepath.Join(certHomeDir, "rpc.cert"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -4650,10 +4650,10 @@ func genCertPair(certFile, keyFile string) error {
|
||||
}
|
||||
|
||||
// Write cert and key files.
|
||||
if err = ioutil.WriteFile(certFile, cert, 0666); err != nil {
|
||||
if err = os.WriteFile(certFile, cert, 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = ioutil.WriteFile(keyFile, key, 0600); err != nil {
|
||||
if err = os.WriteFile(keyFile, key, 0600); err != nil {
|
||||
os.Remove(certFile)
|
||||
return err
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package txscript
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
@ -25,7 +25,7 @@ var (
|
||||
|
||||
func init() {
|
||||
// tx 620f57c92cf05a7f7e7f7d28255d5f7089437bc48e34dcfebf7751d08b7fb8f5
|
||||
txHex, err := ioutil.ReadFile("data/many_inputs_tx.hex")
|
||||
txHex, err := os.ReadFile("data/many_inputs_tx.hex")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("unable to read benchmark tx file: %v", err))
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -490,7 +490,7 @@ func testScripts(t *testing.T, tests [][]interface{}, useSigCache bool) {
|
||||
// TestScripts ensures all of the tests in script_tests.json execute with the
|
||||
// expected results as defined in the test data.
|
||||
func TestScripts(t *testing.T) {
|
||||
file, err := ioutil.ReadFile("data/script_tests.json")
|
||||
file, err := os.ReadFile("data/script_tests.json")
|
||||
if err != nil {
|
||||
t.Fatalf("TestScripts: %v\n", err)
|
||||
}
|
||||
@ -521,7 +521,7 @@ func testVecF64ToUint32(f float64) uint32 {
|
||||
// TestTxInvalidTests ensures all of the tests in tx_invalid.json fail as
|
||||
// expected.
|
||||
func TestTxInvalidTests(t *testing.T) {
|
||||
file, err := ioutil.ReadFile("data/tx_invalid.json")
|
||||
file, err := os.ReadFile("data/tx_invalid.json")
|
||||
if err != nil {
|
||||
t.Fatalf("TestTxInvalidTests: %v\n", err)
|
||||
}
|
||||
@ -679,7 +679,7 @@ testloop:
|
||||
|
||||
// TestTxValidTests ensures all of the tests in tx_valid.json pass as expected.
|
||||
func TestTxValidTests(t *testing.T) {
|
||||
file, err := ioutil.ReadFile("data/tx_valid.json")
|
||||
file, err := os.ReadFile("data/tx_valid.json")
|
||||
if err != nil {
|
||||
t.Fatalf("TestTxValidTests: %v\n", err)
|
||||
}
|
||||
@ -836,7 +836,7 @@ testloop:
|
||||
// in sighash.json.
|
||||
// https://github.com/bitcoin/bitcoin/blob/master/src/test/data/sighash.json
|
||||
func TestCalcSignatureHash(t *testing.T) {
|
||||
file, err := ioutil.ReadFile("data/sighash.json")
|
||||
file, err := os.ReadFile("data/sighash.json")
|
||||
if err != nil {
|
||||
t.Fatalf("TestCalcSignatureHash: %v\n", err)
|
||||
}
|
||||
@ -1044,7 +1044,7 @@ func TestTaprootReferenceTests(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
testJson, err := ioutil.ReadFile(path)
|
||||
testJson, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read file: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user