From 4f4dac956444d464a41e7325fca307ab89eb6bdf Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 20 Aug 2025 02:07:42 +0200 Subject: [PATCH] chore: fix all golangci-lint staticcheck issues align kubo with unified golang ci linter from IPDX and rules used in boxo and other go packages addressed lint rules: - ST1000: added package comments - ST1020, ST1021, ST1022: fixed function/method comments - QF1001: applied De Morgan's law - QF1003: converted if-else chains to tagged switches - QF1004: replaced strings.Replace with strings.ReplaceAll - QF1008: simplified embedded struct field selectors - unconvert: removed unnecessary type conversions - usestdlibvars: used stdlib constants instead of literals disabled errcheck linter in .golangci.yml --- .golangci.yml | 4 ++ assets/assets.go | 1 + client/rpc/api.go | 1 + client/rpc/api_test.go | 2 +- client/rpc/auth/auth.go | 1 + client/rpc/response.go | 2 +- cmd/ipfs/kubo/daemon.go | 5 ++- cmd/ipfs/kubo/start.go | 2 +- cmd/ipfs/util/signal.go | 1 + commands/context.go | 1 + config/config.go | 6 +-- config/routing.go | 6 +-- config/serialize/serialize.go | 1 + core/commands/cat.go | 2 +- core/commands/cid.go | 2 +- core/commands/cmdenv/env.go | 1 + core/commands/cmdutils/utils.go | 1 + core/commands/dag/dag.go | 1 + core/commands/e/error.go | 1 + core/commands/files.go | 30 +++++++------- core/commands/id.go | 14 +++---- core/commands/keyencode/keyencode.go | 1 + core/commands/name/ipns.go | 3 +- core/commands/object/object.go | 1 + core/commands/p2p.go | 2 +- core/commands/pin/pin.go | 13 +++--- core/commands/pin/remotepin.go | 4 +- core/commands/refs.go | 8 ++-- core/commands/routing.go | 2 +- core/coreapi/coreapi.go | 18 ++++---- core/coreapi/routing.go | 4 +- core/coreapi/swarm.go | 2 +- core/coreapi/test/path_test.go | 1 + core/coreapi/unixfs.go | 4 +- core/corehttp/commands.go | 2 +- core/corehttp/metrics.go | 2 +- core/corehttp/webui.go | 2 +- core/coreiface/options/block.go | 1 + core/coreiface/tests/api.go | 1 + core/coreiface/tests/block.go | 8 ++-- core/coreiface/tests/pin.go | 2 +- core/coreiface/tests/unixfs.go | 1 + core/corerepo/gc.go | 1 + core/coreunix/add.go | 3 +- core/mock/mock.go | 1 + core/node/bitswap.go | 2 +- core/node/groups.go | 1 + core/node/helpers/helpers.go | 1 + core/node/libp2p/discovery.go | 1 + core/node/libp2p/fd/sys_unix.go | 1 + core/node/libp2p/rcmgr_defaults.go | 2 +- doc.go | 4 +- fuse/ipns/ipns_unix.go | 20 ++++----- fuse/mfs/mfs_unix.go | 41 ++++++++++--------- fuse/mount/fuse.go | 2 +- fuse/mount/mount.go | 2 +- fuse/node/mount_unix.go | 5 ++- fuse/readonly/doc.go | 2 +- fuse/readonly/readonly_unix.go | 28 ++++++------- misc/fsutil/fsutil.go | 1 + p2p/listener.go | 1 + p2p/stream.go | 4 +- plugin/daemon.go | 1 + plugin/loader/loader.go | 1 + plugin/plugins/badgerds/badgerds.go | 1 + plugin/plugins/dagjose/dagjose.go | 1 + plugin/plugins/flatfs/flatfs.go | 1 + plugin/plugins/fxtest/fxtest.go | 1 + plugin/plugins/git/git.go | 1 + plugin/plugins/levelds/levelds.go | 1 + plugin/plugins/nopfs/nopfs.go | 1 + plugin/plugins/pebbleds/pebbleds.go | 1 + plugin/plugins/peerlog/peerlog.go | 1 + plugin/plugins/telemetry/telemetry.go | 3 +- plugin/plugins/telemetry/telemetry_test.go | 2 +- profile/profile.go | 1 + repo/common/common.go | 1 + repo/fsrepo/doc.go | 2 +- repo/fsrepo/migrations/fetch.go | 1 + .../migrations/ipfsfetcher/ipfsfetcher.go | 1 + repo/repo.go | 1 + routing/composer.go | 1 + routing/delegated_test.go | 4 +- test/cli/add_test.go | 1 + .../delegated_routing_v1_http_client_test.go | 4 +- test/cli/dht_autoclient_test.go | 2 +- test/cli/harness/harness.go | 2 + test/cli/harness/pbinspect.go | 2 +- test/cli/http_retrieval_client_test.go | 2 +- test/cli/must.go | 1 + test/cli/testutils/asserts.go | 1 + test/cli/testutils/files.go | 2 +- .../httprouting/mock_http_content_router.go | 1 + test/cli/testutils/pinningservice/pinning.go | 1 + test/cli/testutils/random_deterministic.go | 2 +- thirdparty/unit/unit.go | 1 + thirdparty/verifbs/verifbs.go | 1 + 97 files changed, 199 insertions(+), 142 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3611130c8..5b2fbf25e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -3,6 +3,10 @@ linters: default: standard enable: - staticcheck + - unconvert + - usestdlibvars + disable: + - errcheck settings: staticcheck: checks: diff --git a/assets/assets.go b/assets/assets.go index 6196ed22f..fdea06864 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -1,3 +1,4 @@ +// Package assets provides embedded asset files for kubo. package assets import ( diff --git a/client/rpc/api.go b/client/rpc/api.go index c4b73d387..1ccd99902 100644 --- a/client/rpc/api.go +++ b/client/rpc/api.go @@ -1,3 +1,4 @@ +// Package rpc provides an RPC client implementation for the kubo HTTP API. package rpc import ( diff --git a/client/rpc/api_test.go b/client/rpc/api_test.go index 745f0fe13..5307d4965 100644 --- a/client/rpc/api_test.go +++ b/client/rpc/api_test.go @@ -111,7 +111,7 @@ func Test_NewURLApiWithClient_With_Headers(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { val := r.Header.Get(headerToTest) if val != expectedHeaderValue { - w.WriteHeader(400) + w.WriteHeader(http.StatusBadRequest) return } http.ServeContent(w, r, "", time.Now(), strings.NewReader("test")) diff --git a/client/rpc/auth/auth.go b/client/rpc/auth/auth.go index a6ed273cd..f67553481 100644 --- a/client/rpc/auth/auth.go +++ b/client/rpc/auth/auth.go @@ -1,3 +1,4 @@ +// Package auth provides HTTP authentication utilities for the RPC client. package auth import "net/http" diff --git a/client/rpc/response.go b/client/rpc/response.go index c47da4a68..3c731c4cb 100644 --- a/client/rpc/response.go +++ b/client/rpc/response.go @@ -80,7 +80,7 @@ func (r *Response) decode(dec interface{}) error { func (r *Request) Send(c *http.Client) (*Response, error) { url := r.getURL() - req, err := http.NewRequest("POST", url, r.Body) + req, err := http.NewRequest(http.MethodPost, url, r.Body) if err != nil { return nil, err } diff --git a/cmd/ipfs/kubo/daemon.go b/cmd/ipfs/kubo/daemon.go index eb8b23a97..98d94d23b 100644 --- a/cmd/ipfs/kubo/daemon.go +++ b/cmd/ipfs/kubo/daemon.go @@ -323,9 +323,10 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment } defer fetcher.Close() - if migrationCfg.Keep == "cache" { + switch migrationCfg.Keep { + case "cache": cacheMigrations = true - } else if migrationCfg.Keep == "pin" { + case "pin": pinMigrations = true } diff --git a/cmd/ipfs/kubo/start.go b/cmd/ipfs/kubo/start.go index 4a8709cc6..b16f51c56 100644 --- a/cmd/ipfs/kubo/start.go +++ b/cmd/ipfs/kubo/start.go @@ -1,4 +1,4 @@ -// cmd/ipfs/kubo implements the primary CLI binary for kubo +// Package kubo implements the primary CLI binary for kubo package kubo import ( diff --git a/cmd/ipfs/util/signal.go b/cmd/ipfs/util/signal.go index 2cfd0d5bd..7737d91f8 100644 --- a/cmd/ipfs/util/signal.go +++ b/cmd/ipfs/util/signal.go @@ -1,6 +1,7 @@ //go:build !wasm // +build !wasm +// Package util provides utility functions for the IPFS CLI. package util import ( diff --git a/commands/context.go b/commands/context.go index ca425acbf..36ad61053 100644 --- a/commands/context.go +++ b/commands/context.go @@ -1,3 +1,4 @@ +// Package commands implements IPFS commands. package commands import ( diff --git a/config/config.go b/config/config.go index eee7e768b..3da578e63 100644 --- a/config/config.go +++ b/config/config.go @@ -1,4 +1,4 @@ -// package config implements the ipfs config file datastructures and utilities. +// Package config implements the ipfs config file datastructures and utilities. package config import ( @@ -141,7 +141,7 @@ func ToMap(conf *Config) (map[string]interface{}, error) { return m, nil } -// Convert config to a map, without using encoding/json, since +// ReflectToMap converts config to a map, without using encoding/json, since // zero/empty/'omitempty' fields are excluded by encoding/json during // marshaling. func ReflectToMap(conf interface{}) interface{} { @@ -222,7 +222,7 @@ func (c *Config) Clone() (*Config, error) { return &newConfig, nil } -// Check if the provided key is present in the structure. +// CheckKey checks if the provided key is present in the structure. func CheckKey(key string) error { conf := Config{} diff --git a/config/routing.go b/config/routing.go index aea60c3bd..24d2a91ac 100644 --- a/config/routing.go +++ b/config/routing.go @@ -127,13 +127,13 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error { return err } - r.Router.Type = out.Type - r.Router.Parameters = p + r.Type = out.Type + r.Parameters = p return nil } -// Type is the routing type. +// RouterType is the routing type. // Depending of the type we need to instantiate different Routing implementations. type RouterType string diff --git a/config/serialize/serialize.go b/config/serialize/serialize.go index 7cb479f6b..6de1afd22 100644 --- a/config/serialize/serialize.go +++ b/config/serialize/serialize.go @@ -1,3 +1,4 @@ +// Package fsrepo provides configuration serialization utilities. package fsrepo import ( diff --git a/core/commands/cat.go b/core/commands/cat.go index 38a3e8dfa..2d62edd35 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -60,7 +60,7 @@ var CatCmd = &cmds.Command{ return err } - readers, length, err := cat(req.Context, api, req.Arguments, int64(offset), int64(max)) + readers, length, err := cat(req.Context, api, req.Arguments, offset, max) if err != nil { return err } diff --git a/core/commands/cid.go b/core/commands/cid.go index 0be9f6cc1..9db1db504 100644 --- a/core/commands/cid.go +++ b/core/commands/cid.go @@ -353,7 +353,7 @@ var codecsCmd = &cmds.Command{ continue } } - res = append(res, CodeAndName{int(code), mc.Code(code).String()}) + res = append(res, CodeAndName{int(code), code.String()}) } } return cmds.EmitOnce(resp, res) diff --git a/core/commands/cmdenv/env.go b/core/commands/cmdenv/env.go index 06bccb0ef..bc8a7dd9a 100644 --- a/core/commands/cmdenv/env.go +++ b/core/commands/cmdenv/env.go @@ -1,3 +1,4 @@ +// Package cmdenv provides the environment for executing IPFS commands. package cmdenv import ( diff --git a/core/commands/cmdutils/utils.go b/core/commands/cmdutils/utils.go index be295f9e3..54b2e8e24 100644 --- a/core/commands/cmdutils/utils.go +++ b/core/commands/cmdutils/utils.go @@ -1,3 +1,4 @@ +// Package cmdutils provides utilities for kubo commands. package cmdutils import ( diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index ce5edb641..ba8a13f1d 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -1,3 +1,4 @@ +// Package dagcmd provides IPFS DAG manipulation commands. package dagcmd import ( diff --git a/core/commands/e/error.go b/core/commands/e/error.go index 6bc1bbf63..9992de341 100644 --- a/core/commands/e/error.go +++ b/core/commands/e/error.go @@ -1,3 +1,4 @@ +// Package e provides error utilities for IPFS commands. package e import ( diff --git a/core/commands/files.go b/core/commands/files.go index 12a96eba2..cb5f31bef 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -260,16 +260,16 @@ var filesStatCmd = &cmds.Command{ } s, _ := statGetFormatOptions(req) - s = strings.Replace(s, "", out.Hash, -1) - s = strings.Replace(s, "", fmt.Sprintf("%d", out.Size), -1) - s = strings.Replace(s, "", fmt.Sprintf("%d", out.CumulativeSize), -1) - s = strings.Replace(s, "", fmt.Sprintf("%d", out.Blocks), -1) - s = strings.Replace(s, "", out.Type, -1) - s = strings.Replace(s, "", mode, -1) - s = strings.Replace(s, "", modeo, -1) - s = strings.Replace(s, "", mtime, -1) - s = strings.Replace(s, "", mtimes, -1) - s = strings.Replace(s, "", mtimens, -1) + s = strings.ReplaceAll(s, "", out.Hash) + s = strings.ReplaceAll(s, "", fmt.Sprintf("%d", out.Size)) + s = strings.ReplaceAll(s, "", fmt.Sprintf("%d", out.CumulativeSize)) + s = strings.ReplaceAll(s, "", fmt.Sprintf("%d", out.Blocks)) + s = strings.ReplaceAll(s, "", out.Type) + s = strings.ReplaceAll(s, "", mode) + s = strings.ReplaceAll(s, "", modeo) + s = strings.ReplaceAll(s, "", mtime) + s = strings.ReplaceAll(s, "", mtimes) + s = strings.ReplaceAll(s, "", mtimens) fmt.Fprintln(w, s) @@ -785,11 +785,11 @@ Examples: return err } - if int64(offset) > filen { + if offset > filen { return fmt.Errorf("offset was past end of file (%d > %d)", offset, filen) } - _, err = rfd.Seek(int64(offset), io.SeekStart) + _, err = rfd.Seek(offset, io.SeekStart) if err != nil { return err } @@ -800,7 +800,7 @@ Examples: if count < 0 { return fmt.Errorf("cannot specify negative 'count'") } - r = io.LimitReader(r, int64(count)) + r = io.LimitReader(r, count) } return res.Emit(r) }, @@ -1049,7 +1049,7 @@ See '--to-files' in 'ipfs add --help' for more information. return fmt.Errorf("cannot have negative byte count") } - _, err = wfd.Seek(int64(offset), io.SeekStart) + _, err = wfd.Seek(offset, io.SeekStart) if err != nil { flog.Error("seekfail: ", err) return err @@ -1061,7 +1061,7 @@ See '--to-files' in 'ipfs add --help' for more information. return err } if countfound { - r = io.LimitReader(r, int64(count)) + r = io.LimitReader(r, count) } _, err = io.Copy(wfd, r) diff --git a/core/commands/id.go b/core/commands/id.go index 295223258..e6fc21a07 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -123,13 +123,13 @@ EXAMPLE: format, found := req.Options[formatOptionName].(string) if found { output := format - output = strings.Replace(output, "", out.ID, -1) - output = strings.Replace(output, "", out.AgentVersion, -1) - output = strings.Replace(output, "", out.PublicKey, -1) - output = strings.Replace(output, "", strings.Join(out.Addresses, "\n"), -1) - output = strings.Replace(output, "", strings.Join(protocol.ConvertToStrings(out.Protocols), "\n"), -1) - output = strings.Replace(output, "\\n", "\n", -1) - output = strings.Replace(output, "\\t", "\t", -1) + output = strings.ReplaceAll(output, "", out.ID) + output = strings.ReplaceAll(output, "", out.AgentVersion) + output = strings.ReplaceAll(output, "", out.PublicKey) + output = strings.ReplaceAll(output, "", strings.Join(out.Addresses, "\n")) + output = strings.ReplaceAll(output, "", strings.Join(protocol.ConvertToStrings(out.Protocols), "\n")) + output = strings.ReplaceAll(output, "\\n", "\n") + output = strings.ReplaceAll(output, "\\t", "\t") fmt.Fprint(w, output) } else { marshaled, err := json.MarshalIndent(out, "", "\t") diff --git a/core/commands/keyencode/keyencode.go b/core/commands/keyencode/keyencode.go index c0c85164a..b0d4b0d03 100644 --- a/core/commands/keyencode/keyencode.go +++ b/core/commands/keyencode/keyencode.go @@ -1,3 +1,4 @@ +// Package keyencode provides key encoding utilities for kubo commands. package keyencode import ( diff --git a/core/commands/name/ipns.go b/core/commands/name/ipns.go index e9d5c4426..86415500b 100644 --- a/core/commands/name/ipns.go +++ b/core/commands/name/ipns.go @@ -1,3 +1,4 @@ +// Package name provides IPNS name commands. package name import ( @@ -149,7 +150,7 @@ Resolve the value of a dnslink: if v.Err != nil && (recursive || v.Err != namesys.ErrResolveRecursion) { return v.Err } - if err := res.Emit(&ResolvedPath{v.Path.String()}); err != nil { + if err := res.Emit(&ResolvedPath{v.String()}); err != nil { return err } diff --git a/core/commands/object/object.go b/core/commands/object/object.go index 380ca2533..0d4fb3e00 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -1,3 +1,4 @@ +// Package objectcmd implements IPFS object manipulation commands. package objectcmd import ( diff --git a/core/commands/p2p.go b/core/commands/p2p.go index 1fbdc8a28..956cbebc3 100644 --- a/core/commands/p2p.go +++ b/core/commands/p2p.go @@ -386,7 +386,7 @@ var p2pCloseCmd = &cmds.Command{ } } - if !(closeAll || p || l || t) { + if !closeAll && !p && !l && !t { return errors.New("no matching options given") } diff --git a/core/commands/pin/pin.go b/core/commands/pin/pin.go index 428a75b69..189b985d6 100644 --- a/core/commands/pin/pin.go +++ b/core/commands/pin/pin.go @@ -1,3 +1,4 @@ +// Package pin implements IPFS pinning commands. package pin import ( @@ -387,7 +388,7 @@ Example: lgcList := map[string]PinLsType{} if !stream { emit = func(v PinLsOutputWrapper) error { - lgcList[v.PinLsObject.Cid] = PinLsType{Type: v.PinLsObject.Type, Name: v.PinLsObject.Name} + lgcList[v.Cid] = PinLsType{Type: v.Type, Name: v.Name} return nil } } else { @@ -432,16 +433,16 @@ Example: if stream { if quiet { - fmt.Fprintf(w, "%s\n", out.PinLsObject.Cid) - } else if out.PinLsObject.Name == "" { - fmt.Fprintf(w, "%s %s\n", out.PinLsObject.Cid, out.PinLsObject.Type) + fmt.Fprintf(w, "%s\n", out.Cid) + } else if out.Name == "" { + fmt.Fprintf(w, "%s %s\n", out.Cid, out.Type) } else { - fmt.Fprintf(w, "%s %s %s\n", out.PinLsObject.Cid, out.PinLsObject.Type, out.PinLsObject.Name) + fmt.Fprintf(w, "%s %s %s\n", out.Cid, out.Type, out.Name) } return nil } - for k, v := range out.PinLsList.Keys { + for k, v := range out.Keys { if quiet { fmt.Fprintf(w, "%s\n", k) } else if v.Name == "" { diff --git a/core/commands/pin/remotepin.go b/core/commands/pin/remotepin.go index 068d15d0b..8156eea8a 100644 --- a/core/commands/pin/remotepin.go +++ b/core/commands/pin/remotepin.go @@ -696,7 +696,7 @@ type PinCount struct { Failed int } -// Struct returned by ipfs pin remote service ls --enc=json | jq +// PinServicesList is the struct returned by ipfs pin remote service ls --enc=json | jq type PinServicesList struct { RemoteServices []ServiceDetails } @@ -772,7 +772,7 @@ func getRemotePinServiceInfo(env cmds.Environment, name string) (endpoint, key s func normalizeEndpoint(endpoint string) (string, error) { uri, err := neturl.ParseRequestURI(endpoint) - if err != nil || !(uri.Scheme == "http" || uri.Scheme == "https") { + if err != nil || (uri.Scheme != "http" && uri.Scheme != "https") { return "", fmt.Errorf("service endpoint must be a valid HTTP URL") } diff --git a/core/commands/refs.go b/core/commands/refs.go index 53c92c3df..107b0177c 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -320,7 +320,7 @@ func (rw *RefWriter) visit(c cid.Cid, depth int) (bool, bool) { return !atMaxDepth, !ok } -// Write one edge +// WriteEdge writes one edge func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Encoder) error { if rw.Ctx != nil { select { @@ -334,9 +334,9 @@ func (rw *RefWriter) WriteEdge(from, to cid.Cid, linkname string, enc cidenc.Enc switch { case rw.PrintFmt != "": s = rw.PrintFmt - s = strings.Replace(s, "", enc.Encode(from), -1) - s = strings.Replace(s, "", enc.Encode(to), -1) - s = strings.Replace(s, "", linkname, -1) + s = strings.ReplaceAll(s, "", enc.Encode(from)) + s = strings.ReplaceAll(s, "", enc.Encode(to)) + s = strings.ReplaceAll(s, "", linkname) default: s += enc.Encode(to) } diff --git a/core/commands/routing.go b/core/commands/routing.go index 0804b1f44..ade8a795e 100644 --- a/core/commands/routing.go +++ b/core/commands/routing.go @@ -601,7 +601,7 @@ func escapeDhtKey(s string) (string, error) { parts := strings.Split(s, "/") if len(parts) != 3 || parts[0] != "" || - !(parts[1] == "ipns" || parts[1] == "pk") { + (parts[1] != "ipns" && parts[1] != "pk") { return "", errors.New("invalid key") } diff --git a/core/coreapi/coreapi.go b/core/coreapi/coreapi.go index 66763e884..20fa434df 100644 --- a/core/coreapi/coreapi.go +++ b/core/coreapi/coreapi.go @@ -1,13 +1,11 @@ -/* -**NOTE: this package is experimental.** - -Package coreapi provides direct access to the core commands in IPFS. If you are -embedding IPFS directly in your Go program, this package is the public -interface you should use to read and write files or otherwise control IPFS. - -If you are running IPFS as a separate process, you should use `client/rpc` to -work with it via HTTP. -*/ +// Package coreapi provides direct access to the core commands in IPFS. If you are +// embedding IPFS directly in your Go program, this package is the public +// interface you should use to read and write files or otherwise control IPFS. +// +// **NOTE: this package is experimental.** +// +// If you are running IPFS as a separate process, you should use `client/rpc` to +// work with it via HTTP. package coreapi import ( diff --git a/core/coreapi/routing.go b/core/coreapi/routing.go index 6d432d744..302d7375a 100644 --- a/core/coreapi/routing.go +++ b/core/coreapi/routing.go @@ -60,7 +60,7 @@ func normalizeKey(s string) (string, error) { parts := strings.Split(s, "/") if len(parts) != 3 || parts[0] != "" || - !(parts[1] == "ipns" || parts[1] == "pk") { + (parts[1] != "ipns" && parts[1] != "pk") { return "", errors.New("invalid key") } @@ -79,7 +79,7 @@ func (api *RoutingAPI) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, return peer.AddrInfo{}, err } - pi, err := api.routing.FindPeer(ctx, peer.ID(p)) + pi, err := api.routing.FindPeer(ctx, p) if err != nil { return peer.AddrInfo{}, err } diff --git a/core/coreapi/swarm.go b/core/coreapi/swarm.go index e5332a217..b8dbaa5d9 100644 --- a/core/coreapi/swarm.go +++ b/core/coreapi/swarm.go @@ -180,7 +180,7 @@ func (ci *connInfo) Direction() inet.Direction { } func (ci *connInfo) Latency() (time.Duration, error) { - return ci.peerstore.LatencyEWMA(peer.ID(ci.ID())), nil + return ci.peerstore.LatencyEWMA(ci.ID()), nil } func (ci *connInfo) Streams() ([]protocol.ID, error) { diff --git a/core/coreapi/test/path_test.go b/core/coreapi/test/path_test.go index f1337e809..82a6d0a58 100644 --- a/core/coreapi/test/path_test.go +++ b/core/coreapi/test/path_test.go @@ -1,3 +1,4 @@ +// Package test provides test utilities for core API. package test import ( diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index b0206e7b9..b6962ce1f 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -80,12 +80,12 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options // return //} - if settings.NoCopy && !(cfg.Experimental.FilestoreEnabled || cfg.Experimental.UrlstoreEnabled) { + if settings.NoCopy && (!cfg.Experimental.FilestoreEnabled && !cfg.Experimental.UrlstoreEnabled) { return path.ImmutablePath{}, errors.New("either the filestore or the urlstore must be enabled to use nocopy, see: https://github.com/ipfs/kubo/blob/master/docs/experimental-features.md#ipfs-filestore") } addblockstore := api.blockstore - if !(settings.FsCache || settings.NoCopy) { + if !settings.FsCache && !settings.NoCopy { addblockstore = bstore.NewGCBlockstore(api.baseBlocks, api.blockstore) } exch := api.exchange diff --git a/core/corehttp/commands.go b/core/corehttp/commands.go index 14de87d08..204223974 100644 --- a/core/corehttp/commands.go +++ b/core/corehttp/commands.go @@ -114,7 +114,7 @@ func patchCORSVars(c *cmdsHttp.ServerConfig, addr net.Addr) { for i, o := range oldOrigins { // TODO: allow replacing . tricky, ip4 and ip6 and hostnames... if port != "" { - o = strings.Replace(o, "", port, -1) + o = strings.ReplaceAll(o, "", port) } newOrigins[i] = o } diff --git a/core/corehttp/metrics.go b/core/corehttp/metrics.go index be1031513..a64ed2a7b 100644 --- a/core/corehttp/metrics.go +++ b/core/corehttp/metrics.go @@ -22,7 +22,7 @@ func MetricsScrapingOption(path string) ServeOption { } } -// This adds collection of OpenCensus metrics +// MetricsOpenCensusCollectionOption adds collection of OpenCensus metrics func MetricsOpenCensusCollectionOption() ServeOption { return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { log.Info("Init OpenCensus") diff --git a/core/corehttp/webui.go b/core/corehttp/webui.go index 9c3244ad2..fd16d9d28 100644 --- a/core/corehttp/webui.go +++ b/core/corehttp/webui.go @@ -1,6 +1,6 @@ package corehttp -// WebUI version confirmed to work with this Kubo version +// WebUIPath is the WebUI version confirmed to work with this Kubo version const WebUIPath = "/ipfs/bafybeifplj2s3yegn7ko7tdnwpoxa4c5uaqnk2ajnw5geqm34slcj6b6mu" // v4.8.0 // WebUIPaths is a list of all past webUI paths. diff --git a/core/coreiface/options/block.go b/core/coreiface/options/block.go index 83a43702c..84a3d7366 100644 --- a/core/coreiface/options/block.go +++ b/core/coreiface/options/block.go @@ -1,3 +1,4 @@ +// Package options defines configuration options for IPFS core interface methods. package options import ( diff --git a/core/coreiface/tests/api.go b/core/coreiface/tests/api.go index 86ab60ae9..f76f5b8bf 100644 --- a/core/coreiface/tests/api.go +++ b/core/coreiface/tests/api.go @@ -1,3 +1,4 @@ +// Package tests provides test suites for CoreAPI implementations. package tests import ( diff --git a/core/coreiface/tests/block.go b/core/coreiface/tests/block.go index 2b5a68a63..999a52264 100644 --- a/core/coreiface/tests/block.go +++ b/core/coreiface/tests/block.go @@ -53,7 +53,7 @@ func (tp *TestSuite) TestBlock(t *testing.T) { t.Run("TestBlockPin", tp.TestBlockPin) } -// when no opts are passed, produced CID has 'raw' codec +// TestBlockPut tests that when no opts are passed, produced CID has 'raw' codec func (tp *TestSuite) TestBlockPut(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -72,7 +72,7 @@ func (tp *TestSuite) TestBlockPut(t *testing.T) { } } -// Format is deprecated, it used invalid codec names. +// TestBlockPutFormatDagCbor tests that Format is deprecated, it used invalid codec names. // Confirm 'cbor' gets fixed to 'dag-cbor' func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) @@ -92,7 +92,7 @@ func (tp *TestSuite) TestBlockPutFormatDagCbor(t *testing.T) { } } -// Format is deprecated, it used invalid codec names. +// TestBlockPutFormatDagPb tests that Format is deprecated, it used invalid codec names. // Confirm 'protobuf' got fixed to 'dag-pb' func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) @@ -112,7 +112,7 @@ func (tp *TestSuite) TestBlockPutFormatDagPb(t *testing.T) { } } -// Format is deprecated, it used invalid codec names. +// TestBlockPutFormatV0 tests that Format is deprecated, it used invalid codec names. // Confirm fake codec 'v0' got fixed to CIDv0 (with implicit dag-pb codec) func (tp *TestSuite) TestBlockPutFormatV0(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) diff --git a/core/coreiface/tests/pin.go b/core/coreiface/tests/pin.go index 18f90c051..29623ad99 100644 --- a/core/coreiface/tests/pin.go +++ b/core/coreiface/tests/pin.go @@ -536,7 +536,7 @@ func assertPinLsAllConsistency(t *testing.T, ctx context.Context, api iface.Core t.Fatal(err) } - if expected, actual := len(pins), pinProps.Set.Len(); expected != actual { + if expected, actual := len(pins), pinProps.Len(); expected != actual { t.Fatalf("pin ls all has %d pins of type %s, but pin ls for the type has %d", expected, typeStr, actual) } diff --git a/core/coreiface/tests/unixfs.go b/core/coreiface/tests/unixfs.go index c2717216c..ae09b72d8 100644 --- a/core/coreiface/tests/unixfs.go +++ b/core/coreiface/tests/unixfs.go @@ -800,6 +800,7 @@ func (tp *TestSuite) TestLsEmptyDir(t *testing.T) { } } +// TestLsNonUnixfs tests listing non-UnixFS content. // TODO(lgierth) this should test properly, with len(links) > 0 func (tp *TestSuite) TestLsNonUnixfs(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) diff --git a/core/corerepo/gc.go b/core/corerepo/gc.go index bf285e3d9..d3397366b 100644 --- a/core/corerepo/gc.go +++ b/core/corerepo/gc.go @@ -1,3 +1,4 @@ +// Package corerepo provides repository management utilities for the IPFS core. package corerepo import ( diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 55a9d5bec..4ca373f27 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -1,3 +1,4 @@ +// Package coreunix provides Unix-like file addition utilities for IPFS. package coreunix import ( @@ -496,7 +497,7 @@ func (adder *Adder) addDir(ctx context.Context, path string, dir files.Directory adder.SetMfsRoot(mr) } - if !(toplevel && path == "") { + if !toplevel || path != "" { mr, err := adder.mfsRoot() if err != nil { return err diff --git a/core/mock/mock.go b/core/mock/mock.go index f9e0876f8..c976df3f5 100644 --- a/core/mock/mock.go +++ b/core/mock/mock.go @@ -1,3 +1,4 @@ +// Package coremock provides mock implementations for testing IPFS core functionality. package coremock import ( diff --git a/core/node/bitswap.go b/core/node/bitswap.go index e73145292..56f73c04d 100644 --- a/core/node/bitswap.go +++ b/core/node/bitswap.go @@ -126,7 +126,7 @@ func Bitswap(serverEnabled, libp2pEnabled, httpEnabled bool) interface{} { // Kubo uses own, customized ProviderQueryManager in.BitswapOpts = append(in.BitswapOpts, bitswap.WithClientOption(client.WithDefaultProviderQueryManager(false))) - var maxProviders int = DefaultMaxProviders + maxProviders := DefaultMaxProviders var bcDisposition string if in.Cfg.Internal.Bitswap != nil { diff --git a/core/node/groups.go b/core/node/groups.go index 9904574a8..e57ff6096 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -1,3 +1,4 @@ +// Package node implements IPFS nodes. package node import ( diff --git a/core/node/helpers/helpers.go b/core/node/helpers/helpers.go index 36ac435e8..7147be5f1 100644 --- a/core/node/helpers/helpers.go +++ b/core/node/helpers/helpers.go @@ -1,3 +1,4 @@ +// Package helpers provides utility functions for IPFS nodes. package helpers import ( diff --git a/core/node/libp2p/discovery.go b/core/node/libp2p/discovery.go index 086610772..a38980d91 100644 --- a/core/node/libp2p/discovery.go +++ b/core/node/libp2p/discovery.go @@ -1,3 +1,4 @@ +// Package libp2p provides libp2p configuration and setup for IPFS nodes. package libp2p import ( diff --git a/core/node/libp2p/fd/sys_unix.go b/core/node/libp2p/fd/sys_unix.go index 5e417c0fa..7138e86d3 100644 --- a/core/node/libp2p/fd/sys_unix.go +++ b/core/node/libp2p/fd/sys_unix.go @@ -1,6 +1,7 @@ //go:build linux || darwin // +build linux darwin +// Package fd provides file descriptor management utilities. package fd import ( diff --git a/core/node/libp2p/rcmgr_defaults.go b/core/node/libp2p/rcmgr_defaults.go index 98fdccb99..5b6fb22bc 100644 --- a/core/node/libp2p/rcmgr_defaults.go +++ b/core/node/libp2p/rcmgr_defaults.go @@ -19,7 +19,7 @@ var infiniteResourceLimits = rcmgr.InfiniteLimits.ToPartialLimitConfig().System // The defaults follow the documentation in docs/libp2p-resource-management.md. // Any changes in the logic here should be reflected there. func createDefaultLimitConfig(cfg config.SwarmConfig) (limitConfig rcmgr.ConcreteLimitConfig, logMessageForStartup string, err error) { - maxMemoryDefaultString := humanize.Bytes(uint64(memory.TotalMemory()) / 2) + maxMemoryDefaultString := humanize.Bytes(memory.TotalMemory() / 2) maxMemoryString := cfg.ResourceMgr.MaxMemory.WithDefault(maxMemoryDefaultString) maxMemory, err := humanize.ParseBytes(maxMemoryString) if err != nil { diff --git a/doc.go b/doc.go index 1183559a0..58321d1e3 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,2 @@ -/* -IPFS is a global, versioned, peer-to-peer filesystem -*/ +// Package ipfs is a global, versioned, peer-to-peer filesystem package ipfs diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index 9c36c9a26..898b1f04e 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -1,7 +1,7 @@ //go:build !nofuse && !openbsd && !netbsd && !plan9 // +build !nofuse,!openbsd,!netbsd,!plan9 -// package fuse/ipns implements a fuse filesystem that interfaces +// Package ipns implements a fuse filesystem that interfaces // with ipns, the naming system for ipfs. package ipns @@ -163,7 +163,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { switch name { case "mach_kernel", ".hidden", "._.": // Just quiet some log noise on OS X. - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } if lnk, ok := r.LocalLinks[name]; ok { @@ -178,7 +178,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { case *FileNode: return nd, nil default: - return nil, syscall.Errno(syscall.EIO) + return nil, syscall.EIO } } @@ -187,7 +187,7 @@ func (r *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { resolved, err := r.Ipfs.Name().Resolve(ctx, ipnsName) if err != nil { log.Warnf("ipns: namesys resolve error: %s", err) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } if resolved.Namespace() != path.IPFSNamespace { @@ -279,7 +279,7 @@ func (d *Directory) Lookup(ctx context.Context, name string) (fs.Node, error) { child, err := d.dir.Child(name) if err != nil { // todo: make this error more versatile. - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } switch child := child.(type) { @@ -317,7 +317,7 @@ func (d *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { if len(entries) > 0 { return entries, nil } - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } func (fi *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { @@ -428,7 +428,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse. if req.Flags&fuse.OpenTruncate != 0 { if req.Flags.IsReadOnly() { log.Error("tried to open a readonly file with truncate") - return nil, syscall.Errno(syscall.ENOTSUP) + return nil, syscall.ENOTSUP } log.Info("Need to truncate file!") err := fd.Truncate(0) @@ -439,7 +439,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse. log.Info("Need to append to file!") if req.Flags.IsReadOnly() { log.Error("tried to open a readonly file with append") - return nil, syscall.Errno(syscall.ENOTSUP) + return nil, syscall.ENOTSUP } _, err := fd.Seek(0, io.SeekEnd) @@ -491,7 +491,7 @@ func (d *Directory) Create(ctx context.Context, req *fuse.CreateRequest, resp *f func (d *Directory) Remove(ctx context.Context, req *fuse.RemoveRequest) error { err := d.dir.Unlink(req.Name) if err != nil { - return syscall.Errno(syscall.ENOENT) + return syscall.ENOENT } return nil } @@ -521,7 +521,7 @@ func (d *Directory) Rename(ctx context.Context, req *fuse.RenameRequest, newDir } case *FileNode: log.Error("Cannot move node into a file!") - return syscall.Errno(syscall.EPERM) + return syscall.EPERM default: log.Error("Unknown node type for rename target dir!") return errors.New("unknown fs node type") diff --git a/fuse/mfs/mfs_unix.go b/fuse/mfs/mfs_unix.go index 91cad257d..aaa35030d 100644 --- a/fuse/mfs/mfs_unix.go +++ b/fuse/mfs/mfs_unix.go @@ -2,6 +2,7 @@ // +build linux darwin freebsd netbsd openbsd // +build !nofuse +// Package mfs provides a FUSE interface for IPFS mutable file system. package mfs import ( @@ -29,22 +30,22 @@ const ( dirSize = 8 ) -// FUSE filesystem mounted at /mfs. +// FileSystem is a FUSE filesystem mounted at /mfs. type FileSystem struct { root Dir } -// Get filesystem root. +// Root gets filesystem root. func (fs *FileSystem) Root() (fs.Node, error) { return &fs.root, nil } -// FUSE Adapter for MFS directories. +// Dir is a FUSE Adapter for MFS directories. type Dir struct { mfsDir *mfs.Directory } -// Directory attributes (stat). +// Attr returns directory attributes (stat). func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { attr.Mode = mfsDirMode attr.Size = dirSize * blockSize @@ -52,12 +53,12 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { return nil } -// Access files in a directory. +// Lookup accesses files in a directory. func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (fs.Node, error) { mfsNode, err := dir.mfsDir.Child(req.Name) switch err { case os.ErrNotExist: - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT case nil: default: return nil, err @@ -76,10 +77,10 @@ func (dir *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse. return &result, nil } - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } -// List (ls) MFS directory. +// ReadDirAll lists (ls) MFS directory. func (dir *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { var res []fuse.Dirent nodes, err := dir.mfsDir.List(ctx) @@ -136,7 +137,7 @@ func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error { return dir.mfsDir.Flush() } -// Move (mv) an MFS file. +// Rename moves (mv) an MFS file. func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fs.Node) error { file, err := dir.mfsDir.Child(req.OldName) if err != nil { @@ -215,13 +216,13 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse. return &file, &handler, nil } -// List dir xattr. +// Listxattr lists dir xattr. func (dir *Dir) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error { resp.Append(ipfsCIDXattr) return nil } -// Get dir xattr. +// Getxattr gets dir xattr. func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error { switch req.Name { case ipfsCIDXattr: @@ -236,12 +237,12 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f } } -// FUSE adapter for MFS files. +// File is a FUSE adapter for MFS files. type File struct { mfsFile *mfs.File } -// File attributes. +// Attr returns file attributes. func (file *File) Attr(ctx context.Context, attr *fuse.Attr) error { size, _ := file.mfsFile.Size() @@ -283,18 +284,18 @@ func (file *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.Op }, nil } -// Sync the file's contents to MFS. +// Fsync syncs the file's contents to MFS. func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { return file.mfsFile.Sync() } -// List file xattr. +// Listxattr lists file xattr. func (file *File) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, resp *fuse.ListxattrResponse) error { resp.Append(ipfsCIDXattr) return nil } -// Get file xattr. +// Getxattr gets file xattr. func (file *File) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error { switch req.Name { case ipfsCIDXattr: @@ -309,7 +310,7 @@ func (file *File) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp } } -// Wrapper for MFS's file descriptor that conforms to the FUSE fs.Handler +// FileHandler is a wrapper for MFS's file descriptor that conforms to the FUSE fs.Handler // interface. type FileHandler struct { mfsFD mfs.FileDescriptor @@ -353,7 +354,7 @@ func (fh *FileHandler) Write(ctx context.Context, req *fuse.WriteRequest, resp * return nil } -// Flushes the file's buffer. +// Flush flushes the file's buffer. func (fh *FileHandler) Flush(ctx context.Context, req *fuse.FlushRequest) error { fh.mu.Lock() defer fh.mu.Unlock() @@ -361,7 +362,7 @@ func (fh *FileHandler) Flush(ctx context.Context, req *fuse.FlushRequest) error return fh.mfsFD.Flush() } -// Closes the file. +// Release closes the file. func (fh *FileHandler) Release(ctx context.Context, req *fuse.ReleaseRequest) error { fh.mu.Lock() defer fh.mu.Unlock() @@ -369,7 +370,7 @@ func (fh *FileHandler) Release(ctx context.Context, req *fuse.ReleaseRequest) er return fh.mfsFD.Close() } -// Create new filesystem. +// NewFileSystem creates new filesystem. func NewFileSystem(ipfs *core.IpfsNode) fs.FS { return &FileSystem{ root: Dir{ diff --git a/fuse/mount/fuse.go b/fuse/mount/fuse.go index e18c0b4a9..d41de4102 100644 --- a/fuse/mount/fuse.go +++ b/fuse/mount/fuse.go @@ -27,7 +27,7 @@ type mount struct { unmountOnce sync.Once } -// Mount mounts a fuse fs.FS at a given location, and returns a Mount instance. +// NewMount mounts a fuse fs.FS at a given location, and returns a Mount instance. // ctx is parent is a ContextGroup to bind the mount's ContextGroup to. func NewMount(fsys fs.FS, mountpoint string, allowOther bool) (Mount, error) { var conn *fuse.Conn diff --git a/fuse/mount/mount.go b/fuse/mount/mount.go index ca10405fe..2915d3a0d 100644 --- a/fuse/mount/mount.go +++ b/fuse/mount/mount.go @@ -1,4 +1,4 @@ -// package mount provides a simple abstraction around a mount point +// Package mount provides a simple abstraction around a mount point package mount import ( diff --git a/fuse/node/mount_unix.go b/fuse/node/mount_unix.go index 6c63f6e50..f3f1acc68 100644 --- a/fuse/node/mount_unix.go +++ b/fuse/node/mount_unix.go @@ -1,6 +1,7 @@ //go:build !windows && !openbsd && !netbsd && !plan9 && !nofuse // +build !windows,!openbsd,!netbsd,!plan9,!nofuse +// Package node provides FUSE mount functionality for IPFS nodes. package node import ( @@ -70,8 +71,8 @@ func doMount(node *core.IpfsNode, fsdir, nsdir, mfsdir string) error { fmtFuseErr := func(err error, mountpoint string) error { s := err.Error() if strings.Contains(s, fuseNoDirectory) { - s = strings.Replace(s, `fusermount: "fusermount:`, "", -1) - s = strings.Replace(s, `\n", exit status 1`, "", -1) + s = strings.ReplaceAll(s, `fusermount: "fusermount:`, "") + s = strings.ReplaceAll(s, `\n", exit status 1`, "") return errors.New(s) } if s == fuseExitStatus1 { diff --git a/fuse/readonly/doc.go b/fuse/readonly/doc.go index 1a7e779fe..68057b968 100644 --- a/fuse/readonly/doc.go +++ b/fuse/readonly/doc.go @@ -1,3 +1,3 @@ -// package fuse/readonly implements a fuse filesystem to access files +// Package readonly implements a fuse filesystem to access files // stored inside of ipfs. package readonly diff --git a/fuse/readonly/readonly_unix.go b/fuse/readonly/readonly_unix.go index 573e80e23..08cbd89be 100644 --- a/fuse/readonly/readonly_unix.go +++ b/fuse/readonly/readonly_unix.go @@ -59,38 +59,38 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { switch name { case "mach_kernel", ".hidden", "._.": // Just quiet some log noise on OS X. - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } p, err := path.NewPath("/ipfs/" + name) if err != nil { log.Debugf("fuse failed to parse path: %q: %s", name, err) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } imPath, err := path.NewImmutablePath(p) if err != nil { log.Debugf("fuse failed to convert path: %q: %s", name, err) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } nd, ndLnk, err := s.Ipfs.UnixFSPathResolver.ResolvePath(ctx, imPath) if err != nil { // todo: make this error more versatile. - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } cidLnk, ok := ndLnk.(cidlink.Link) if !ok { log.Debugf("non-cidlink returned from ResolvePath: %v", ndLnk) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } // convert ipld-prime node to universal node blk, err := s.Ipfs.Blockstore.Get(ctx, cidLnk.Cid) if err != nil { log.Debugf("fuse failed to retrieve block: %v: %s", cidLnk, err) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } var fnd ipld.Node @@ -107,11 +107,11 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { fnd, err = mdag.RawNodeConverter(blk, nd) default: log.Error("fuse node was not a supported type") - return nil, syscall.Errno(syscall.ENOTSUP) + return nil, syscall.ENOTSUP } if err != nil { log.Errorf("could not convert protobuf or raw node: %s", err) - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } return &Node{Ipfs: s.Ipfs, Nd: fnd}, nil @@ -120,7 +120,7 @@ func (s *Root) Lookup(ctx context.Context, name string) (fs.Node, error) { // ReadDirAll reads a particular directory. Disallowed for root. func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { log.Debug("read Root") - return nil, syscall.Errno(syscall.EPERM) + return nil, syscall.EPERM } // Node is the core object representing a filesystem tree node. @@ -162,7 +162,7 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error { case ft.TFile: size := s.cached.FileSize() a.Mode = 0o444 - a.Size = uint64(size) + a.Size = size a.Blocks = uint64(len(s.Nd.Links())) case ft.TRaw: a.Mode = 0o444 @@ -184,12 +184,12 @@ func (s *Node) Lookup(ctx context.Context, name string) (fs.Node, error) { switch err { case os.ErrNotExist, mdag.ErrLinkNotFound: // todo: make this error more versatile. - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT case nil: // noop default: log.Errorf("fuse lookup %q: %s", name, err) - return nil, syscall.Errno(syscall.EIO) + return nil, syscall.EIO } nd, err := s.Ipfs.DAG.Get(ctx, link.Cid) @@ -252,7 +252,7 @@ func (s *Node) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { if len(entries) > 0 { return entries, nil } - return nil, syscall.Errno(syscall.ENOENT) + return nil, syscall.ENOENT } func (s *Node) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error { @@ -278,7 +278,7 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR return err } // Data has a capacity of Size - buf := resp.Data[:int(req.Size)] + buf := resp.Data[:req.Size] n, err := io.ReadFull(r, buf) resp.Data = buf[:n] switch err { diff --git a/misc/fsutil/fsutil.go b/misc/fsutil/fsutil.go index 6773ec12f..9f2960aca 100644 --- a/misc/fsutil/fsutil.go +++ b/misc/fsutil/fsutil.go @@ -1,3 +1,4 @@ +// Package fsutil provides filesystem utilities. package fsutil import ( diff --git a/p2p/listener.go b/p2p/listener.go index f5942ffa0..68457ec01 100644 --- a/p2p/listener.go +++ b/p2p/listener.go @@ -1,3 +1,4 @@ +// Package p2p implements libp2p connectivity utilities. package p2p import ( diff --git a/p2p/stream.go b/p2p/stream.go index 5d05cba79..690f5c795 100644 --- a/p2p/stream.go +++ b/p2p/stream.go @@ -76,7 +76,7 @@ func (r *StreamRegistry) Register(streamInfo *Stream) { r.Lock() defer r.Unlock() - r.ConnManager.TagPeer(streamInfo.peer, cmgrTag, 20) + r.TagPeer(streamInfo.peer, cmgrTag, 20) r.conns[streamInfo.peer]++ streamInfo.id = r.nextID @@ -99,7 +99,7 @@ func (r *StreamRegistry) Deregister(streamID uint64) { r.conns[p]-- if r.conns[p] < 1 { delete(r.conns, p) - r.ConnManager.UntagPeer(p, cmgrTag) + r.UntagPeer(p, cmgrTag) } delete(r.Streams, streamID) diff --git a/plugin/daemon.go b/plugin/daemon.go index 9f75099d6..7757aafd5 100644 --- a/plugin/daemon.go +++ b/plugin/daemon.go @@ -1,3 +1,4 @@ +// Package plugin provides interfaces for extending kubo functionality. package plugin import ( diff --git a/plugin/loader/loader.go b/plugin/loader/loader.go index 624907614..fa2febcd2 100644 --- a/plugin/loader/loader.go +++ b/plugin/loader/loader.go @@ -1,3 +1,4 @@ +// Package loader provides plugin loading functionality for kubo. package loader import ( diff --git a/plugin/plugins/badgerds/badgerds.go b/plugin/plugins/badgerds/badgerds.go index 2410f196c..99484ad90 100644 --- a/plugin/plugins/badgerds/badgerds.go +++ b/plugin/plugins/badgerds/badgerds.go @@ -1,3 +1,4 @@ +// Package badgerds provides a BadgerDB datastore plugin. package badgerds import ( diff --git a/plugin/plugins/dagjose/dagjose.go b/plugin/plugins/dagjose/dagjose.go index 4545e2e96..075c9d580 100644 --- a/plugin/plugins/dagjose/dagjose.go +++ b/plugin/plugins/dagjose/dagjose.go @@ -1,3 +1,4 @@ +// Package dagjose provides the DAG-JOSE codec plugin. package dagjose import ( diff --git a/plugin/plugins/flatfs/flatfs.go b/plugin/plugins/flatfs/flatfs.go index 397c2656c..e86f30d13 100644 --- a/plugin/plugins/flatfs/flatfs.go +++ b/plugin/plugins/flatfs/flatfs.go @@ -1,3 +1,4 @@ +// Package flatfs provides a flatfs datastore plugin. package flatfs import ( diff --git a/plugin/plugins/fxtest/fxtest.go b/plugin/plugins/fxtest/fxtest.go index 4205e3eb8..15d298e49 100644 --- a/plugin/plugins/fxtest/fxtest.go +++ b/plugin/plugins/fxtest/fxtest.go @@ -1,3 +1,4 @@ +// Package fxtest provides a test plugin for the fx dependency injection framework. package fxtest import ( diff --git a/plugin/plugins/git/git.go b/plugin/plugins/git/git.go index baaea6c35..d2c694344 100644 --- a/plugin/plugins/git/git.go +++ b/plugin/plugins/git/git.go @@ -1,3 +1,4 @@ +// Package git provides a git IPLD codec plugin. package git import ( diff --git a/plugin/plugins/levelds/levelds.go b/plugin/plugins/levelds/levelds.go index 78331730e..4ad3d9c85 100644 --- a/plugin/plugins/levelds/levelds.go +++ b/plugin/plugins/levelds/levelds.go @@ -1,3 +1,4 @@ +// Package levelds provides a LevelDB datastore plugin. package levelds import ( diff --git a/plugin/plugins/nopfs/nopfs.go b/plugin/plugins/nopfs/nopfs.go index c32d7533f..8aec0c02f 100644 --- a/plugin/plugins/nopfs/nopfs.go +++ b/plugin/plugins/nopfs/nopfs.go @@ -1,3 +1,4 @@ +// Package nopfs provides a content blocking plugin using the nopfs library. package nopfs import ( diff --git a/plugin/plugins/pebbleds/pebbleds.go b/plugin/plugins/pebbleds/pebbleds.go index fab1cc16a..e6a4e65be 100644 --- a/plugin/plugins/pebbleds/pebbleds.go +++ b/plugin/plugins/pebbleds/pebbleds.go @@ -1,3 +1,4 @@ +// Package pebbleds provides a PebbleDB datastore plugin. package pebbleds import ( diff --git a/plugin/plugins/peerlog/peerlog.go b/plugin/plugins/peerlog/peerlog.go index 822a636c8..126a959a4 100644 --- a/plugin/plugins/peerlog/peerlog.go +++ b/plugin/plugins/peerlog/peerlog.go @@ -1,3 +1,4 @@ +// Package peerlog provides a plugin for logging peer connection events. package peerlog import ( diff --git a/plugin/plugins/telemetry/telemetry.go b/plugin/plugins/telemetry/telemetry.go index 0414e5098..071b4503f 100644 --- a/plugin/plugins/telemetry/telemetry.go +++ b/plugin/plugins/telemetry/telemetry.go @@ -1,3 +1,4 @@ +// Package telemetry provides a plugin for sending telemetry data. package telemetry import ( @@ -531,7 +532,7 @@ func (p *telemetryPlugin) sendTelemetry() error { log.Debugf("sending telemetry:\n %s", data) - req, err := http.NewRequest("POST", p.endpoint, bytes.NewBuffer(data)) + req, err := http.NewRequest(http.MethodPost, p.endpoint, bytes.NewBuffer(data)) if err != nil { return err } diff --git a/plugin/plugins/telemetry/telemetry_test.go b/plugin/plugins/telemetry/telemetry_test.go index 6b88ced92..62bb7efb4 100644 --- a/plugin/plugins/telemetry/telemetry_test.go +++ b/plugin/plugins/telemetry/telemetry_test.go @@ -27,7 +27,7 @@ func mockServer(t *testing.T) (*httptest.Server, func() LogEvent) { // Create a mock HTTP test server return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Check if the request is POST to the correct endpoint - if r.Method != "POST" || r.URL.Path != "/" { + if r.Method != http.MethodPost || r.URL.Path != "/" { t.Log("invalid request") http.Error(w, "invalid request", http.StatusBadRequest) return diff --git a/profile/profile.go b/profile/profile.go index 32df334e3..788b70569 100644 --- a/profile/profile.go +++ b/profile/profile.go @@ -1,3 +1,4 @@ +// Package profile provides performance profiling utilities for kubo. package profile import ( diff --git a/repo/common/common.go b/repo/common/common.go index 6a6dee6dd..3259fe5c3 100644 --- a/repo/common/common.go +++ b/repo/common/common.go @@ -1,3 +1,4 @@ +// Package common provides shared utilities for repository implementations. package common import ( diff --git a/repo/fsrepo/doc.go b/repo/fsrepo/doc.go index 327afcf09..fba5965c8 100644 --- a/repo/fsrepo/doc.go +++ b/repo/fsrepo/doc.go @@ -1,4 +1,4 @@ -// package fsrepo +// Package fsrepo implements filesystem-backed repository storage. // // TODO explain the package roadmap... // diff --git a/repo/fsrepo/migrations/fetch.go b/repo/fsrepo/migrations/fetch.go index ee1deefa0..e9c77c9db 100644 --- a/repo/fsrepo/migrations/fetch.go +++ b/repo/fsrepo/migrations/fetch.go @@ -1,3 +1,4 @@ +// Package migrations provides utilities for fetching and running IPFS repository migrations. package migrations import ( diff --git a/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go b/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go index ea020dfcc..537790063 100644 --- a/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go +++ b/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go @@ -1,3 +1,4 @@ +// Package ipfsfetcher provides utilities for fetching migrations via IPFS. package ipfsfetcher import ( diff --git a/repo/repo.go b/repo/repo.go index f345e89b4..a712cf78b 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -1,3 +1,4 @@ +// Package repo provides interfaces for IPFS repository management. package repo import ( diff --git a/routing/composer.go b/routing/composer.go index 500fa371e..f3e67ca95 100644 --- a/routing/composer.go +++ b/routing/composer.go @@ -1,3 +1,4 @@ +// Package routing provides routing utilities for IPFS. package routing import ( diff --git a/routing/delegated_test.go b/routing/delegated_test.go index 028503a37..a8af0ee51 100644 --- a/routing/delegated_test.go +++ b/routing/delegated_test.go @@ -55,7 +55,7 @@ func TestParser(t *testing.T) { RouterName: "r2", }, }, &ExtraDHTParams{}, &ExtraHTTPParams{ - PeerID: string(pid), + PeerID: pid, PrivKeyB64: sk, }) @@ -146,7 +146,7 @@ func TestParserRecursive(t *testing.T) { RouterName: "composable2", }, }, &ExtraDHTParams{}, &ExtraHTTPParams{ - PeerID: string(pid), + PeerID: pid, PrivKeyB64: sk, }) diff --git a/test/cli/add_test.go b/test/cli/add_test.go index e4138b624..244158b22 100644 --- a/test/cli/add_test.go +++ b/test/cli/add_test.go @@ -1,3 +1,4 @@ +// Package cli contains integration tests for IPFS CLI commands. package cli import ( diff --git a/test/cli/delegated_routing_v1_http_client_test.go b/test/cli/delegated_routing_v1_http_client_test.go index 44e62246b..d49b29391 100644 --- a/test/cli/delegated_routing_v1_http_client_test.go +++ b/test/cli/delegated_routing_v1_http_client_test.go @@ -57,7 +57,7 @@ func TestHTTPDelegatedRouting(t *testing.T) { } }) res := node.RunIPFS("daemon") - assert.Equal(t, 1, res.ExitErr.ProcessState.ExitCode()) + assert.Equal(t, 1, res.ExitErr.ExitCode()) assert.Contains( t, res.Stderr.String(), @@ -78,7 +78,7 @@ func TestHTTPDelegatedRouting(t *testing.T) { } }) res := node.RunIPFS("daemon") - assert.Equal(t, 1, res.ExitErr.ProcessState.ExitCode()) + assert.Equal(t, 1, res.ExitErr.ExitCode()) assert.Contains( t, res.Stderr.String(), diff --git a/test/cli/dht_autoclient_test.go b/test/cli/dht_autoclient_test.go index adb200509..8b3d76cc1 100644 --- a/test/cli/dht_autoclient_test.go +++ b/test/cli/dht_autoclient_test.go @@ -12,7 +12,7 @@ import ( func TestDHTAutoclient(t *testing.T) { t.Parallel() nodes := harness.NewT(t).NewNodes(10).Init() - harness.Nodes(nodes[8:]).ForEachPar(func(node *harness.Node) { + nodes[8:].ForEachPar(func(node *harness.Node) { node.IPFS("config", "Routing.Type", "autoclient") }) nodes.StartDaemons().Connect() diff --git a/test/cli/harness/harness.go b/test/cli/harness/harness.go index 067608cdc..a6c4caeba 100644 --- a/test/cli/harness/harness.go +++ b/test/cli/harness/harness.go @@ -1,3 +1,4 @@ +// Package harness provides a test harness for IPFS CLI integration testing. package harness import ( @@ -24,6 +25,7 @@ type Harness struct { Nodes Nodes } +// EnableDebugLogging enables debug logging for the test harness. // TODO: use zaptest.NewLogger(t) instead func EnableDebugLogging() { err := logging.SetLogLevel("testharness", "DEBUG") diff --git a/test/cli/harness/pbinspect.go b/test/cli/harness/pbinspect.go index 6abddb61f..e8ad7df31 100644 --- a/test/cli/harness/pbinspect.go +++ b/test/cli/harness/pbinspect.go @@ -31,7 +31,7 @@ func (n *Node) InspectPBNode(cid string) (PBNode, error) { } -// Define structs to match the JSON for +// PBHash defines structs to match the JSON for protobuf inspection. type PBHash struct { Slash string `json:"/"` } diff --git a/test/cli/http_retrieval_client_test.go b/test/cli/http_retrieval_client_test.go index e2934fc99..9a0f62c8c 100644 --- a/test/cli/http_retrieval_client_test.go +++ b/test/cli/http_retrieval_client_test.go @@ -107,7 +107,7 @@ func NewMockHTTPProviderServer(c cid.Cid, body string, debug bool) *httptest.Ser if strings.HasPrefix(req.URL.Path, expectedPathPrefix) { w.Header().Set("Content-Type", "application/vnd.ipld.raw") w.WriteHeader(http.StatusOK) - if req.Method == "GET" { + if req.Method == http.MethodGet { _, err := w.Write([]byte(body)) if err != nil { fmt.Fprintf(os.Stderr, "NewMockHTTPProviderServer GET %s error: %v\n", req.URL.Path, err) diff --git a/test/cli/must.go b/test/cli/must.go index e12598466..2c8cb8735 100644 --- a/test/cli/must.go +++ b/test/cli/must.go @@ -1,3 +1,4 @@ +// Package cli provides testing utilities for IPFS CLI commands. package cli func MustVal[V any](val V, err error) V { diff --git a/test/cli/testutils/asserts.go b/test/cli/testutils/asserts.go index cf840c20e..46ac7496c 100644 --- a/test/cli/testutils/asserts.go +++ b/test/cli/testutils/asserts.go @@ -1,3 +1,4 @@ +// Package testutils provides utilities for testing CLI commands. package testutils import ( diff --git a/test/cli/testutils/files.go b/test/cli/testutils/files.go index e17c98adf..9efc17ee6 100644 --- a/test/cli/testutils/files.go +++ b/test/cli/testutils/files.go @@ -14,7 +14,7 @@ func MustOpen(name string) *os.File { return f } -// Searches for a file in a dir, then the parent dir, etc. +// FindUp searches for a file in a dir, then the parent dir, etc. // If the file is not found, an empty string is returned. func FindUp(name, dir string) string { curDir := dir diff --git a/test/cli/testutils/httprouting/mock_http_content_router.go b/test/cli/testutils/httprouting/mock_http_content_router.go index 8f6f31023..dc512cafc 100644 --- a/test/cli/testutils/httprouting/mock_http_content_router.go +++ b/test/cli/testutils/httprouting/mock_http_content_router.go @@ -1,3 +1,4 @@ +// Package httprouting provides test utilities for HTTP routing functionality. package httprouting import ( diff --git a/test/cli/testutils/pinningservice/pinning.go b/test/cli/testutils/pinningservice/pinning.go index 6bfd4ed4e..aded7f633 100644 --- a/test/cli/testutils/pinningservice/pinning.go +++ b/test/cli/testutils/pinningservice/pinning.go @@ -1,3 +1,4 @@ +// Package pinningservice provides test utilities for pinning service functionality. package pinningservice import ( diff --git a/test/cli/testutils/random_deterministic.go b/test/cli/testutils/random_deterministic.go index e55404168..8c8167d27 100644 --- a/test/cli/testutils/random_deterministic.go +++ b/test/cli/testutils/random_deterministic.go @@ -27,7 +27,7 @@ func (r *randomReader) Read(p []byte) (int, error) { return int(n), nil } -// createRandomReader produces specified number of pseudo-random bytes +// DeterministicRandomReader produces specified number of pseudo-random bytes // from a seed. func DeterministicRandomReader(sizeStr string, seed string) (io.Reader, error) { size, err := humanize.ParseBytes(sizeStr) diff --git a/thirdparty/unit/unit.go b/thirdparty/unit/unit.go index 3b10db44c..b26bb4a54 100644 --- a/thirdparty/unit/unit.go +++ b/thirdparty/unit/unit.go @@ -1,3 +1,4 @@ +// Package unit provides data size unit formatting utilities. package unit import "fmt" diff --git a/thirdparty/verifbs/verifbs.go b/thirdparty/verifbs/verifbs.go index 2fcc52bb9..6fdf0e435 100644 --- a/thirdparty/verifbs/verifbs.go +++ b/thirdparty/verifbs/verifbs.go @@ -1,3 +1,4 @@ +// Package verifbs provides a verified blockstore wrapper. package verifbs import (