supply prefix filtering when necessary (#14772)

currently filterPefix was never used and set
that would filter out entries when needed
when `prefix` doesn't end with `/` - this
often leads to objects getting Walked(), Healed()
that were never requested by the caller.
This commit is contained in:
Harshavardhana 2022-04-19 08:20:48 -07:00 committed by GitHub
parent 4685b76e08
commit 598ce1e354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
@ -1723,14 +1724,16 @@ func (z *erasureServerPools) Walk(ctx context.Context, bucket, prefix string, re
} }
path := baseDirFromPrefix(prefix) path := baseDirFromPrefix(prefix)
if path == "" { filterPrefix := strings.Trim(strings.TrimPrefix(prefix, path), slashSeparator)
path = prefix if path == prefix {
filterPrefix = ""
} }
lopts := listPathRawOptions{ lopts := listPathRawOptions{
disks: disks, disks: disks,
bucket: bucket, bucket: bucket,
path: path, path: path,
filterPrefix: filterPrefix,
recursive: true, recursive: true,
forwardTo: "", forwardTo: "",
minDisks: 1, minDisks: 1,
@ -1783,14 +1786,16 @@ func listAndHeal(ctx context.Context, bucket, prefix string, set *erasureObjects
} }
path := baseDirFromPrefix(prefix) path := baseDirFromPrefix(prefix)
if path == "" { filterPrefix := strings.Trim(strings.TrimPrefix(prefix, path), slashSeparator)
path = prefix if path == prefix {
filterPrefix = ""
} }
lopts := listPathRawOptions{ lopts := listPathRawOptions{
disks: disks, disks: disks,
bucket: bucket, bucket: bucket,
path: path, path: path,
filterPrefix: filterPrefix,
recursive: true, recursive: true,
forwardTo: "", forwardTo: "",
minDisks: 1, minDisks: 1,