Skip to content

Commit

Permalink
Merge pull request #5022 from Bren2010/review/cmd/ipfs
Browse files Browse the repository at this point in the history
Remove leftover bits of code.
  • Loading branch information
whyrusleeping committed May 28, 2018
2 parents 2ba7179 + 80370f0 commit 611d572
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 43 deletions.
4 changes: 0 additions & 4 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions cmd/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
29 changes: 8 additions & 21 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 2 additions & 13 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 611d572

Please sign in to comment.