close file

This commit is contained in:
Frank 2020-07-23 18:21:13 +08:00
parent 78f7a96300
commit c38b8b1265
9 changed files with 23 additions and 2 deletions

View File

@ -18,6 +18,7 @@ func LoadVector(t *testing.T, f string, out interface{}) {
if err != nil {
t.Fatal(err)
}
defer fi.Close()
if err := json.NewDecoder(fi).Decode(out); err != nil {
t.Fatal(err)

View File

@ -466,6 +466,7 @@ var importAnalyzeCmd = &cli.Command{
if err != nil {
return err
}
defer fi.Close() //nolint:errcheck
const nWorkers = 16
jsonIn := make(chan []byte, 2*nWorkers)

View File

@ -240,6 +240,7 @@ func parseMultisigCsv(csvf string) ([]GenAccountEntry, error) {
if err != nil {
return nil, xerrors.Errorf("read multisig csv: %w", err)
}
defer fileReader.Close() //nolint:errcheck
r := csv.NewReader(fileReader)
records, err := r.ReadAll()
if err != nil {

View File

@ -155,6 +155,9 @@ var aggregateManifestsCmd = &cli.Command{
}
inputs = append(inputs, val)
if err := fi.Close(); err != nil {
return err
}
}
output := make(map[string]genesis.Miner)

View File

@ -65,11 +65,17 @@ var importCarCmd = &cli.Command{
fmt.Println()
return ds.Close()
default:
if err := f.Close(); err != nil {
return err
}
fmt.Println()
return err
case nil:
fmt.Printf("\r%s", blk.Cid())
if err := bs.Put(blk); err != nil {
if err := f.Close(); err != nil {
return err
}
return xerrors.Errorf("put %s: %w", blk.Cid(), err)
}
}

View File

@ -1,6 +1,7 @@
package main
import (
"bufio"
"encoding/base64"
"encoding/hex"
"encoding/json"
@ -64,10 +65,12 @@ var keyinfoImportCmd = &cli.Command{
input = os.Stdin
} else {
var err error
input, err = os.Open(cctx.Args().First())
inputFile, err := os.Open(cctx.Args().First())
if err != nil {
return err
}
defer inputFile.Close()
input = bufio.NewReader(inputFile)
}
encoded, err := ioutil.ReadAll(input)
@ -174,10 +177,12 @@ var keyinfoInfoCmd = &cli.Command{
input = os.Stdin
} else {
var err error
input, err = os.Open(cctx.Args().First())
inputFile, err := os.Open(cctx.Args().First())
if err != nil {
return err
}
defer inputFile.Close()
input = bufio.NewReader(inputFile)
}
encoded, err := ioutil.ReadAll(input)

View File

@ -317,6 +317,7 @@ func ImportChain(r repo.Repo, fname string) error {
if err != nil {
return err
}
defer fi.Close() //nolint:errcheck
lr, err := r.Lock(repo.FullNode)
if err != nil {

View File

@ -494,6 +494,7 @@ func (a *API) ClientCalcCommP(ctx context.Context, inpath string, miner address.
if err != nil {
return nil, err
}
defer rdr.Close()
stat, err := rdr.Stat()
if err != nil {
@ -554,6 +555,7 @@ func (a *API) clientImport(ctx context.Context, ref api.FileRef, store *importmg
if err != nil {
return cid.Undef, err
}
defer f.Close()
stat, err := f.Stat()
if err != nil {

View File

@ -390,6 +390,7 @@ func (fsr *fsLockedRepo) List() ([]string, error) {
if err != nil {
return nil, xerrors.Errorf("opening dir to list keystore: %w", err)
}
defer dir.Close() //nolint:errcheck
files, err := dir.Readdir(-1)
if err != nil {
return nil, xerrors.Errorf("reading keystore dir: %w", err)