cleanup
License: MIT Signed-off-by: keks <keks@cryptoscope.co>
keks committed
Dec 20, 2017 at 13:19 UTC
8f24d8e211c90ad41784f4f4853f32b8d8dee218
10 files changed
+22
-79
cmd/ipfs/daemon.go
+9
-11
@@ -18,7 +18,6 @@ import (
18
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
19
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
20
nodeMount "github.com/ipfs/go-ipfs/fuse/node"
21
- //config "github.com/ipfs/go-ipfs/repo/config"
21
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
22
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
23
@@ -200,7 +199,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
199
}
200
}
201
203
- ctx := env.(*oldcmds.Context)
202
+ cctx := env.(*oldcmds.Context)
203
204
go func() {
205
<-req.Context.Done()
@@ -219,10 +218,9 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
218
// first, whether user has provided the initialization flag. we may be
219
// running in an uninitialized state.
220
initialize, _ := req.Options[initOptionKwd].(bool)
222
-
221
if initialize {
222
225
- cfg := ctx.ConfigRoot
223
+ cfg := cctx.ConfigRoot
224
if !fsrepo.IsInitialized(cfg) {
225
err := initWithDefaults(os.Stdout, cfg)
226
if err != nil {
@@ -234,7 +232,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
232
233
// acquire the repo lock _before_ constructing a node. we need to make
234
// sure we are permitted to access the resources (datastore, etc.)
237
- repo, err := fsrepo.Open(ctx.ConfigRoot)
235
+ repo, err := fsrepo.Open(cctx.ConfigRoot)
236
switch err {
237
default:
238
re.SetError(err, cmdkit.ErrNormal)
@@ -264,7 +262,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
262
return
263
}
264
267
- repo, err = fsrepo.Open(ctx.ConfigRoot)
265
+ repo, err = fsrepo.Open(cctx.ConfigRoot)
266
if err != nil {
267
re.SetError(err, cmdkit.ErrNormal)
268
return
@@ -273,7 +271,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
271
break
272
}
273
276
- cfg, err := ctx.GetConfig()
274
+ cfg, err := cctx.GetConfig()
275
if err != nil {
276
re.SetError(err, cmdkit.ErrNormal)
277
return
@@ -340,12 +338,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
338
}
339
}()
340
343
- ctx.ConstructNode = func() (*core.IpfsNode, error) {
341
+ cctx.ConstructNode = func() (*core.IpfsNode, error) {
342
return node, nil
343
}
344
345
// construct api endpoint - every time
348
- err, apiErrc := serveHTTPApi(req, ctx)
346
+ err, apiErrc := serveHTTPApi(req, cctx)
347
if err != nil {
348
re.SetError(err, cmdkit.ErrNormal)
349
return
@@ -359,7 +357,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
357
return
358
}
359
if mount {
362
- if err := mountFuse(req, ctx); err != nil {
360
+ if err := mountFuse(req, cctx); err != nil {
361
re.SetError(err, cmdkit.ErrNormal)
362
return
363
}
@@ -376,7 +374,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
374
var gwErrc <-chan error
375
if len(cfg.Addresses.Gateway) > 0 {
376
var err error
379
- err, gwErrc = serveHTTPGateway(req, ctx)
377
+ err, gwErrc = serveHTTPGateway(req, cctx)
378
if err != nil {
379
re.SetError(err, cmdkit.ErrNormal)
380
return
cmd/ipfs/main.go
-3
@@ -108,11 +108,8 @@ func mainRet() int {
108
}
109
log.Debugf("config path is %s", repoPath)
110
111
- // this sets up the function that will initialize the config lazily.
112
-
111
// this sets up the function that will initialize the node
112
// this is so that we can construct the node lazily.
115
-
113
return &oldcmds.Context{
114
ConfigRoot: repoPath,
115
LoadConfig: loadConfig,
commands/legacy/legacy.go
-26
@@ -53,29 +53,3 @@ func OldContext(env interface{}) *oldcmds.Context {
53
54
return ctx
55
}
56
-
57
-/*
58
-// OldReqLog returns an oldcmds.ReqLog from a ReqLog
59
-func OldReqLog(newrl *ReqLog) *oldcmds.ReqLog {
60
- if newrl == nil {
61
- return nil
62
- }
63
-
64
- rl := &oldcmds.ReqLog{}
65
-
66
- for _, rle := range newrl.Requests {
67
- oldrle := &oldcmds.ReqLogEntry{
68
- StartTime: rle.StartTime,
69
- EndTime: rle.EndTime,
70
- Active: rle.Active,
71
- Command: rle.Command,
72
- Options: rle.Options,
73
- Args: rle.Args,
74
- ID: rle.ID,
75
- }
76
- rl.AddEntry(oldrle)
77
- }
78
-
79
- return rl
80
-}
81
-*/
commands/legacy/legacy_test.go
-29
@@ -184,32 +184,3 @@ func TestTeeEmitter(t *testing.T) {
184
t.Fatal("expected %#v, got %#v", expect, buf2.String())
185
}
186
}
187
-
188
-/*
189
-type teeErrorTestCase struct {
190
- err1, err2 error
191
- bothNil bool
192
- errString string
193
-}
194
-
195
-func TestTeeError(t *testing.T) {
196
- tcs := []teeErrorTestCase{
197
- teeErrorTestCase{nil, nil, true, ""},
198
- teeErrorTestCase{fmt.Errorf("error!"), nil, false, "1: error!"},
199
- teeErrorTestCase{nil, fmt.Errorf("error!"), false, "2: error!"},
200
- teeErrorTestCase{fmt.Errorf("error!"), fmt.Errorf("error!"), false, `1: error!
201
-2: error!`},
202
- }
203
-
204
- for i, tc := range tcs {
205
- teeError := cmds.TeeError{tc.err1, tc.err2}
206
- if teeError.BothNil() != tc.bothNil {
207
- t.Fatalf("BothNil()/%d: expected %v but got %v", i, tc.bothNil, teeError.BothNil())
208
- }
209
-
210
- if teeError.Error() != tc.errString {
211
- t.Fatalf("Error()/%d: expected %v but got %v", i, tc.errString, teeError.Error())
212
- }
213
- }
214
-}
215
-*/
commands/request.go
+4
@@ -76,6 +76,9 @@ func (c *Context) RootContext() context.Context {
76
return n.Context()
77
}
78
79
+// LogRequest adds the passed request to the request log and
80
+// returns a function that should be called when the request
81
+// lifetime is over.
82
func (c *Context) LogRequest(req *cmds.Request) func() {
83
rle := &ReqLogEntry{
84
StartTime: time.Now(),
@@ -93,6 +96,7 @@ func (c *Context) LogRequest(req *cmds.Request) func() {
96
}
97
}
98
99
+// Close cleans up the application state.
100
func (c *Context) Close() {
101
// let's not forget teardown. If a node was initialized, we must close it.
102
// Note that this means the underlying req.Context().Node variable is exposed.
core/commands/add.go
+3
-1
@@ -145,6 +145,7 @@ You can now check what blocks have been created by:
145
return nil
146
}
147
148
+ // HACK! Using context to pass the size to PostRun
149
sizeCh := make(chan int64, 1)
150
req.Context = context.WithValue(req.Context, "size", sizeCh)
151
@@ -366,6 +367,7 @@ You can now check what blocks have been created by:
367
bar.Start()
368
}
369
370
+ // HACK! using context to pass size from PreRun
371
var sizeChan chan int64
372
sizeChan, _ = req.Context.Value("size").(chan int64)
373
@@ -429,7 +431,7 @@ You can now check what blocks have been created by:
431
bar.ShowTimeLeft = true
432
}
433
case <-req.Context.Done():
432
- //re.SetError(req.Context.Err(), cmdkit.ErrNormal)
434
+ // don't set or print error here, that happens in the goroutine below
435
return
436
}
437
}
core/commands/cat.go
+1
-1
@@ -62,7 +62,7 @@ var CatCmd = &cmds.Command{
62
}
63
64
err = req.ParseBodyArgs()
65
- if err != nil && err.Error() != "all arguments covered by positional arguments" {
65
+ if err != nil && !cmds.IsAllArgsAlreadyCovered(err) {
66
res.SetError(err, cmdkit.ErrNormal)
67
return
68
}
core/commands/commands.go
-1
@@ -11,7 +11,6 @@ import (
11
"sort"
12
"strings"
13
14
- // oldcmds "github.com/ipfs/go-ipfs/commands"
14
e "github.com/ipfs/go-ipfs/core/commands/e"
15
16
"gx/ipfs/QmSRaAPPNxyhnXeDa5NXtZ2CWBYJ6BRWNQp6gKxhPcoqDM/go-ipfs-cmdkit"
core/commands/get_test.go
+4
-6
@@ -45,12 +45,10 @@ func TestGetOutputPath(t *testing.T) {
45
},
46
}
47
48
- /*
49
- defOpts, err := GetCmd.GetOptions([]string{})
50
- if err != nil {
51
- t.Fatalf("error getting default command options: %v", err)
52
- }
53
- */
48
+ _, err := GetCmd.GetOptions([]string{})
49
+ if err != nil {
50
+ t.Fatalf("error getting default command options: %v", err)
51
+ }
52
53
for _, tc := range cases {
54
req, err := cmds.NewRequest(context.TODO(), []string{}, tc.opts, tc.args, nil, GetCmd)
test/sharness/t0110-gateway.sh
+1
-1
@@ -135,7 +135,7 @@ test_expect_success "get IPFS directory file through readonly API output looks g
135
test_cmp dir/test actual
136
'
137
138
-test_expect_failure "refs IPFS directory file through readonly API succeeds" '
138
+test_expect_success "refs IPFS directory file through readonly API succeeds" '
139
test_curl_gateway_api "refs?arg=$HASH2/test"
140
'
141