diff --git a/cli/parse.go b/cli/parse.go index 9f5d1174..f61dc192 100644 --- a/cli/parse.go +++ b/cli/parse.go @@ -10,11 +10,10 @@ import ( "sort" "strings" - "github.com/ipfs/go-ipfs-cmds" - osh "github.com/Kubuxu/go-os-helper" "github.com/ipfs/go-ipfs-cmdkit" "github.com/ipfs/go-ipfs-cmdkit/files" + "github.com/ipfs/go-ipfs-cmds" logging "github.com/ipfs/go-log" ) @@ -79,9 +78,9 @@ func isRecursive(req *cmds.Request) bool { return rec && ok } -func derefLinks(req *cmds.Request) bool { - linkOpt, ok := req.Options[cmds.DerefLong].(bool) - return linkOpt && ok +func linkResolveDepth(req *cmds.Request) int { + linkOpt, _ := req.Options[cmds.DerefLong].(int) //TODO: safety concern + return linkOpt } type parseState struct { @@ -270,7 +269,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error { fpath = stdin.Name() file = files.NewReaderFile("", fpath, r, nil) } else { - nf, err := appendFile(fpath, argDef, isRecursive(req), isHidden(req), derefLinks(req)) + nf, err := appendFile(fpath, argDef, isRecursive(req), isHidden(req), linkResolveDepth(req)) if err != nil { return err } @@ -460,7 +459,7 @@ func getArgDef(i int, argDefs []cmdkit.Argument) *cmdkit.Argument { const notRecursiveFmtStr = "'%s' is a directory, use the '-%s' flag to specify directories" const dirNotSupportedFmtStr = "Invalid path '%s', argument '%s' does not support directories" -func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden, derefLinks bool) (files.File, error) { +func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden bool, resolveDepth int) (files.File, error) { if fpath == "." { cwd, err := os.Getwd() if err != nil { @@ -475,16 +474,7 @@ func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden, derefL fpath = filepath.ToSlash(filepath.Clean(fpath)) - var ( - stat os.FileInfo - err error - ) - if derefLinks { - stat, err = os.Stat(fpath) - fmt.Printf("DBG appendFile stat: %#v\n", stat) - } else { - stat, err = os.Lstat(fpath) - } + stat, err := os.Lstat(fpath) if err != nil { return nil, err } @@ -498,7 +488,7 @@ func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden, derefL } } - return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat) + return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat, resolveDepth) } // Inform the user if a file is waiting on input diff --git a/cli/run.go b/cli/run.go index 7f615f62..3b532c6c 100644 --- a/cli/run.go +++ b/cli/run.go @@ -39,7 +39,6 @@ func Run(ctx context.Context, root *cmds.Command, if timeoutStr, ok := req.Options[cmds.TimeoutOpt]; ok { timeout, err := time.ParseDuration(timeoutStr.(string)) if err != nil { - printErr(err) return err } req.Context, cancel = context.WithTimeout(req.Context, timeout) diff --git a/http/handler.go b/http/handler.go index 2f6a3188..85e031ec 100644 --- a/http/handler.go +++ b/http/handler.go @@ -2,8 +2,6 @@ package http import ( "context" - "crypto/rand" - "encoding/base32" "errors" "net/http" "runtime/debug" @@ -12,6 +10,7 @@ import ( cmds "github.com/ipfs/go-ipfs-cmds" logging "github.com/ipfs/go-log" + "github.com/libp2p/go-libp2p-loggables" cors "github.com/rs/cors" ) @@ -133,7 +132,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } defer cancel() - req.Context = logging.ContextWithLoggable(req.Context, uuidLoggable()) + req.Context = logging.ContextWithLoggable(req.Context, loggables.Uuid("requestId")) if cn, ok := w.(http.CloseNotifier); ok { clientGone := cn.CloseNotify() go func() { @@ -161,15 +160,6 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.root.Call(req, re, h.env) } -func uuidLoggable() logging.Loggable { - ids := make([]byte, 16) - rand.Read(ids) - - return logging.Metadata{ - "requestId": base32.HexEncoding.EncodeToString(ids), - } -} - func sanitizedErrStr(err error) string { s := err.Error() s = strings.Split(s, "\n")[0] diff --git a/http/parse.go b/http/parse.go index b2441275..c07a597b 100644 --- a/http/parse.go +++ b/http/parse.go @@ -210,8 +210,6 @@ func parseResponse(httpRes *http.Response, req *cmds.Request) (cmds.Response, er } e.Message = string(mes) e.Code = cmdkit.ErrNormal - case res.dec == nil: - return nil, fmt.Errorf("unknown error content type: %s", contentType) default: // handle marshalled errors err := res.dec.Decode(&e) diff --git a/http/parse_test.go b/http/parse_test.go index a3742a50..c6ae68b8 100644 --- a/http/parse_test.go +++ b/http/parse_test.go @@ -2,7 +2,6 @@ package http import ( "bytes" - "fmt" "io" "net/http" "net/url" @@ -198,15 +197,6 @@ func TestParseResponse(t *testing.T) { }, }, }, - { - status: 500, - header: http.Header{ - contentTypeHeader: []string{"evil/bad"}, - channelHeader: []string{"1"}, - }, - body: mkbuf("test error"), - err: fmt.Errorf("unknown error content type: %s", "evil/bad"), - }, } for _, tc := range tcs { diff --git a/opts.go b/opts.go index 02174fe5..36b5e1ed 100644 --- a/opts.go +++ b/opts.go @@ -23,4 +23,4 @@ var OptionEncodingType = cmdkit.StringOption(EncLong, EncShort, "The encoding ty var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory paths recursively").WithDefault(false) var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output") var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "Set a global timeout on the command") -var OptionDerefArgs = cmdkit.BoolOption(DerefLong, "Resolve argument symlinks instead of adding them as-is").WithDefault(false) +var OptionDerefArgs = cmdkit.IntOption(DerefLong, "Resolve symlinks instead of adding them as-is").WithDefault(1)