mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
cleanup
License: MIT Signed-off-by: keks <keks@cryptoscope.co>
This commit is contained in:
parent
7b1963906b
commit
8f24d8e211
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
}
|
||||
*/
|
||||
|
||||
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
'
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user