From 1f293eff1b3da26a0c1e4c7d1c45adb88f536dd8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 27 Mar 2019 14:46:29 +0000 Subject: [PATCH 1/3] chore: fix a bunch of issues caught by golangci-lint Most of these are probably harmless but a few looked like they might actually be bugs. Most of them are just faulty tests. License: MIT Signed-off-by: Steven Allen --- cmd/ipfs/daemon.go | 4 +- cmd/ipfs/main.go | 8 ++- cmd/ipfswatch/main.go | 10 ++- cmd/seccat/seccat.go | 10 ++- commands/reqlog.go | 2 - core/builder.go | 4 +- core/commands/add.go | 8 ++- core/commands/cid.go | 9 +-- core/commands/commands.go | 22 +----- core/commands/config.go | 14 ++-- core/commands/files.go | 3 + core/commands/get.go | 2 +- core/commands/p2p.go | 5 +- core/commands/repo.go | 12 ++-- core/commands/swarm.go | 6 +- core/core.go | 10 ++- core/coreapi/pubsub.go | 12 ++-- core/coreapi/swarm.go | 9 +-- core/corehttp/gateway_test.go | 8 +-- core/corehttp/mutex_profile.go | 4 +- core/corehttp/option_test.go | 4 +- core/corerepo/gc.go | 8 ++- core/coreunix/add_test.go | 11 +-- core/coreunix/metadata_test.go | 6 +- dagutils/diff.go | 4 +- dagutils/utils.go | 2 +- exchange/reprovide/reprovide_test.go | 7 +- fuse/ipns/ipns_test.go | 74 +++++++++++---------- fuse/mount/fuse.go | 2 +- fuse/node/mount_unix.go | 10 +-- fuse/readonly/ipfs_test.go | 6 +- keystore/keystore_test.go | 2 +- namesys/namesys.go | 2 +- namesys/namesys_test.go | 5 +- namesys/republisher/repub_test.go | 4 +- namesys/routing.go | 2 +- p2p/remote.go | 6 +- p2p/stream.go | 20 +++--- pin/pin_test.go | 20 ++++-- plugin/loader/loader.go | 2 +- provider/queue.go | 8 +-- provider/queue_test.go | 3 + test/bench/bench_cli_ipfs_add/main.go | 11 ++- test/bench/offline_add/main.go | 5 +- test/dependencies/ma-pipe-unidir/main.go | 7 +- test/integration/addcat_test.go | 17 +++-- test/integration/bench_cat_test.go | 9 ++- test/integration/bitswap_wo_routing_test.go | 5 +- test/integration/three_legged_cat_test.go | 15 +++-- 49 files changed, 244 insertions(+), 195 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index dfc55e5e6..aa8818722 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -530,7 +530,7 @@ func printSwarmAddrs(node *core.IpfsNode) { for _, addr := range ifaceAddrs { lisAddrs = append(lisAddrs, addr.String()) } - sort.Sort(sort.StringSlice(lisAddrs)) + sort.Strings(lisAddrs) for _, addr := range lisAddrs { fmt.Printf("Swarm listening on %s\n", addr) } @@ -539,7 +539,7 @@ func printSwarmAddrs(node *core.IpfsNode) { for _, addr := range node.PeerHost.Addrs() { addrs = append(addrs, addr.String()) } - sort.Sort(sort.StringSlice(addrs)) + sort.Strings(addrs) for _, addr := range addrs { fmt.Printf("Swarm announcing %s\n", addr) } diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index bd0ecf216..e8f89b4eb 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -37,8 +37,6 @@ import ( // log is the command logger var log = logging.Logger("cmd/ipfs") -var errRequestCanceled = errors.New("request canceled") - // declared as a var for testing purposes var dnsResolver = madns.DefaultResolver @@ -325,7 +323,11 @@ func startProfiling() (func(), error) { if err != nil { return nil, err } - pprof.StartCPUProfile(ofi) + err = pprof.StartCPUProfile(ofi) + if err != nil { + ofi.Close() + return nil, err + } go func() { for range time.NewTicker(time.Second * 30).C { err := writeHeapProfileToFile() diff --git a/cmd/ipfswatch/main.go b/cmd/ipfswatch/main.go index 771499529..732077858 100644 --- a/cmd/ipfswatch/main.go +++ b/cmd/ipfswatch/main.go @@ -103,7 +103,7 @@ func run(ipfsPath, watchPath string) error { }) } - interrupts := make(chan os.Signal) + interrupts := make(chan os.Signal, 1) signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM) for { @@ -129,7 +129,9 @@ func run(ipfsPath, watchPath string) error { switch e.Op { case fsnotify.Create: if isDir { - addTree(watcher, e.Name) + if err := addTree(watcher, e.Name); err != nil { + return err + } } } proc.Go(func(p process.Process) { @@ -167,6 +169,10 @@ func run(ipfsPath, watchPath string) error { func addTree(w *fsnotify.Watcher, root string) error { err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + if err != nil { + log.Println(err) + return nil + } isDir, err := IsDirectory(path) if err != nil { log.Println(err) diff --git a/cmd/seccat/seccat.go b/cmd/seccat/seccat.go index bbe6a58cd..5a5ae49a2 100644 --- a/cmd/seccat/seccat.go +++ b/cmd/seccat/seccat.go @@ -129,8 +129,14 @@ func setupPeer(a args) (peer.ID, pstore.Peerstore, error) { } ps := pstoremem.NewPeerstore() - ps.AddPrivKey(p, sk) - ps.AddPubKey(p, pk) + err = ps.AddPrivKey(p, sk) + if err != nil { + return "", nil, err + } + err = ps.AddPubKey(p, pk) + if err != nil { + return "", nil, err + } out("local peer id: %s", p) return p, ps, nil diff --git a/commands/reqlog.go b/commands/reqlog.go index bae1ef13c..55488ab3e 100644 --- a/commands/reqlog.go +++ b/commands/reqlog.go @@ -44,8 +44,6 @@ func (rl *ReqLog) AddEntry(rle *ReqLogEntry) { if rle == nil || !rle.Active { rl.maybeCleanup() } - - return } // ClearInactive removes stale entries diff --git a/core/builder.go b/core/builder.go index 13dce637d..1fdec9944 100644 --- a/core/builder.go +++ b/core/builder.go @@ -78,10 +78,10 @@ func (cfg *BuildCfg) fillDefaults() error { if cfg.Repo == nil { var d ds.Datastore - d = ds.NewMapDatastore() - if cfg.NilRepo { d = ds.NewNullDatastore() + } else { + d = ds.NewMapDatastore() } r, err := defaultRepo(dsync.MutexWrap(d)) if err != nil { diff --git a/core/commands/add.go b/core/commands/add.go index bdf24a6e1..e6e78c1da 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -230,7 +230,7 @@ You can now check what blocks have been created by: opts = append(opts, options.Unixfs.Layout(options.TrickleLayout)) } - errCh := make(chan error) + errCh := make(chan error, 1) go func() { var err error defer func() { errCh <- err }() @@ -255,12 +255,14 @@ You can now check what blocks have been created by: output.Name = path.Join(name, output.Name) } - res.Emit(&AddEvent{ + if err := res.Emit(&AddEvent{ Name: output.Name, Hash: h, Bytes: output.Bytes, Size: output.Size, - }) + }); err != nil { + return err + } } return <-errCh diff --git a/core/commands/cid.go b/core/commands/cid.go index 932de3134..d24873f6b 100644 --- a/core/commands/cid.go +++ b/core/commands/cid.go @@ -239,8 +239,7 @@ var basesCmd = &cmds.Command{ for code, name := range mbase.EncodingToStr { res = append(res, CodeAndName{int(code), name}) } - cmds.EmitOnce(resp, res) - return nil + return cmds.EmitOnce(resp, res) }, Encoders: cmds.EncoderMap{ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error { @@ -287,8 +286,7 @@ var codecsCmd = &cmds.Command{ for code, name := range cid.CodecToStr { res = append(res, CodeAndName{int(code), name}) } - cmds.EmitOnce(resp, res) - return nil + return cmds.EmitOnce(resp, res) }, Encoders: cmds.EncoderMap{ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, val []CodeAndName) error { @@ -321,8 +319,7 @@ var hashesCmd = &cmds.Command{ } res = append(res, CodeAndName{int(code), name}) } - cmds.EmitOnce(resp, res) - return nil + return cmds.EmitOnce(resp, res) }, Encoders: codecsCmd.Encoders, Type: codecsCmd.Type, diff --git a/core/commands/commands.go b/core/commands/commands.go index aed53a301..3c5a58da9 100644 --- a/core/commands/commands.go +++ b/core/commands/commands.go @@ -12,8 +12,6 @@ import ( "sort" "strings" - e "github.com/ipfs/go-ipfs/core/commands/e" - "github.com/ipfs/go-ipfs-cmdkit" cmds "github.com/ipfs/go-ipfs-cmds" ) @@ -129,28 +127,10 @@ func cmdPathStrings(cmd *Command, showOptions bool) []string { } recurse("", cmd) - sort.Sort(sort.StringSlice(cmds)) + sort.Strings(cmds) return cmds } -// changes here will also need to be applied at -// - ./dag/dag.go -// - ./object/object.go -// - ./files/files.go -// - ./unixfs/unixfs.go -func unwrapOutput(i interface{}) (interface{}, error) { - var ( - ch <-chan interface{} - ok bool - ) - - if ch, ok = i.(<-chan interface{}); !ok { - return nil, e.TypeErr(ch, i) - } - - return <-ch, nil -} - type nonFatalError string // streamResult is a helper function to stream results that possibly diff --git a/core/commands/config.go b/core/commands/config.go index 709931ecb..8c7869e91 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -134,8 +134,8 @@ Set the value of the 'Datastore.Path' key: } buf = append(buf, byte('\n')) - w.Write(buf) - return nil + _, err = w.Write(buf) + return err }), }, Type: ConfigField{}, @@ -185,9 +185,8 @@ NOTE: For security reasons, this command will omit your private key. If you woul return err } buf = append(buf, byte('\n')) - w.Write(buf) - - return nil + _, err = w.Write(buf) + return err }), }, } @@ -352,9 +351,8 @@ var configProfileApplyCmd = &cmds.Command{ diff := jsondiff.Compare(out.OldCfg, out.NewCfg) buf := jsondiff.Format(diff) - w.Write(buf) - - return nil + _, err := w.Write(buf) + return err }), }, Type: ConfigUpdateOutput{}, diff --git a/core/commands/files.go b/core/commands/files.go index fc931d373..928434d72 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -168,6 +168,9 @@ var filesStatCmd = &cmds.Command{ } local, sizeLocal, err := walkBlock(req.Context, dagserv, nd) + if err != nil { + return err + } o.WithLocality = true o.Local = local diff --git a/core/commands/get.go b/core/commands/get.go index 54521583e..b73aa5cbd 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -274,7 +274,7 @@ func fileArchive(f files.Node, name string, archive bool, compression int) (io.R piper, pipew := io.Pipe() checkErrAndClosePipe := func(err error) bool { if err != nil { - pipew.CloseWithError(err) + _ = pipew.CloseWithError(err) return true } return false diff --git a/core/commands/p2p.go b/core/commands/p2p.go index f6edd71af..7c2160688 100644 --- a/core/commands/p2p.go +++ b/core/commands/p2p.go @@ -149,8 +149,11 @@ func parseIpfsAddr(addr string) ([]ipfsaddr.IPFSAddr, error) { } // resolve mutiladdr whose protocol is not ma.P_IPFS ctx, cancel := context.WithTimeout(context.Background(), resolveTimeout) + defer cancel() addrs, err := madns.Resolve(ctx, mutiladdr) - cancel() + if err != nil { + return nil, err + } if len(addrs) == 0 { return nil, errors.New("fail to resolve the multiaddr:" + mutiladdr.String()) } diff --git a/core/commands/repo.go b/core/commands/repo.go index 0416c996b..f7b431603 100644 --- a/core/commands/repo.go +++ b/core/commands/repo.go @@ -98,7 +98,10 @@ order to reclaim hard disk space. } } else { err := corerepo.CollectResult(req.Context, gcOutChan, func(k cid.Cid) { - re.Emit(&GcResult{Key: k}) + // Nothing to do with this error, really. This + // most likely means that the client is gone but + // we still need to let the GC finish. + _ = re.Emit(&GcResult{Key: k}) }) if err != nil { return err @@ -163,10 +166,9 @@ Version string The repo version. if err != nil { return err } - cmds.EmitOnce(res, &corerepo.Stat{ + return cmds.EmitOnce(res, &corerepo.Stat{ SizeStat: sizeStat, }) - return nil } stat, err := corerepo.RepoStat(req.Context, n) @@ -396,9 +398,9 @@ var repoVersionCmd = &cmds.Command{ quiet, _ := req.Options[repoQuietOptionName].(bool) if quiet { - fmt.Fprintf(w, fmt.Sprintf("fs-repo@%s\n", out.Version)) + fmt.Fprintf(w, "fs-repo@%s\n", out.Version) } else { - fmt.Fprintf(w, fmt.Sprintf("ipfs repo version fs-repo@%s\n", out.Version)) + fmt.Fprintf(w, "ipfs repo version fs-repo@%s\n", out.Version) } return nil }), diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 204fb9d14..68edd8003 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -256,7 +256,7 @@ var swarmAddrsCmd = &cmds.Command{ for p := range am.Addrs { ids = append(ids, p) } - sort.Sort(sort.StringSlice(ids)) + sort.Strings(ids) for _, p := range ids { paddrs := am.Addrs[p] @@ -307,7 +307,7 @@ var swarmAddrsLocalCmd = &cmds.Command{ } addrs = append(addrs, saddr) } - sort.Sort(sort.StringSlice(addrs)) + sort.Strings(addrs) return cmds.EmitOnce(res, &stringList{addrs}) }, Type: stringList{}, @@ -338,7 +338,7 @@ var swarmAddrsListenCmd = &cmds.Command{ for _, addr := range maddrs { addrs = append(addrs, addr.String()) } - sort.Sort(sort.StringSlice(addrs)) + sort.Strings(addrs) return cmds.EmitOnce(res, &stringList{addrs}) }, diff --git a/core/core.go b/core/core.go index 0d41b7378..7f653e228 100644 --- a/core/core.go +++ b/core/core.go @@ -399,7 +399,7 @@ func makeAddrsFactory(cfg config.Addresses) (p2pbhost.AddrsFactory, error) { var out []ma.Multiaddr for _, maddr := range addrs { // check for exact matches - ok, _ := noAnnAddrs[maddr.String()] + ok := noAnnAddrs[maddr.String()] // check for /ipcidr matches if !ok && !filters.AddrBlocked(maddr) { out = append(out, maddr) @@ -815,8 +815,12 @@ func (n *IpfsNode) loadPrivateKey() error { } n.PrivateKey = sk - n.Peerstore.AddPrivKey(n.Identity, n.PrivateKey) - n.Peerstore.AddPubKey(n.Identity, sk.GetPublic()) + if err := n.Peerstore.AddPrivKey(n.Identity, n.PrivateKey); err != nil { + return err + } + if err := n.Peerstore.AddPubKey(n.Identity, sk.GetPublic()); err != nil { + return err + } return nil } diff --git a/core/coreapi/pubsub.go b/core/coreapi/pubsub.go index f5a2a54fb..987d9d6c8 100644 --- a/core/coreapi/pubsub.go +++ b/core/coreapi/pubsub.go @@ -48,14 +48,7 @@ func (api *PubSubAPI) Peers(ctx context.Context, opts ...caopts.PubSubPeersOptio return nil, err } - peers := api.pubSub.ListPeers(settings.Topic) - out := make([]peer.ID, len(peers)) - - for i, peer := range peers { - out[i] = peer - } - - return out, nil + return api.pubSub.ListPeers(settings.Topic), nil } func (api *PubSubAPI) Publish(ctx context.Context, topic string, data []byte) error { @@ -69,6 +62,9 @@ func (api *PubSubAPI) Publish(ctx context.Context, topic string, data []byte) er func (api *PubSubAPI) Subscribe(ctx context.Context, topic string, opts ...caopts.PubSubSubscribeOption) (coreiface.PubSubSubscription, error) { options, err := caopts.PubSubSubscribeOptions(opts...) + if err != nil { + return nil, err + } r, err := api.checkNode() if err != nil { diff --git a/core/coreapi/swarm.go b/core/coreapi/swarm.go index e99266a7c..56057130d 100644 --- a/core/coreapi/swarm.go +++ b/core/coreapi/swarm.go @@ -23,9 +23,8 @@ type connInfo struct { conn net.Conn dir net.Direction - addr ma.Multiaddr - peer peer.ID - muxer string + addr ma.Multiaddr + peer peer.ID } func (api *SwarmAPI) Connect(ctx context.Context, pi pstore.PeerInfo) error { @@ -83,9 +82,7 @@ func (api *SwarmAPI) KnownAddrs(context.Context) (map[peer.ID][]ma.Multiaddr, er addrs := make(map[peer.ID][]ma.Multiaddr) ps := api.peerHost.Network().Peerstore() for _, p := range ps.Peers() { - for _, a := range ps.Addrs(p) { - addrs[p] = append(addrs[p], a) - } + addrs[p] = append(addrs[p], ps.Addrs(p)...) sort.Slice(addrs[p], func(i, j int) bool { return addrs[p][i].String() < addrs[p][j].String() }) diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index b44f9ef4f..72193cf52 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -43,7 +43,7 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re depth = ^uint(0) } for strings.HasPrefix(name, "/ipns/") { - if depth <= 0 { + if depth == 0 { return value, namesys.ErrResolveRecursion } depth-- @@ -235,9 +235,6 @@ func TestGatewayGet(t *testing.T) { } func TestIPNSHostnameRedirect(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ns := mockNamesys{} ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) @@ -326,9 +323,6 @@ func TestIPNSHostnameRedirect(t *testing.T) { } func TestIPNSHostnameBacklinks(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - ns := mockNamesys{} ts, api, ctx := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) diff --git a/core/corehttp/mutex_profile.go b/core/corehttp/mutex_profile.go index db39a7bc9..f8d66e5ef 100644 --- a/core/corehttp/mutex_profile.go +++ b/core/corehttp/mutex_profile.go @@ -20,7 +20,7 @@ func MutexFractionOption(path string) ServeOption { } if err := r.ParseForm(); err != nil { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } @@ -33,7 +33,7 @@ func MutexFractionOption(path string) ServeOption { fr, err := strconv.Atoi(asfr) if err != nil { w.WriteHeader(http.StatusBadRequest) - w.Write([]byte(err.Error())) + _, _ = w.Write([]byte(err.Error())) return } log.Infof("Setting MutexProfileFraction to %d", fr) diff --git a/core/corehttp/option_test.go b/core/corehttp/option_test.go index 22157618c..17fcefe09 100644 --- a/core/corehttp/option_test.go +++ b/core/corehttp/option_test.go @@ -52,7 +52,9 @@ func TestCheckVersionOption(t *testing.T) { if !tc.shouldHandle { t.Error("handler was called even though version didn't match") } else { - io.WriteString(w, "check!") + if _, err := io.WriteString(w, "check!"); err != nil { + t.Error(err) + } } }) diff --git a/core/corerepo/gc.go b/core/corerepo/gc.go index 68ce20d54..3a75efab6 100644 --- a/core/corerepo/gc.go +++ b/core/corerepo/gc.go @@ -40,11 +40,15 @@ func NewGC(n *core.IpfsNode) (*GC, error) { // TODO: there should be a general check for all of the cfg fields // maybe distinguish between user config file and default struct? if cfg.Datastore.StorageMax == "" { - r.SetConfigKey("Datastore.StorageMax", "10GB") + if err := r.SetConfigKey("Datastore.StorageMax", "10GB"); err != nil { + return nil, err + } cfg.Datastore.StorageMax = "10GB" } if cfg.Datastore.StorageGCWatermark == 0 { - r.SetConfigKey("Datastore.StorageGCWatermark", 90) + if err := r.SetConfigKey("Datastore.StorageGCWatermark", 90); err != nil { + return nil, err + } cfg.Datastore.StorageGCWatermark = 90 } diff --git a/core/coreunix/add_test.go b/core/coreunix/add_test.go index 69b2d367c..95f244cff 100644 --- a/core/coreunix/add_test.go +++ b/core/coreunix/add_test.go @@ -72,7 +72,7 @@ func TestAddGCLive(t *testing.T) { _, err := adder.AddAllAndPin(slf) if err != nil { - t.Fatal(err) + t.Error(err) } }() @@ -93,7 +93,9 @@ func TestAddGCLive(t *testing.T) { }() // gc shouldnt start until we let the add finish its current file. - pipew.Write([]byte("some data for file b")) + if _, err := pipew.Write([]byte("some data for file b")); err != nil { + t.Fatal(err) + } select { case <-gcstarted: @@ -178,7 +180,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) { defer close(adder.Out) _, err = adder.AddAllAndPin(file) if err != nil { - t.Fatal(err) + t.Error(err) } }() for range out { @@ -227,7 +229,7 @@ func (bs *testBlockstore) PutMany(blocks []blocks.Block) error { return bs.GCBlockstore.PutMany(blocks) } -func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) error { +func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) { fsn, ok := block.(*pi.FilestoreNode) if ok { posInfo := fsn.PosInfo @@ -240,7 +242,6 @@ func (bs *testBlockstore) CheckForPosInfo(block blocks.Block) error { bs.countAtOffsetNonZero += 1 } } - return nil } type dummyFileInfo struct { diff --git a/core/coreunix/metadata_test.go b/core/coreunix/metadata_test.go index ca735332b..42d7d348c 100644 --- a/core/coreunix/metadata_test.go +++ b/core/coreunix/metadata_test.go @@ -3,6 +3,7 @@ package coreunix import ( "bytes" "context" + "io" "io/ioutil" "testing" @@ -35,7 +36,10 @@ func TestMetadata(t *testing.T) { // Make some random node ds := getDagserv(t) data := make([]byte, 1000) - u.NewTimeSeededRand().Read(data) + _, err := io.ReadFull(u.NewTimeSeededRand(), data) + if err != nil { + t.Fatal(err) + } r := bytes.NewReader(data) nd, err := importer.BuildDagFromReader(ds, chunker.DefaultSplitter(r)) if err != nil { diff --git a/dagutils/diff.go b/dagutils/diff.go index 05493269a..a43756ffd 100644 --- a/dagutils/diff.go +++ b/dagutils/diff.go @@ -139,8 +139,8 @@ func Diff(ctx context.Context, ds ipld.DAGService, a, b ipld.Node) ([]*Change, e out = append(out, subc) } } - cleanA.RemoveNodeLink(l.Name) - cleanB.RemoveNodeLink(l.Name) + _ = cleanA.RemoveNodeLink(l.Name) + _ = cleanB.RemoveNodeLink(l.Name) } } diff --git a/dagutils/utils.go b/dagutils/utils.go index 848b84d19..3a796a9c5 100644 --- a/dagutils/utils.go +++ b/dagutils/utils.go @@ -183,7 +183,7 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string) return nil, err } - e.tmp.Remove(ctx, root.Cid()) + _ = e.tmp.Remove(ctx, root.Cid()) _ = root.RemoveNodeLink(path[0]) err = root.AddNodeLink(path[0], nnode) diff --git a/exchange/reprovide/reprovide_test.go b/exchange/reprovide/reprovide_test.go index 62817bb83..ce1d123c1 100644 --- a/exchange/reprovide/reprovide_test.go +++ b/exchange/reprovide/reprovide_test.go @@ -30,11 +30,14 @@ func TestReprovide(t *testing.T) { bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) blk := blocks.NewBlock([]byte("this is a test")) - bstore.Put(blk) + err := bstore.Put(blk) + if err != nil { + t.Fatal(err) + } keyProvider := NewBlockstoreProvider(bstore) reprov := NewReprovider(ctx, clA, keyProvider) - err := reprov.Reprovide() + err = reprov.Reprovide() if err != nil { t.Fatal(err) } diff --git a/fuse/ipns/ipns_test.go b/fuse/ipns/ipns_test.go index e7d4aa7d8..e2ff88da4 100644 --- a/fuse/ipns/ipns_test.go +++ b/fuse/ipns/ipns_test.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "fmt" + "io" "io/ioutil" mrand "math/rand" "os" @@ -30,7 +31,10 @@ func maybeSkipFuseTests(t *testing.T) { func randBytes(size int) []byte { b := make([]byte, size) - u.NewTimeSeededRand().Read(b) + _, err := io.ReadFull(u.NewTimeSeededRand(), b) + if err != nil { + panic(err) + } return b } @@ -41,31 +45,18 @@ func mkdir(t *testing.T, path string) { } } -func writeFile(t *testing.T, size int, path string) []byte { - return writeFileData(t, randBytes(size), path) +func writeFileOrFail(t *testing.T, size int, path string) []byte { + data, err := writeFile(size, path) + if err != nil { + t.Fatal(err) + } + return data } -func writeFileData(t *testing.T, data []byte, path string) []byte { - fi, err := os.Create(path) - if err != nil { - t.Fatal(err) - } - - n, err := fi.Write(data) - if err != nil { - t.Fatal(err) - } - - if n != len(data) { - t.Fatal("Didnt write proper amount!") - } - - err = fi.Close() - if err != nil { - t.Fatal(err) - } - - return data +func writeFile(size int, path string) ([]byte, error) { + data := randBytes(size) + err := ioutil.WriteFile(path, data, 0666) + return data, err } func verifyFile(t *testing.T, path string, wantData []byte) { @@ -168,7 +159,7 @@ func TestIpnsBasicIO(t *testing.T) { defer closeMount(mnt) fname := mnt.Dir + "/local/testfile" - data := writeFile(t, 10, fname) + data := writeFileOrFail(t, 10, fname) rbuf, err := ioutil.ReadFile(fname) if err != nil { @@ -198,7 +189,7 @@ func TestFilePersistence(t *testing.T) { node, mnt := setupIpnsTest(t, nil) fname := "/local/atestfile" - data := writeFile(t, 127, mnt.Dir+fname) + data := writeFileOrFail(t, 127, mnt.Dir+fname) mnt.Close() @@ -226,7 +217,7 @@ func TestMultipleDirs(t *testing.T) { checkExists(t, mnt.Dir+dir1) t.Log("write a file in it") - data1 := writeFile(t, 4000, mnt.Dir+dir1+"/file1") + data1 := writeFileOrFail(t, 4000, mnt.Dir+dir1+"/file1") verifyFile(t, mnt.Dir+dir1+"/file1", data1) @@ -236,7 +227,7 @@ func TestMultipleDirs(t *testing.T) { checkExists(t, mnt.Dir+dir1+"/dir2") t.Log("file in that subdirectory") - data2 := writeFile(t, 5000, mnt.Dir+dir1+"/dir2/file2") + data2 := writeFileOrFail(t, 5000, mnt.Dir+dir1+"/dir2/file2") verifyFile(t, mnt.Dir+dir1+"/dir2/file2", data2) @@ -262,7 +253,7 @@ func TestFileSizeReporting(t *testing.T) { defer mnt.Close() fname := mnt.Dir + "/local/sizecheck" - data := writeFile(t, 5555, fname) + data := writeFileOrFail(t, 5555, fname) finfo, err := os.Stat(fname) if err != nil { @@ -302,7 +293,7 @@ func TestAppendFile(t *testing.T) { defer mnt.Close() fname := mnt.Dir + "/local/file" - data := writeFile(t, 1300, fname) + data := writeFileOrFail(t, 1300, fname) fi, err := os.OpenFile(fname, os.O_RDWR|os.O_APPEND, 0666) if err != nil { @@ -360,7 +351,11 @@ func TestConcurrentWrites(t *testing.T) { go func(n int) { defer wg.Done() for j := 0; j < filesPerActor; j++ { - out := writeFile(t, fileSize, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", n, j)) + out, err := writeFile(fileSize, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", n, j)) + if err != nil { + t.Error(err) + continue + } data[n][j] = out } }(i) @@ -369,6 +364,10 @@ func TestConcurrentWrites(t *testing.T) { for i := 0; i < nactors; i++ { for j := 0; j < filesPerActor; j++ { + if data[i][j] == nil { + // Error already reported. + continue + } verifyFile(t, mnt.Dir+fmt.Sprintf("/local/%dFILE%d", i, j), data[i][j]) } } @@ -410,7 +409,8 @@ func TestFSThrash(t *testing.T) { newDir := fmt.Sprintf("%s/dir%d-%d", dir, worker, j) err := os.Mkdir(newDir, os.ModeDir) if err != nil { - t.Fatal(err) + t.Error(err) + continue } dirlock.Lock() dirs = append(dirs, newDir) @@ -432,7 +432,11 @@ func TestFSThrash(t *testing.T) { newFileName := fmt.Sprintf("%s/file%d-%d", dir, worker, j) - data := writeFile(t, 2000+mrand.Intn(5000), newFileName) + data, err := writeFile(2000+mrand.Intn(5000), newFileName) + if err != nil { + t.Error(err) + continue + } filelock.Lock() files[newFileName] = data filelock.Unlock() @@ -444,11 +448,11 @@ func TestFSThrash(t *testing.T) { for name, data := range files { out, err := ioutil.ReadFile(name) if err != nil { - t.Fatal(err) + t.Error(err) } if !bytes.Equal(data, out) { - t.Fatal("Data didnt match") + t.Errorf("Data didnt match in %s: expected %v, got %v", name, data, out) } } } diff --git a/fuse/mount/fuse.go b/fuse/mount/fuse.go index 889318be2..41d14cc36 100644 --- a/fuse/mount/fuse.go +++ b/fuse/mount/fuse.go @@ -56,7 +56,7 @@ func NewMount(p goprocess.Process, fsys fs.FS, mountpoint string, allow_other bo // launch the mounting process. if err := m.mount(); err != nil { - m.Unmount() // just in case. + _ = m.Unmount() // just in case. return nil, err } diff --git a/fuse/node/mount_unix.go b/fuse/node/mount_unix.go index eb96efed5..8fee86947 100644 --- a/fuse/node/mount_unix.go +++ b/fuse/node/mount_unix.go @@ -35,10 +35,12 @@ func Mount(node *core.IpfsNode, fsdir, nsdir string) error { // if the user said "Mount", then there must be something wrong. // so, close them and try again. if node.Mounts.Ipfs != nil && node.Mounts.Ipfs.IsActive() { - node.Mounts.Ipfs.Unmount() + // best effort + _ = node.Mounts.Ipfs.Unmount() } if node.Mounts.Ipns != nil && node.Mounts.Ipns.IsActive() { - node.Mounts.Ipns.Unmount() + // best effort + _ = node.Mounts.Ipns.Unmount() } if err := platformFuseChecks(node); err != nil { @@ -95,10 +97,10 @@ func doMount(node *core.IpfsNode, fsdir, nsdir string) error { if err1 != nil || err2 != nil { if fsmount != nil { - fsmount.Unmount() + _ = fsmount.Unmount() } if nsmount != nil { - nsmount.Unmount() + _ = nsmount.Unmount() } if err1 != nil { diff --git a/fuse/readonly/ipfs_test.go b/fuse/readonly/ipfs_test.go index 94e3ad19c..1383c169e 100644 --- a/fuse/readonly/ipfs_test.go +++ b/fuse/readonly/ipfs_test.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "io" "io/ioutil" "math/rand" "os" @@ -41,7 +42,10 @@ func maybeSkipFuseTests(t *testing.T) { func randObj(t *testing.T, nd *core.IpfsNode, size int64) (ipld.Node, []byte) { buf := make([]byte, size) - u.NewTimeSeededRand().Read(buf) + _, err := io.ReadFull(u.NewTimeSeededRand(), buf) + if err != nil { + t.Fatal(err) + } read := bytes.NewReader(buf) obj, err := importer.BuildTrickleDagFromReader(nd.DAG, chunker.DefaultSplitter(read)) if err != nil { diff --git a/keystore/keystore_test.go b/keystore/keystore_test.go index c69fd6a05..d7118d756 100644 --- a/keystore/keystore_test.go +++ b/keystore/keystore_test.go @@ -198,7 +198,7 @@ func TestInvalidKeyFiles(t *testing.T) { t.Fatal(err) } - if exist, err = ks.Has(".invalid"); err == nil { + if _, err = ks.Has(".invalid"); err == nil { t.Fatal("shouldnt be able to put a key with a 'hidden' name") } } diff --git a/namesys/namesys.go b/namesys/namesys.go index 94d498992..f8b8c6d12 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -183,7 +183,7 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path. return err } ttl := DefaultResolverCacheTTL - if ttEol := eol.Sub(time.Now()); ttEol < ttl { + if ttEol := time.Until(eol); ttEol < ttl { ttl = ttEol } ns.cacheSet(peer.IDB58Encode(id), value, ttl) diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index 09c5a39c2..38d6c4abb 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -104,5 +104,8 @@ func TestPublishWithCache0(t *testing.T) { if err != nil { t.Fatal(err) } - nsys.Publish(context.Background(), priv, p) + err = nsys.Publish(context.Background(), priv, p) + if err != nil { + t.Fatal(err) + } } diff --git a/namesys/republisher/repub_test.go b/namesys/republisher/repub_test.go index 22d69e254..8f0048c4c 100644 --- a/namesys/republisher/repub_test.go +++ b/namesys/republisher/repub_test.go @@ -41,7 +41,9 @@ func TestRepublish(t *testing.T) { nodes = append(nodes, nd) } - mn.LinkAll() + if err := mn.LinkAll(); err != nil { + t.Fatal(err) + } bsinf := core.BootstrapConfigWithPeers( []pstore.PeerInfo{ diff --git a/namesys/routing.go b/namesys/routing.go index d58133775..e89dd9c9d 100644 --- a/namesys/routing.go +++ b/namesys/routing.go @@ -137,7 +137,7 @@ func (r *IpnsResolver) resolveOnceAsync(ctx context.Context, name string, option case ipns.ErrUnrecognizedValidity: // No EOL. case nil: - ttEol := eol.Sub(time.Now()) + ttEol := time.Until(eol) if ttEol < 0 { // It *was* valid when we first resolved it. ttl = 0 diff --git a/p2p/remote.go b/p2p/remote.go index 83dfd99c3..f6b956829 100644 --- a/p2p/remote.go +++ b/p2p/remote.go @@ -48,7 +48,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto protocol.ID, addr ma.Mu func (l *remoteListener) handleStream(remote net.Stream) { local, err := manet.Dial(l.addr) if err != nil { - remote.Reset() + _ = remote.Reset() return } @@ -56,14 +56,14 @@ func (l *remoteListener) handleStream(remote net.Stream) { if l.reportRemote { if _, err := fmt.Fprintf(local, "%s\n", peer.Pretty()); err != nil { - remote.Reset() + _ = remote.Reset() return } } peerMa, err := ma.NewMultiaddr(maPrefix + peer.Pretty()) if err != nil { - remote.Reset() + _ = remote.Reset() return } diff --git a/p2p/stream.go b/p2p/stream.go index aa4c39c17..e29c965b0 100644 --- a/p2p/stream.go +++ b/p2p/stream.go @@ -31,15 +31,13 @@ type Stream struct { } // close stream endpoints and deregister it -func (s *Stream) close() error { +func (s *Stream) close() { s.Registry.Close(s) - return nil } // reset closes stream endpoints and deregisters it -func (s *Stream) reset() error { +func (s *Stream) reset() { s.Registry.Reset(s) - return nil } func (s *Stream) startStreaming() { @@ -108,17 +106,15 @@ func (r *StreamRegistry) Deregister(streamID uint64) { } // Close stream endpoints and deregister it -func (r *StreamRegistry) Close(s *Stream) error { - s.Local.Close() - s.Remote.Close() +func (r *StreamRegistry) Close(s *Stream) { + _ = s.Local.Close() + _ = s.Remote.Close() s.Registry.Deregister(s.id) - return nil } // Reset closes stream endpoints and deregisters it -func (r *StreamRegistry) Reset(s *Stream) error { - s.Local.Close() - s.Remote.Reset() +func (r *StreamRegistry) Reset(s *Stream) { + _ = s.Local.Close() + _ = s.Remote.Reset() s.Registry.Deregister(s.id) - return nil } diff --git a/pin/pin_test.go b/pin/pin_test.go index 6f9914ef3..27e4c71de 100644 --- a/pin/pin_test.go +++ b/pin/pin_test.go @@ -2,6 +2,7 @@ package pin import ( "context" + "io" "testing" "time" @@ -21,7 +22,10 @@ var rand = util.NewTimeSeededRand() func randNode() (*mdag.ProtoNode, cid.Cid) { nd := new(mdag.ProtoNode) nd.SetData(make([]byte, 32)) - rand.Read(nd.Data()) + _, err := io.ReadFull(rand, nd.Data()) + if err != nil { + panic(err) + } k := nd.Cid() return nd, k } @@ -111,11 +115,11 @@ func TestPinnerBasic(t *testing.T) { assertPinned(t, p, bk, "Recursively pinned node not found..") d, _ := randNode() - d.AddNodeLink("a", a) - d.AddNodeLink("c", c) + _ = d.AddNodeLink("a", a) + _ = d.AddNodeLink("c", c) e, _ := randNode() - d.AddNodeLink("e", e) + _ = d.AddNodeLink("e", e) // Must be in dagserv for unpin to work err = dserv.Add(ctx, e) @@ -385,8 +389,12 @@ func TestPinUpdate(t *testing.T) { n1, c1 := randNode() n2, c2 := randNode() - dserv.Add(ctx, n1) - dserv.Add(ctx, n2) + if err := dserv.Add(ctx, n1); err != nil { + t.Fatal(err) + } + if err := dserv.Add(ctx, n2); err != nil { + t.Fatal(err) + } if err := p.Pin(ctx, n1, true); err != nil { t.Fatal(err) diff --git a/plugin/loader/loader.go b/plugin/loader/loader.go index 939edb9ad..b5a2d08ed 100644 --- a/plugin/loader/loader.go +++ b/plugin/loader/loader.go @@ -115,7 +115,7 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error { if pl, ok := pl.(plugin.PluginDaemon); ok { err := pl.Start(iface) if err != nil { - closePlugins(loader.plugins[i:]) + _ = closePlugins(loader.plugins[i:]) return err } } diff --git a/provider/queue.go b/provider/queue.go index 918bdcbd7..c8982ff10 100644 --- a/provider/queue.go +++ b/provider/queue.go @@ -62,11 +62,6 @@ func (q *Queue) Dequeue() <-chan cid.Cid { return q.dequeue } -type entry struct { - cid cid.Cid - key datastore.Key -} - // Look for next Cid in the queue and return it. Skip over gaps and mangled data func (q *Queue) nextEntry() (datastore.Key, cid.Cid) { for { @@ -91,6 +86,9 @@ func (q *Queue) nextEntry() (datastore.Key, cid.Cid) { log.Warningf("Error marshalling Cid from queue: ", err) q.head++ err = q.ds.Delete(key) + if err != nil { + log.Warningf("Provider queue failed to delete: %s", key) + } continue } diff --git a/provider/queue_test.go b/provider/queue_test.go index 2857da0a9..e151478d9 100644 --- a/provider/queue_test.go +++ b/provider/queue_test.go @@ -99,6 +99,9 @@ func TestMangledData(t *testing.T) { // remove entries in the middle err = queue.ds.Put(queue.queueKey(5), []byte("borked")) + if err != nil { + t.Fatal(err) + } expected := append(cids[:5], cids[6:]...) assertOrdered(expected, queue, t) diff --git a/test/bench/bench_cli_ipfs_add/main.go b/test/bench/bench_cli_ipfs_add/main.go index a05e3907d..dbd092891 100644 --- a/test/bench/bench_cli_ipfs_add/main.go +++ b/test/bench/bench_cli_ipfs_add/main.go @@ -80,7 +80,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) { } defer os.Remove(f.Name()) - random.WritePseudoRandomBytes(amount, f, seed) + if err := random.WritePseudoRandomBytes(amount, f, seed); err != nil { + benchmarkError = err + b.Fatal(err) + } if err := f.Close(); err != nil { benchmarkError = err b.Fatal(err) @@ -95,8 +98,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) { benchmarkError = err b.Fatal(err) } - defer daemonCmd.Wait() - defer daemonCmd.Process.Signal(os.Interrupt) + defer func() { + _ = daemonCmd.Process.Signal(os.Interrupt) + _ = daemonCmd.Wait() + }() } b.StartTimer() diff --git a/test/bench/offline_add/main.go b/test/bench/offline_add/main.go index 1f3c3786d..745976863 100644 --- a/test/bench/offline_add/main.go +++ b/test/bench/offline_add/main.go @@ -62,7 +62,10 @@ func benchmarkAdd(amount int64) (*testing.BenchmarkResult, error) { } defer os.Remove(f.Name()) - random.WritePseudoRandomBytes(amount, f, seed) + err = random.WritePseudoRandomBytes(amount, f, seed) + if err != nil { + b.Fatal(err) + } if err := f.Close(); err != nil { b.Fatal(err) } diff --git a/test/dependencies/ma-pipe-unidir/main.go b/test/dependencies/ma-pipe-unidir/main.go index e677491d4..03617e618 100644 --- a/test/dependencies/ma-pipe-unidir/main.go +++ b/test/dependencies/ma-pipe-unidir/main.go @@ -81,12 +81,15 @@ func app() int { defer conn.Close() switch mode { case "recv": - io.Copy(os.Stdout, conn) + _, err = io.Copy(os.Stdout, conn) case "send": - io.Copy(conn, os.Stdin) + _, err = io.Copy(conn, os.Stdin) default: return 1 } + if err != nil { + return 1 + } return 0 } diff --git a/test/integration/addcat_test.go b/test/integration/addcat_test.go index 173c20e91..b0def746d 100644 --- a/test/integration/addcat_test.go +++ b/test/integration/addcat_test.go @@ -84,8 +84,11 @@ func AddCatPowers(conf testutil.LatencyConfig, megabytesMax int64) error { } func RandomBytes(n int64) []byte { - data := new(bytes.Buffer) - random.WritePseudoRandomBytes(n, data, kSeed) + var data bytes.Buffer + err := random.WritePseudoRandomBytes(n, &data, kSeed) + if err != nil { + panic(err) + } return data.Bytes() } @@ -155,13 +158,15 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error { } // verify - bufout := new(bytes.Buffer) - io.Copy(bufout, readerCatted.(io.Reader)) - if 0 != bytes.Compare(bufout.Bytes(), data) { + var bufout bytes.Buffer + _, err = io.Copy(&bufout, readerCatted.(io.Reader)) + if err != nil { + return err + } + if !bytes.Equal(bufout.Bytes(), data) { return errors.New("catted data does not match added data") } - cancel() return nil } diff --git a/test/integration/bench_cat_test.go b/test/integration/bench_cat_test.go index 19c7c127a..e8a2322de 100644 --- a/test/integration/bench_cat_test.go +++ b/test/integration/bench_cat_test.go @@ -102,9 +102,12 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error { } // verify - bufout := new(bytes.Buffer) - io.Copy(bufout, readerCatted.(io.Reader)) - if 0 != bytes.Compare(bufout.Bytes(), data) { + var bufout bytes.Buffer + _, err = io.Copy(&bufout, readerCatted.(io.Reader)) + if err != nil { + return err + } + if !bytes.Equal(bufout.Bytes(), data) { return errors.New("catted data does not match added data") } return nil diff --git a/test/integration/bitswap_wo_routing_test.go b/test/integration/bitswap_wo_routing_test.go index 62f9ce98c..af4406633 100644 --- a/test/integration/bitswap_wo_routing_test.go +++ b/test/integration/bitswap_wo_routing_test.go @@ -35,7 +35,10 @@ func TestBitswapWithoutRouting(t *testing.T) { nodes = append(nodes, n) } - mn.LinkAll() + err := mn.LinkAll() + if err != nil { + t.Fatal(err) + } // connect them for _, n1 := range nodes { diff --git a/test/integration/three_legged_cat_test.go b/test/integration/three_legged_cat_test.go index 239fa3673..953c7e370 100644 --- a/test/integration/three_legged_cat_test.go +++ b/test/integration/three_legged_cat_test.go @@ -112,7 +112,10 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error { return err } - mn.LinkAll() + err = mn.LinkAll() + if err != nil { + return err + } bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID()) bcfg := core.BootstrapConfigWithPeers([]pstore.PeerInfo{bis}) @@ -134,11 +137,13 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error { } // verify - bufout := new(bytes.Buffer) - io.Copy(bufout, readerCatted.(io.Reader)) - if 0 != bytes.Compare(bufout.Bytes(), data) { + var bufout bytes.Buffer + _, err = io.Copy(&bufout, readerCatted.(io.Reader)) + if err != nil { + return err + } + if !bytes.Equal(bufout.Bytes(), data) { return errors.New("catted data does not match added data") } - cancel() return nil } From 9a9310df107107b4e0dfaa6283e4b1d0cdc0d8f2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 27 Mar 2019 15:26:31 +0000 Subject: [PATCH 2/3] test: fix namesys test License: MIT Signed-off-by: Steven Allen --- namesys/namesys_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index 38d6c4abb..2cf316cf3 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -15,6 +15,7 @@ import ( ci "github.com/libp2p/go-libp2p-crypto" peer "github.com/libp2p/go-libp2p-peer" pstoremem "github.com/libp2p/go-libp2p-peerstore/pstoremem" + record "github.com/libp2p/go-libp2p-record" ) type mockResolver struct { @@ -97,7 +98,10 @@ func TestPublishWithCache0(t *testing.T) { t.Fatal(err) } - routing := offroute.NewOfflineRouter(dst, ipns.Validator{KeyBook: ps}) + routing := offroute.NewOfflineRouter(dst, record.NamespacedValidator{ + "ipns": ipns.Validator{KeyBook: ps}, + "pk": record.PublicKeyValidator{}, + }) nsys := NewNameSystem(routing, dst, 0) p, err := path.ParsePath(unixfs.EmptyDirNode().Cid().String()) From 5ee455b5b13d1795eecb45c777680c36ca78571c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 28 Mar 2019 01:54:29 +0000 Subject: [PATCH 3/3] chore: make code climate happy 1. Yes, I like my symmetry. 2. No, we don't want to stash the private key if we fail to put it in the peerstore. License: MIT Signed-off-by: Steven Allen --- core/core.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/core.go b/core/core.go index 7f653e228..1a87c0123 100644 --- a/core/core.go +++ b/core/core.go @@ -814,13 +814,13 @@ func (n *IpfsNode) loadPrivateKey() error { return err } - n.PrivateKey = sk - if err := n.Peerstore.AddPrivKey(n.Identity, n.PrivateKey); err != nil { + if err := n.Peerstore.AddPrivKey(n.Identity, sk); err != nil { return err } if err := n.Peerstore.AddPubKey(n.Identity, sk.GetPublic()); err != nil { return err } + n.PrivateKey = sk return nil }