diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index c5e2b244b..29d2f2053 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -18,7 +18,6 @@ import ( corehttp "github.com/ipfs/go-ipfs/core/corehttp" corerepo "github.com/ipfs/go-ipfs/core/corerepo" nodeMount "github.com/ipfs/go-ipfs/fuse/node" - //config "github.com/ipfs/go-ipfs/repo/config" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations" @@ -200,7 +199,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { } } - ctx := env.(*oldcmds.Context) + cctx := env.(*oldcmds.Context) go func() { <-req.Context.Done() @@ -219,10 +218,9 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { // first, whether user has provided the initialization flag. we may be // running in an uninitialized state. initialize, _ := req.Options[initOptionKwd].(bool) - if initialize { - cfg := ctx.ConfigRoot + cfg := cctx.ConfigRoot if !fsrepo.IsInitialized(cfg) { err := initWithDefaults(os.Stdout, cfg) if err != nil { @@ -234,7 +232,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { // acquire the repo lock _before_ constructing a node. we need to make // sure we are permitted to access the resources (datastore, etc.) - repo, err := fsrepo.Open(ctx.ConfigRoot) + repo, err := fsrepo.Open(cctx.ConfigRoot) switch err { default: re.SetError(err, cmdkit.ErrNormal) @@ -264,7 +262,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { return } - repo, err = fsrepo.Open(ctx.ConfigRoot) + repo, err = fsrepo.Open(cctx.ConfigRoot) if err != nil { re.SetError(err, cmdkit.ErrNormal) return @@ -273,7 +271,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { break } - cfg, err := ctx.GetConfig() + cfg, err := cctx.GetConfig() if err != nil { re.SetError(err, cmdkit.ErrNormal) return @@ -340,12 +338,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { } }() - ctx.ConstructNode = func() (*core.IpfsNode, error) { + cctx.ConstructNode = func() (*core.IpfsNode, error) { return node, nil } // construct api endpoint - every time - err, apiErrc := serveHTTPApi(req, ctx) + err, apiErrc := serveHTTPApi(req, cctx) if err != nil { re.SetError(err, cmdkit.ErrNormal) return @@ -359,7 +357,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { return } if mount { - if err := mountFuse(req, ctx); err != nil { + if err := mountFuse(req, cctx); err != nil { re.SetError(err, cmdkit.ErrNormal) return } @@ -376,7 +374,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) { var gwErrc <-chan error if len(cfg.Addresses.Gateway) > 0 { var err error - err, gwErrc = serveHTTPGateway(req, ctx) + err, gwErrc = serveHTTPGateway(req, cctx) if err != nil { re.SetError(err, cmdkit.ErrNormal) return diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 63b713309..e6dd46e58 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -108,11 +108,8 @@ func mainRet() int { } log.Debugf("config path is %s", repoPath) - // this sets up the function that will initialize the config lazily. - // this sets up the function that will initialize the node // this is so that we can construct the node lazily. - return &oldcmds.Context{ ConfigRoot: repoPath, LoadConfig: loadConfig, diff --git a/commands/legacy/legacy.go b/commands/legacy/legacy.go index 828004669..61db54dcf 100644 --- a/commands/legacy/legacy.go +++ b/commands/legacy/legacy.go @@ -53,29 +53,3 @@ func OldContext(env interface{}) *oldcmds.Context { return ctx } - -/* -// OldReqLog returns an oldcmds.ReqLog from a ReqLog -func OldReqLog(newrl *ReqLog) *oldcmds.ReqLog { - if newrl == nil { - return nil - } - - rl := &oldcmds.ReqLog{} - - for _, rle := range newrl.Requests { - oldrle := &oldcmds.ReqLogEntry{ - StartTime: rle.StartTime, - EndTime: rle.EndTime, - Active: rle.Active, - Command: rle.Command, - Options: rle.Options, - Args: rle.Args, - ID: rle.ID, - } - rl.AddEntry(oldrle) - } - - return rl -} -*/ diff --git a/commands/legacy/legacy_test.go b/commands/legacy/legacy_test.go index 28f61791f..30e79f148 100644 --- a/commands/legacy/legacy_test.go +++ b/commands/legacy/legacy_test.go @@ -184,32 +184,3 @@ func TestTeeEmitter(t *testing.T) { t.Fatal("expected %#v, got %#v", expect, buf2.String()) } } - -/* -type teeErrorTestCase struct { - err1, err2 error - bothNil bool - errString string -} - -func TestTeeError(t *testing.T) { - tcs := []teeErrorTestCase{ - teeErrorTestCase{nil, nil, true, ""}, - teeErrorTestCase{fmt.Errorf("error!"), nil, false, "1: error!"}, - teeErrorTestCase{nil, fmt.Errorf("error!"), false, "2: error!"}, - teeErrorTestCase{fmt.Errorf("error!"), fmt.Errorf("error!"), false, `1: error! -2: error!`}, - } - - for i, tc := range tcs { - teeError := cmds.TeeError{tc.err1, tc.err2} - if teeError.BothNil() != tc.bothNil { - t.Fatalf("BothNil()/%d: expected %v but got %v", i, tc.bothNil, teeError.BothNil()) - } - - if teeError.Error() != tc.errString { - t.Fatalf("Error()/%d: expected %v but got %v", i, tc.errString, teeError.Error()) - } - } -} -*/ diff --git a/commands/request.go b/commands/request.go index 5c26a5e8b..f0dd2b10e 100644 --- a/commands/request.go +++ b/commands/request.go @@ -76,6 +76,9 @@ func (c *Context) RootContext() context.Context { return n.Context() } +// LogRequest adds the passed request to the request log and +// returns a function that should be called when the request +// lifetime is over. func (c *Context) LogRequest(req *cmds.Request) func() { rle := &ReqLogEntry{ StartTime: time.Now(), @@ -93,6 +96,7 @@ func (c *Context) LogRequest(req *cmds.Request) func() { } } +// Close cleans up the application state. func (c *Context) Close() { // let's not forget teardown. If a node was initialized, we must close it. // Note that this means the underlying req.Context().Node variable is exposed. diff --git a/core/commands/add.go b/core/commands/add.go index 69d494ada..0c66cc0fa 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -145,6 +145,7 @@ You can now check what blocks have been created by: return nil } + // HACK! Using context to pass the size to PostRun sizeCh := make(chan int64, 1) req.Context = context.WithValue(req.Context, "size", sizeCh) @@ -366,6 +367,7 @@ You can now check what blocks have been created by: bar.Start() } + // HACK! using context to pass size from PreRun var sizeChan chan int64 sizeChan, _ = req.Context.Value("size").(chan int64) @@ -429,7 +431,7 @@ You can now check what blocks have been created by: bar.ShowTimeLeft = true } case <-req.Context.Done(): - //re.SetError(req.Context.Err(), cmdkit.ErrNormal) + // don't set or print error here, that happens in the goroutine below return } } diff --git a/core/commands/cat.go b/core/commands/cat.go index c949ef827..1034f7924 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -62,7 +62,7 @@ var CatCmd = &cmds.Command{ } err = req.ParseBodyArgs() - if err != nil && err.Error() != "all arguments covered by positional arguments" { + if err != nil && !cmds.IsAllArgsAlreadyCovered(err) { res.SetError(err, cmdkit.ErrNormal) return } diff --git a/core/commands/commands.go b/core/commands/commands.go index 4fa546742..bec5eca0f 100644 --- a/core/commands/commands.go +++ b/core/commands/commands.go @@ -11,7 +11,6 @@ import ( "sort" "strings" - // oldcmds "github.com/ipfs/go-ipfs/commands" e "github.com/ipfs/go-ipfs/core/commands/e" "gx/ipfs/QmSRaAPPNxyhnXeDa5NXtZ2CWBYJ6BRWNQp6gKxhPcoqDM/go-ipfs-cmdkit" diff --git a/core/commands/get_test.go b/core/commands/get_test.go index 7672a7fdc..7850bfa69 100644 --- a/core/commands/get_test.go +++ b/core/commands/get_test.go @@ -45,12 +45,10 @@ func TestGetOutputPath(t *testing.T) { }, } - /* - defOpts, err := GetCmd.GetOptions([]string{}) - if err != nil { - t.Fatalf("error getting default command options: %v", err) - } - */ + _, err := GetCmd.GetOptions([]string{}) + if err != nil { + t.Fatalf("error getting default command options: %v", err) + } for _, tc := range cases { req, err := cmds.NewRequest(context.TODO(), []string{}, tc.opts, tc.args, nil, GetCmd) diff --git a/test/sharness/t0110-gateway.sh b/test/sharness/t0110-gateway.sh index fa37c5b21..c5a4aa39c 100755 --- a/test/sharness/t0110-gateway.sh +++ b/test/sharness/t0110-gateway.sh @@ -135,7 +135,7 @@ test_expect_success "get IPFS directory file through readonly API output looks g test_cmp dir/test actual ' -test_expect_failure "refs IPFS directory file through readonly API succeeds" ' +test_expect_success "refs IPFS directory file through readonly API succeeds" ' test_curl_gateway_api "refs?arg=$HASH2/test" '