From ba2e8149c83717272513c64e1a664646d6972f77 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 23 May 2016 11:34:26 +0530 Subject: [PATCH] Ignore BucketEmpty error for top-level listing (#1727) * Ignore BucketEmpty error for top-level listing This is relevant in the case of non-fs backend like s3, play etc. * Used ToGoError() to get Error interface from *probe.Error --- ls-main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ls-main.go b/ls-main.go index e3d7a256..9a354b88 100644 --- a/ls-main.go +++ b/ls-main.go @@ -135,10 +135,16 @@ func mainList(ctx *cli.Context) { clnt, err := newClient(targetURL) fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.") - st, err := clnt.Stat() - fatalIf(err.Trace(targetURL), "Unable to stat target ‘"+targetURL+"’.") - - if st.Type.IsDir() { + var st *clientContent + if st, err = clnt.Stat(); err != nil { + switch err.ToGoError().(type) { + case BucketNameEmpty: + // For aliases like ``mc ls s3`` it's acceptable to receive BucketNameEmpty error. + // Nothing to do. + default: + fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.") + } + } else if st.Type.IsDir() { targetURL = targetURL + string(clnt.GetURL().Separator) clnt, err = newClient(targetURL) fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")