Skip to content

Commit

Permalink
change ioutil.ReadFile -> os.ReadFile
Browse files Browse the repository at this point in the history
Signed-off-by: Фёдор Партанский <pfi79@mail.ru>
  • Loading branch information
pfi79 authored and C0rWin committed Aug 18, 2023
1 parent 4ca66d4 commit 79468d8
Show file tree
Hide file tree
Showing 82 changed files with 237 additions and 259 deletions.
5 changes: 2 additions & 3 deletions ccaas_builder/cmd/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -74,7 +73,7 @@ func run() error {
return errors.WithMessagef(err, "%s not found ", metadataFile)
}

metadataFileContents, cause := ioutil.ReadFile(metadataFile)
metadataFileContents, cause := os.ReadFile(metadataFile)
if cause != nil {
return errors.WithMessagef(cause, "%s file not readable", metadataFile)
}
Expand Down Expand Up @@ -104,7 +103,7 @@ func run() error {
return errors.WithMessagef(err, "%s not found ", connectionSrcFile)
}

connectionFileContents, err := ioutil.ReadFile(connectionSrcFile)
connectionFileContents, err := os.ReadFile(connectionSrcFile)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions ccaas_builder/cmd/build/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package main

import (
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -169,7 +168,7 @@ func TestTemplating(t *testing.T) {
gt.Expect(err).NotTo(HaveOccurred())

// check that the file has the exepected contents
connectionFileContents, err := ioutil.ReadFile(chkfile)
connectionFileContents, err := os.ReadFile(chkfile)
gt.Expect(err).NotTo(HaveOccurred())

expectedJson := `{
Expand Down
3 changes: 1 addition & 2 deletions ccaas_builder/cmd/detect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -53,7 +52,7 @@ func run() error {
return errors.WithMessagef(err, "%s not found ", metadataFile)
}

mdbytes, cause := ioutil.ReadFile(metadataFile)
mdbytes, cause := os.ReadFile(metadataFile)
if cause != nil {
err := errors.WithMessagef(cause, "%s not readable", metadataFile)
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/common/comm/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package comm

import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestClientBadConfig(t *testing.T) {
}

func loadFileOrDie(path string) []byte {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
fmt.Println("Failed opening file", path, ":", err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/common/comm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package comm

import (
"io/ioutil"
"os"
"time"

"github.com/hyperledger/fabric/common/crypto/tlsgen"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (conf Config) ToSecureOptions(newSelfSignedTLSCert genTLSCertFunc) (comm.Se
}

func loadFile(path string) ([]byte, error) {
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return nil, errors.Errorf("Failed opening file %s: %v", path, err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/configtxgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -133,7 +132,7 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou

func doInspectBlock(inspectBlock string) error {
logger.Info("Inspecting block")
data, err := ioutil.ReadFile(inspectBlock)
data, err := os.ReadFile(inspectBlock)
if err != nil {
return fmt.Errorf("could not read block %s", inspectBlock)
}
Expand All @@ -152,7 +151,7 @@ func doInspectBlock(inspectBlock string) error {

func doInspectChannelCreateTx(inspectChannelCreateTx string) error {
logger.Info("Inspecting transaction")
data, err := ioutil.ReadFile(inspectChannelCreateTx)
data, err := os.ReadFile(inspectChannelCreateTx)
if err != nil {
return fmt.Errorf("could not read channel create tx: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/osnadmin/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -75,7 +74,7 @@ var _ = Describe("osnadmin", func() {
Expect(err).NotTo(HaveOccurred())

caCertPool := x509.NewCertPool()
clientCAPem, err := ioutil.ReadFile(filepath.Join(tempDir, "client-ca.pem"))
clientCAPem, err := os.ReadFile(filepath.Join(tempDir, "client-ca.pem"))
Expect(err).NotTo(HaveOccurred())
caCertPool.AppendCertsFromPEM(clientCAPem)

Expand Down
6 changes: 3 additions & 3 deletions common/channelconfig/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package channelconfig
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestValidateCapabilities(t *testing.T) {
func TestExtractMSPIDsForApplicationOrgs(t *testing.T) {
// load test_configblock.json that contains the application group
// and other properties needed to build channel config and extract MSPIDs
blockData, err := ioutil.ReadFile("testdata/test_configblock.json")
blockData, err := os.ReadFile("testdata/test_configblock.json")
require.NoError(t, err)
block := &cb.Block{}
protolator.DeepUnmarshalJSON(bytes.NewBuffer(blockData), block)
Expand Down Expand Up @@ -348,7 +348,7 @@ func TestMarshalEtcdRaftMetadata(t *testing.T) {
var outputCerts, inputCerts [3][]byte
for i := range unpacked.GetConsenters() {
outputCerts[i] = unpacked.GetConsenters()[i].GetClientTlsCert()
inputCerts[i], _ = ioutil.ReadFile(fmt.Sprintf("testdata/tls-client-%d.pem", i+1))
inputCerts[i], _ = os.ReadFile(fmt.Sprintf("testdata/tls-client-%d.pem", i+1))
}

for i := 0; i < len(inputCerts)-1; i++ {
Expand Down
6 changes: 3 additions & 3 deletions common/crypto/expiration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -25,7 +25,7 @@ import (
)

func TestX509CertExpiresAt(t *testing.T) {
certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "cert.pem"))
certBytes, err := os.ReadFile(filepath.Join("testdata", "cert.pem"))
require.NoError(t, err)
sId := &msp.SerializedIdentity{
IdBytes: certBytes,
Expand All @@ -37,7 +37,7 @@ func TestX509CertExpiresAt(t *testing.T) {
}

func TestX509InvalidCertExpiresAt(t *testing.T) {
certBytes, err := ioutil.ReadFile(filepath.Join("testdata", "badCert.pem"))
certBytes, err := os.ReadFile(filepath.Join("testdata", "badCert.pem"))
require.NoError(t, err)
sId := &msp.SerializedIdentity{
IdBytes: certBytes,
Expand Down
3 changes: 1 addition & 2 deletions common/fabhttp/fabhttp_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package fabhttp_test
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,7 +50,7 @@ func generateCertificates(tempDir string) {

func newHTTPClient(tlsDir string, withClientCert bool, tlsOpts ...func(config *tls.Config)) *http.Client {
clientCertPool := x509.NewCertPool()
caCert, err := ioutil.ReadFile(filepath.Join(tlsDir, "server-ca.pem"))
caCert, err := os.ReadFile(filepath.Join(tlsDir, "server-ca.pem"))
Expect(err).NotTo(HaveOccurred())
clientCertPool.AppendCertsFromPEM(caCert)

Expand Down
4 changes: 2 additions & 2 deletions common/fabhttp/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package fabhttp
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"

"github.com/hyperledger/fabric/internal/pkg/comm"
)
Expand All @@ -32,7 +32,7 @@ func (t TLS) Config() (*tls.Config, error) {
}
caCertPool := x509.NewCertPool()
for _, caPath := range t.ClientCACertFiles {
caPem, err := ioutil.ReadFile(caPath)
caPem, err := os.ReadFile(caPath)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion common/fabhttp/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("TLS", func() {
)
Expect(err).NotTo(HaveOccurred())

pemBytes, err := ioutil.ReadFile(filepath.Join(tempDir, "client-ca.pem"))
pemBytes, err := os.ReadFile(filepath.Join(tempDir, "client-ca.pem"))
Expect(err).NotTo(HaveOccurred())

clientCAPool := x509.NewCertPool()
Expand Down
3 changes: 1 addition & 2 deletions common/ledger/blkstorage/blockfile_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package blkstorage

import (
"fmt"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -479,7 +478,7 @@ func testBlockfileMgrSimulateCrashAtFirstBlockInFile(t *testing.T, deleteBlkfile

// verify that the block file number 1 has been created with partial bytes as a side-effect of crash
lastFilePath := blockfileMgr.currentFileWriter.filePath
lastFileContent, err := ioutil.ReadFile(lastFilePath)
lastFileContent, err := os.ReadFile(lastFilePath)
require.NoError(t, err)
require.Equal(t, lastFileContent, partialBytesForNextBlock)

Expand Down
6 changes: 3 additions & 3 deletions common/ledger/blkstorage/blockindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func TestExportUniqueTxIDs(t *testing.T) {
require.NoError(t, err)
fileHashes, err = blkfileMgr.index.exportUniqueTxIDs(testSnapshotDir, testNewHashFunc)
require.NoError(t, err)
verifyExportedTxIDs(t, testSnapshotDir, fileHashes, "txid-1", "txid-2", "txid-3", configTxID) //"txid-1" appears once, Txids appear in radix sort order
verifyExportedTxIDs(t, testSnapshotDir, fileHashes, "txid-1", "txid-2", "txid-3", configTxID) // "txid-1" appears once, Txids appear in radix sort order
os.Remove(filepath.Join(testSnapshotDir, snapshotDataFileName))
os.Remove(filepath.Join(testSnapshotDir, snapshotMetadataFileName))

Expand Down Expand Up @@ -399,13 +399,13 @@ func verifyExportedTxIDs(t *testing.T, dir string, fileHashes map[string][]byte,
require.Contains(t, fileHashes, snapshotMetadataFileName)

dataFile := filepath.Join(dir, snapshotDataFileName)
dataFileContent, err := ioutil.ReadFile(dataFile)
dataFileContent, err := os.ReadFile(dataFile)
require.NoError(t, err)
dataFileHash := sha256.Sum256(dataFileContent)
require.Equal(t, dataFileHash[:], fileHashes[snapshotDataFileName])

metadataFile := filepath.Join(dir, snapshotMetadataFileName)
metadataFileContent, err := ioutil.ReadFile(metadataFile)
metadataFileContent, err := os.ReadFile(metadataFile)
require.NoError(t, err)
metadataFileHash := sha256.Sum256(metadataFileContent)
require.Equal(t, metadataFileHash[:], fileHashes[snapshotMetadataFileName])
Expand Down
2 changes: 1 addition & 1 deletion common/ledger/blkstorage/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func assertBlockStorePostReset(t *testing.T, store *BlockStore, originallyCommit
}

func assertRecordedHeight(t *testing.T, ledgerDir, expectedRecordedHt string) {
bytes, err := ioutil.ReadFile(path.Join(ledgerDir, fileNamePreRestHt))
bytes, err := os.ReadFile(path.Join(ledgerDir, fileNamePreRestHt))
require.NoError(t, err)
require.Equal(t, expectedRecordedHt, string(bytes))
}
Expand Down
3 changes: 1 addition & 2 deletions common/ledger/snapshot/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/sha256"
"errors"
"hash"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -214,7 +213,7 @@ func TestFileReaderErrorPropagation(t *testing.T) {
}

func computeSha256(t *testing.T, file string) []byte {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
require.NoError(t, err)
sha := sha256.Sum256(data)
return sha[:]
Expand Down
5 changes: 2 additions & 3 deletions common/viperutil/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/pem"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -286,7 +285,7 @@ func stringFromFileDecodeHook(f reflect.Kind, t reflect.Kind, data interface{})
}
switch {
case ok && fileName != nil:
bytes, err := ioutil.ReadFile(fileName.(string))
bytes, err := os.ReadFile(fileName.(string))
if err != nil {
return data, err
}
Expand Down Expand Up @@ -333,7 +332,7 @@ func pemBlocksFromFileDecodeHook(f reflect.Kind, t reflect.Kind, data interface{
switch {
case ok && fileName != "":
var result []string
bytes, err := ioutil.ReadFile(fileName)
bytes, err := os.ReadFile(fileName)
if err != nil {
return data, err
}
Expand Down
Loading

0 comments on commit 79468d8

Please sign in to comment.