1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 17:36:38 +08:00

Merge pull request #2288 from tomgg/tmg/trivial

trivial: various superficial fixes
This commit is contained in:
Jeromy Johnson
2016-02-02 22:27:43 -08:00
13 changed files with 59 additions and 43 deletions

View File

@ -57,7 +57,7 @@ type cmdInvocation struct {
// main roadmap: // main roadmap:
// - parse the commandline to get a cmdInvocation // - parse the commandline to get a cmdInvocation
// - if user requests, help, print it and exit. // - if user requests help, print it and exit.
// - run the command invocation // - run the command invocation
// - output the response // - output the response
// - if anything fails, print error, maybe with help // - if anything fails, print error, maybe with help

View File

@ -133,7 +133,8 @@ func (c *Command) Call(req Request) Response {
} }
} }
// If the command specified an output type, ensure the actual value returned is of that type // If the command specified an output type, ensure the actual value
// returned is of that type
if cmd.Type != nil && !isChan { if cmd.Type != nil && !isChan {
expectedType := reflect.TypeOf(cmd.Type) expectedType := reflect.TypeOf(cmd.Type)
@ -146,7 +147,7 @@ func (c *Command) Call(req Request) Response {
return res return res
} }
// Resolve gets the subcommands at the given path // Resolve returns the subcommands at the given path
func (c *Command) Resolve(pth []string) ([]*Command, error) { func (c *Command) Resolve(pth []string) ([]*Command, error) {
cmds := make([]*Command, len(pth)+1) cmds := make([]*Command, len(pth)+1)
cmds[0] = c cmds[0] = c
@ -175,7 +176,7 @@ func (c *Command) Get(path []string) (*Command, error) {
return cmds[len(cmds)-1], nil return cmds[len(cmds)-1], nil
} }
// GetOptions gets the options in the given path of commands // GetOptions returns the options in the given path of commands
func (c *Command) GetOptions(path []string) (map[string]Option, error) { func (c *Command) GetOptions(path []string) (map[string]Option, error) {
options := make([]Option, 0, len(c.Options)) options := make([]Option, 0, len(c.Options))
@ -217,12 +218,15 @@ func (c *Command) CheckArguments(req Request) error {
// iterate over the arg definitions // iterate over the arg definitions
valueIndex := 0 // the index of the current value (in `args`) valueIndex := 0 // the index of the current value (in `args`)
for _, argDef := range c.Arguments { for _, argDef := range c.Arguments {
// skip optional argument definitions if there aren't sufficient remaining values // skip optional argument definitions if there aren't
if len(args)-valueIndex <= numRequired && !argDef.Required || argDef.Type == ArgFile { // sufficient remaining values
if len(args)-valueIndex <= numRequired && !argDef.Required ||
argDef.Type == ArgFile {
continue continue
} }
// the value for this argument definition. can be nil if it wasn't provided by the caller // the value for this argument definition. can be nil if it
// wasn't provided by the caller
v, found := "", false v, found := "", false
if valueIndex < len(args) { if valueIndex < len(args) {
v = args[valueIndex] v = args[valueIndex]
@ -254,7 +258,8 @@ func (c *Command) Subcommand(id string) *Command {
return c.Subcommands[id] return c.Subcommands[id]
} }
// checkArgValue returns an error if a given arg value is not valid for the given Argument // checkArgValue returns an error if a given arg value is not valid for the
// given Argument
func checkArgValue(v string, found bool, def Argument) error { func checkArgValue(v string, found bool, def Argument) error {
if !found && def.Required { if !found && def.Required {
return fmt.Errorf("Argument '%s' is required", def.Name) return fmt.Errorf("Argument '%s' is required", def.Name)

View File

@ -11,11 +11,12 @@ var (
ErrNotReader = errors.New("This file is a directory, can't use Reader functions") ErrNotReader = errors.New("This file is a directory, can't use Reader functions")
) )
// File is an interface that provides functionality for handling files/directories // File is an interface that provides functionality for handling
// as values that can be supplied to commands. For directories, child files are // files/directories as values that can be supplied to commands. For
// accessed serially by calling `NextFile()`. // directories, child files are accessed serially by calling `NextFile()`.
type File interface { type File interface {
// Files implement ReadCloser, but can only be read from or closed if they are not directories // Files implement ReadCloser, but can only be read from or closed if
// they are not directories
io.ReadCloser io.ReadCloser
// FileName returns a filename path associated with this file // FileName returns a filename path associated with this file
@ -24,13 +25,15 @@ type File interface {
// FullPath returns the full path in the os associated with this file // FullPath returns the full path in the os associated with this file
FullPath() string FullPath() string
// IsDirectory returns true if the File is a directory (and therefore supports calling `NextFile`) // IsDirectory returns true if the File is a directory (and therefore
// and false if the File is a normal file (and therefor supports calling `Read` and `Close`) // supports calling `NextFile`) and false if the File is a normal file
// (and therefor supports calling `Read` and `Close`)
IsDirectory() bool IsDirectory() bool
// NextFile returns the next child file available (if the File is a directory). // NextFile returns the next child file available (if the File is a
// It will return (nil, io.EOF) if no more files are available. // directory). It will return (nil, io.EOF) if no more files are
// If the file is a regular file (not a directory), NextFile will return a non-nil error. // available. If the file is a regular file (not a directory), NextFile
// will return a non-nil error.
NextFile() (File, error) NextFile() (File, error)
} }

View File

@ -75,7 +75,7 @@ recover quickly. This led to gateways not bootstrapping peers
fast enough. fast enough.
The approach taken here is to do what crypto/tls does: The approach taken here is to do what crypto/tls does:
defer the handshake until Read/Write[1]. There are a number of defer the handshake until Read/Write[0]. There are a number of
reasons why this is _the right thing to do_: reasons why this is _the right thing to do_:
- it delays handshaking until it is known to be necessary (doing io) - it delays handshaking until it is known to be necessary (doing io)
- it "accepts" before the handshake, getting the handshake out of the - it "accepts" before the handshake, getting the handshake out of the

View File

@ -1,10 +1,8 @@
/* // Package commands implements the IPFS command interface
Package commands implements the IPFS command interface //
// Using github.com/ipfs/go-ipfs/commands to define the command line and HTTP
Using github.com/ipfs/go-ipfs/commands to define the command line and // APIs. This is the interface available to folks using IPFS from outside of
HTTP APIs. This is the interface available to folks consuming IPFS // the Go language.
from outside of the Go language.
*/
package commands package commands
import ( import (

View File

@ -215,8 +215,15 @@ func doMount(node *core.IpfsNode, fsdir, nsdir string) error {
<-done <-done
<-done <-done
if err1 != nil {
log.Errorf("error mounting: %s", err1)
}
if err2 != nil {
log.Errorf("error mounting: %s", err2)
}
if err1 != nil || err2 != nil { if err1 != nil || err2 != nil {
log.Errorf("error mounting: %s %s", err1, err2)
if fsmount != nil { if fsmount != nil {
fsmount.Unmount() fsmount.Unmount()
} }

View File

@ -21,7 +21,8 @@ import (
// batches/combines and takes all of these into consideration. // batches/combines and takes all of these into consideration.
// //
// Right now, messages go onto the network for four reasons: // Right now, messages go onto the network for four reasons:
// 1. an initial `sendwantlist` message to a provider of the first key in a request // 1. an initial `sendwantlist` message to a provider of the first key in a
// request
// 2. a periodic full sweep of `sendwantlist` messages to all providers // 2. a periodic full sweep of `sendwantlist` messages to all providers
// 3. upon receipt of blocks, a `cancel` message to all peers // 3. upon receipt of blocks, a `cancel` message to all peers
// 4. draining the priority queue of `blockrequests` from peers // 4. draining the priority queue of `blockrequests` from peers
@ -34,7 +35,8 @@ import (
// Some examples of what would be possible: // Some examples of what would be possible:
// //
// * when sending out the wantlists, include `cancel` requests // * when sending out the wantlists, include `cancel` requests
// * when handling `blockrequests`, include `sendwantlist` and `cancel` as appropriate // * when handling `blockrequests`, include `sendwantlist` and `cancel` as
// appropriate
// * when handling `cancel`, if we recently received a wanted block from a // * when handling `cancel`, if we recently received a wanted block from a
// peer, include a partial wantlist that contains a few other high priority // peer, include a partial wantlist that contains a few other high priority
// blocks // blocks

View File

@ -11,7 +11,7 @@ import (
// Any type that implements exchange.Interface may be used as an IPFS block // Any type that implements exchange.Interface may be used as an IPFS block
// exchange protocol. // exchange protocol.
type Interface interface { type Interface interface { // type Exchanger interface
// GetBlock returns the block associated with a given key. // GetBlock returns the block associated with a given key.
GetBlock(context.Context, key.Key) (*blocks.Block, error) GetBlock(context.Context, key.Key) (*blocks.Block, error)

View File

@ -406,7 +406,7 @@ _ipfs()
1) 1)
local opts="add bitswap block bootstrap cat commands config daemon dht \ local opts="add bitswap block bootstrap cat commands config daemon dht \
diag dns file get id init log ls mount name object pin ping \ diag dns file get id init log ls mount name object pin ping \
refs repo swarm tour update version" refs repo stats swarm tour update version"
COMPREPLY=( $(compgen -W "${opts}" -- ${word}) );; COMPREPLY=( $(compgen -W "${opts}" -- ${word}) );;
2) 2)
local command="${COMP_WORDS[1]}" local command="${COMP_WORDS[1]}"

View File

@ -1,5 +1,6 @@
// Package format implements a data format for files in the ipfs filesystem // Package format implements a data format for files in the ipfs filesystem It
// It is not the only format in ipfs, but it is the one that the filesystem assumes // is not the only format in ipfs, but it is the one that the filesystem
// assumes
package unixfs package unixfs
import ( import (

View File

@ -56,8 +56,8 @@ type ReadSeekCloser interface {
io.WriterTo io.WriterTo
} }
// NewDagReader creates a new reader object that reads the data represented by the given // NewDagReader creates a new reader object that reads the data represented by
// node, using the passed in DAGService for data retreival // the given node, using the passed in DAGService for data retreival
func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (*DagReader, error) { func NewDagReader(ctx context.Context, n *mdag.Node, serv mdag.DAGService) (*DagReader, error) {
pb := new(ftpb.Data) pb := new(ftpb.Data)
if err := proto.Unmarshal(n.Data, pb); err != nil { if err := proto.Unmarshal(n.Data, pb); err != nil {
@ -102,8 +102,8 @@ func NewDataFileReader(ctx context.Context, n *mdag.Node, pb *ftpb.Data, serv md
} }
} }
// precalcNextBuf follows the next link in line and loads it from the DAGService, // precalcNextBuf follows the next link in line and loads it from the
// setting the next buffer to read from // DAGService, setting the next buffer to read from
func (dr *DagReader) precalcNextBuf(ctx context.Context) error { func (dr *DagReader) precalcNextBuf(ctx context.Context) error {
dr.buf.Close() // Just to make sure dr.buf.Close() // Just to make sure
if dr.linkPosition >= len(dr.promises) { if dr.linkPosition >= len(dr.promises) {

View File

@ -1,9 +1,9 @@
// Package loggables includes a bunch of transaltor functions for commonplace/stdlib // Package loggables includes a bunch of translator functions for
// objects. This is boilerplate code that shouldn't change much, and not sprinkled // commonplace/stdlib objects. This is boilerplate code that shouldn't change
// all over the place (i.e. gather it here). // much, and not sprinkled all over the place (i.e. gather it here).
// //
// Note: it may make sense to put all stdlib Loggable functions in the eventlog // Note: it may make sense to put all stdlib Loggable functions in the eventlog
// package. Putting it here for now in case we don't want to polute it. // package. Putting it here for now in case we don't want to pollute it.
package loggables package loggables
import ( import (
@ -50,7 +50,7 @@ func Dial(sys string, lid, rid peer.ID, laddr, raddr ma.Multiaddr) DeferredMap {
return m return m
} }
// DeferredMap is a Loggable which may contained deffered values. // DeferredMap is a Loggable which may contain deferred values.
type DeferredMap map[string]interface{} type DeferredMap map[string]interface{}
// Loggable describes objects that can be marshalled into Metadata for logging // Loggable describes objects that can be marshalled into Metadata for logging