Remove leftover bits of code.
License: MIT Signed-off-by: Brendan McMillion <brendan@cloudflare.com>
Brendan McMillion committed
May 16, 2018 at 15:22 UTC
80370f068b7768d69cf2dac54ddd8ec52ad51751
4 files changed
+10
-43
cmd/ipfs/daemon.go
-4
@@ -301,10 +301,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
301
}
302
303
routingOption, _ := req.Options[routingOptionKwd].(string)
304
- if err != nil {
305
- re.SetError(err, cmdkit.ErrNormal)
306
- return
307
- }
304
if routingOption == routingOptionDefaultKwd {
305
cfg, err := repo.Config()
306
if err != nil {
cmd/ipfs/ipfs.go
-5
@@ -26,7 +26,6 @@ var localCommands = map[string]*cmds.Command{
26
"init": initCmd,
27
"commands": commandsClientCmd,
28
}
29
-var localMap = make(map[*cmds.Command]bool)
29
30
func init() {
31
// setting here instead of in literal to prevent initialization loop
@@ -38,10 +37,6 @@ func init() {
37
Root.Subcommands[k] = v
38
}
39
}
41
-
42
- for _, v := range localCommands {
43
- localMap[v] = true
44
- }
40
}
41
42
// NB: when necessary, properties are described using negatives in order to
cmd/ipfs/main.go
+8
-21
@@ -92,6 +92,7 @@ func mainRet() int {
92
os.Args[0] = "ipfs"
93
94
buildEnv := func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) {
95
+ checkDebug(req)
96
repoPath, err := getRepoPath(req)
97
if err != nil {
98
return nil, err
@@ -151,12 +152,7 @@ func checkDebug(req *cmds.Request) {
152
}
153
154
func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
154
- checkDebug(req)
155
- details, err := commandDetails(req.Path, Root)
156
- if err != nil {
157
- return nil, err
158
- }
159
-
155
+ details := commandDetails(req.Path)
156
client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context))
157
if err != nil {
158
return nil, err
@@ -200,25 +196,16 @@ func checkPermissions(path string) (bool, error) {
196
return true, nil
197
}
198
203
-// commandDetails returns a command's details for the command given by |path|
204
-// within the |root| command tree.
205
-//
206
-// Returns an error if the command is not found in the Command tree.
207
-func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) {
199
+// commandDetails returns a command's details for the command given by |path|.
200
+func commandDetails(path []string) *cmdDetails {
201
var details cmdDetails
202
// find the last command in path that has a cmdDetailsMap entry
210
- cmd := root
211
- for _, cmp := range path {
212
- cmd = cmd.Subcommands[cmp]
213
- if cmd == nil {
214
- return nil, fmt.Errorf("subcommand %s should be in root", cmp)
215
- }
216
-
217
- if cmdDetails, found := cmdDetailsMap[strings.Join(path, "/")]; found {
203
+ for i := range path {
204
+ if cmdDetails, found := cmdDetailsMap[strings.Join(path[:i+1], "/")]; found {
205
details = cmdDetails
206
}
207
}
221
- return &details, nil
208
+ return &details
209
}
210
211
// commandShouldRunOnDaemon determines, from command details, whether a
@@ -318,7 +305,7 @@ func startProfiling() (func(), error) {
305
306
stopProfiling := func() {
307
pprof.StopCPUProfile()
321
- defer ofi.Close() // captured by the closure
308
+ ofi.Close() // captured by the closure
309
}
310
return stopProfiling, nil
311
}
core/core.go
+2
-13
@@ -597,12 +597,7 @@ func (n *IpfsNode) teardown() error {
597
598
// OnlineMode returns whether or not the IpfsNode is in OnlineMode.
599
func (n *IpfsNode) OnlineMode() bool {
600
- switch n.mode {
601
- case onlineMode:
602
- return true
603
- default:
604
- return false
605
- }
600
+ return n.mode == onlineMode
601
}
602
603
// SetLocal will set the IpfsNode to local mode
@@ -619,17 +614,11 @@ func (n *IpfsNode) LocalMode() bool {
614
// programmer error should not happen
615
panic("local mode not set")
616
}
622
- switch n.mode {
623
- case localMode:
624
- return true
625
- default:
626
- return false
627
- }
617
+ return n.mode == localMode
618
}
619
620
// Bootstrap will set and call the IpfsNodes bootstrap function.
621
func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {
632
-
622
// TODO what should return value be when in offlineMode?
623
if n.Routing == nil {
624
return nil