fix: 'du' clean the input path to avoid extra counting (#4361)

This commit is contained in:
adfost
2022-11-14 11:12:37 -08:00
committed by GitHub
parent 7cde242709
commit bec340af65
+7 -1
View File
@@ -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--