From e3febd2a4165dc9a284168efd6e6d09bf43b5a96 Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Tue, 24 Sep 2024 16:33:03 -0400 Subject: [PATCH] CLI: when 'ls bucket/objname' becomes 'ls bucket --prefix objname' Signed-off-by: Alex Aizman --- api/bucket.go | 5 +++-- cmd/cli/cli/bucket_hdlr.go | 5 ++++- cmd/cli/cli/object.go | 15 ++++++++------- cmd/cli/cli/show_hdlr.go | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/bucket.go b/api/bucket.go index cf3740b4c5..7fdb8ba06c 100644 --- a/api/bucket.go +++ b/api/bucket.go @@ -12,7 +12,6 @@ import ( "github.com/NVIDIA/aistore/api/apc" "github.com/NVIDIA/aistore/cmn" "github.com/NVIDIA/aistore/cmn/cos" - "github.com/NVIDIA/aistore/cmn/debug" jsoniter "github.com/json-iterator/go" ) @@ -92,7 +91,9 @@ func hdr2msg(bck cmn.Bck, status int, err error) error { if !ok { return err } - debug.Assert(herr.Status == status, herr.Status, " vs ", status) + if status == 0 && herr.Status != 0 { // (connection refused) + return err + } quoted := "\"" + bck.Cname("") + "\"" if !bck.IsQuery() && status == http.StatusNotFound { diff --git a/cmd/cli/cli/bucket_hdlr.go b/cmd/cli/cli/bucket_hdlr.go index 347d7eeae8..b0f4edfc8c 100644 --- a/cmd/cli/cli/bucket_hdlr.go +++ b/cmd/cli/cli/bucket_hdlr.go @@ -617,12 +617,15 @@ func listAnyHandler(c *cli.Context) error { if _, err := headBucket(bck, true /* don't add */); err != nil { return err } - err := showObjProps(c, bck, objName) + notfound, err := showObjProps(c, bck, objName) if err == nil { if _, errV := archive.Mime("", objName); errV == nil { fmt.Fprintf(c.App.Writer, "\n('ais ls %s %s' to list archived contents, %s for details)\n", bck.Cname(objName), flprn(listArchFlag), qflprn(cli.HelpFlag)) } + } else if notfound { + prefix := objName + err = listObjects(c, bck, prefix, false) } return err case bck.Name == "" || flagIsSet(c, bckSummaryFlag): // list or summarize bucket(s) diff --git a/cmd/cli/cli/object.go b/cmd/cli/cli/object.go index 5f12f2b056..4b17eaa426 100644 --- a/cmd/cli/cli/object.go +++ b/cmd/cli/cli/object.go @@ -252,7 +252,7 @@ func calcPutRefresh(c *cli.Context) time.Duration { } // via `ais ls bucket/object` and `ais show bucket/object` -func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error { +func showObjProps(c *cli.Context, bck cmn.Bck, objName string) (notfound bool, _ error) { var ( propsFlag []string selectedProps []string @@ -263,15 +263,16 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error { units, errU = parseUnitsFlag(c, unitsFlag) ) if errU != nil { - return errU + return false, errU } if flagIsSet(c, objNotCachedPropsFlag) || flagIsSet(c, allObjsOrBcksFlag) { hargs.FltPresence = apc.FltExists } objProps, err := api.HeadObject(apiBP, bck, objName, hargs) if err != nil { - if !cmn.IsStatusNotFound(err) { - return err + notfound = cmn.IsStatusNotFound(err) + if !notfound { + return notfound, err } var hint string if apc.IsFltPresent(hargs.FltPresence) && bck.IsRemote() { @@ -281,7 +282,7 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error { hint = fmt.Sprintf(" (tip: try %s option)", qflprn(objNotCachedPropsFlag)) } } - return fmt.Errorf("%q not found in %s%s", objName, bck.Cname(""), hint) + return notfound, fmt.Errorf("%q not found in %s%s", objName, bck.Cname(""), hint) } if flagIsSet(c, allPropsFlag) { @@ -329,9 +330,9 @@ func showObjProps(c *cli.Context, bck cmn.Bck, objName string) error { }) if flagIsSet(c, noHeaderFlag) { - return teb.Print(propNVs, teb.PropValTmplNoHdr) + return false, teb.Print(propNVs, teb.PropValTmplNoHdr) } - return teb.Print(propNVs, teb.PropValTmpl) + return false, teb.Print(propNVs, teb.PropValTmpl) } func propVal(op *cmn.ObjectProps, name string) (v string) { diff --git a/cmd/cli/cli/show_hdlr.go b/cmd/cli/cli/show_hdlr.go index 65882a4dfc..e7c3416cf8 100644 --- a/cmd/cli/cli/show_hdlr.go +++ b/cmd/cli/cli/show_hdlr.go @@ -580,7 +580,8 @@ func showObjectHandler(c *cli.Context) error { if _, err := headBucket(bck, true /* don't add */); err != nil { return err } - return showObjProps(c, bck, object) + _, err = showObjProps(c, bck, object) + return err } func showBckPropsHandler(c *cli.Context) error {