From bec340af652f146e2ec4a7657f356ffb46f63c65 Mon Sep 17 00:00:00 2001 From: adfost Date: Mon, 14 Nov 2022 11:12:37 -0800 Subject: [PATCH] fix: 'du' clean the input path to avoid extra counting (#4361) --- cmd/du-main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/du-main.go b/cmd/du-main.go index 303f334d..73e1d84a 100644 --- a/cmd/du-main.go +++ b/cmd/du-main.go @@ -21,6 +21,7 @@ import ( "context" "fmt" "net/url" + "path" "strings" "time" @@ -122,6 +123,7 @@ func (r duMessage) JSON() string { func du(ctx context.Context, urlStr string, timeRef time.Time, withVersions bool, depth int, encKeyDB map[string][]prefixSSEPair) (sz, objs int64, err error) { targetAlias, targetURL, _ := mustExpandAlias(urlStr) + if !strings.HasSuffix(targetURL, "/") { targetURL += "/" } @@ -136,6 +138,8 @@ func du(ctx context.Context, urlStr string, timeRef time.Time, withVersions bool // just do a recursive listing recursive := depth == 1 + targetAbsolutePath := path.Clean(clnt.GetURL().String()) + contentCh := clnt.List(ctx, ListOptions{ TimeRef: timeRef, WithOlderVersions: withVersions, @@ -157,11 +161,13 @@ func du(ctx context.Context, urlStr string, timeRef time.Time, withVersions bool errorIf(content.Err.Trace(urlStr), "Failed to find disk usage of `"+urlStr+"` recursively.") return 0, 0, exitStatus(globalErrorExitStatus) } - if content.URL.String() == targetURL { + + if content.URL.Path == targetAbsolutePath { continue } if content.Type.IsDir() && !recursive { + depth := depth if depth > 0 { depth--