diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 71a7657f2..be982604a 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -301,10 +301,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment } routingOption, _ := req.Options[routingOptionKwd].(string) - if err != nil { - re.SetError(err, cmdkit.ErrNormal) - return - } if routingOption == routingOptionDefaultKwd { cfg, err := repo.Config() if err != nil { diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index 87ec2884b..51590072b 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -26,7 +26,6 @@ var localCommands = map[string]*cmds.Command{ "init": initCmd, "commands": commandsClientCmd, } -var localMap = make(map[*cmds.Command]bool) func init() { // setting here instead of in literal to prevent initialization loop @@ -38,10 +37,6 @@ func init() { Root.Subcommands[k] = v } } - - for _, v := range localCommands { - localMap[v] = true - } } // NB: when necessary, properties are described using negatives in order to diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 78db6c339..54fe2ebb2 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -92,6 +92,7 @@ func mainRet() int { os.Args[0] = "ipfs" buildEnv := func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) { + checkDebug(req) repoPath, err := getRepoPath(req) if err != nil { return nil, err @@ -151,12 +152,7 @@ func checkDebug(req *cmds.Request) { } func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) { - checkDebug(req) - details, err := commandDetails(req.Path, Root) - if err != nil { - return nil, err - } - + details := commandDetails(req.Path) client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context)) if err != nil { return nil, err @@ -200,25 +196,16 @@ func checkPermissions(path string) (bool, error) { return true, nil } -// commandDetails returns a command's details for the command given by |path| -// within the |root| command tree. -// -// Returns an error if the command is not found in the Command tree. -func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) { +// commandDetails returns a command's details for the command given by |path|. +func commandDetails(path []string) *cmdDetails { var details cmdDetails // find the last command in path that has a cmdDetailsMap entry - cmd := root - for _, cmp := range path { - cmd = cmd.Subcommands[cmp] - if cmd == nil { - return nil, fmt.Errorf("subcommand %s should be in root", cmp) - } - - if cmdDetails, found := cmdDetailsMap[strings.Join(path, "/")]; found { + for i := range path { + if cmdDetails, found := cmdDetailsMap[strings.Join(path[:i+1], "/")]; found { details = cmdDetails } } - return &details, nil + return &details } // commandShouldRunOnDaemon determines, from command details, whether a @@ -318,7 +305,7 @@ func startProfiling() (func(), error) { stopProfiling := func() { pprof.StopCPUProfile() - defer ofi.Close() // captured by the closure + ofi.Close() // captured by the closure } return stopProfiling, nil } diff --git a/core/core.go b/core/core.go index fa6b273f2..b3d3bc659 100644 --- a/core/core.go +++ b/core/core.go @@ -597,12 +597,7 @@ func (n *IpfsNode) teardown() error { // OnlineMode returns whether or not the IpfsNode is in OnlineMode. func (n *IpfsNode) OnlineMode() bool { - switch n.mode { - case onlineMode: - return true - default: - return false - } + return n.mode == onlineMode } // SetLocal will set the IpfsNode to local mode @@ -619,17 +614,11 @@ func (n *IpfsNode) LocalMode() bool { // programmer error should not happen panic("local mode not set") } - switch n.mode { - case localMode: - return true - default: - return false - } + return n.mode == localMode } // Bootstrap will set and call the IpfsNodes bootstrap function. func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error { - // TODO what should return value be when in offlineMode? if n.Routing == nil { return nil