Listing: Do not include marker in CommonPrefixes (#12021) (#12897)

Walk() and Merge code can return dir__XLDIR__ as the last element 
on a page list and dir__XLDIR__ as the first element in the next list page.

dir__XLDIR__ is shown in the second-page list because the marker set to
dir/ is meant to skip dir/ and not dir__XLDIR__

To fix this, the code will avoid adding the marker itself to the listing
result.
This commit is contained in:
Anis Elleuch 2021-08-06 14:35:11 +01:00 committed by Harshavardhana
parent 5df7bbf9f9
commit 851f3c5f0c

View File

@ -913,6 +913,12 @@ func (z *erasureServerSets) listObjects(ctx context.Context, bucket, prefix, mar
for _, entry := range entries.Files { for _, entry := range entries.Files {
objInfo := entry.ToObjectInfo(entry.Volume, entry.Name) objInfo := entry.ToObjectInfo(entry.Volume, entry.Name)
// Always avoid including the marker in the result, this is
// needed to avoid including dir__XLDIR__ and dir/ twice in
// different listing pages
if objInfo.Name == marker {
continue
}
if HasSuffix(objInfo.Name, SlashSeparator) && !recursive { if HasSuffix(objInfo.Name, SlashSeparator) && !recursive {
loi.Prefixes = append(loi.Prefixes, objInfo.Name) loi.Prefixes = append(loi.Prefixes, objInfo.Name)
continue continue
@ -1324,6 +1330,12 @@ func (z *erasureServerSets) listObjectVersions(ctx context.Context, bucket, pref
for _, entry := range entries.FilesVersions { for _, entry := range entries.FilesVersions {
for _, version := range entry.Versions { for _, version := range entry.Versions {
objInfo := version.ToObjectInfo(bucket, entry.Name) objInfo := version.ToObjectInfo(bucket, entry.Name)
// Always avoid including the marker in the result, this is
// needed to avoid including dir__XLDIR__ and dir/ twice in
// different listing pages
if objInfo.Name == marker && objInfo.VersionID == versionMarker {
continue
}
if HasSuffix(objInfo.Name, SlashSeparator) && !recursive { if HasSuffix(objInfo.Name, SlashSeparator) && !recursive {
loi.Prefixes = append(loi.Prefixes, objInfo.Name) loi.Prefixes = append(loi.Prefixes, objInfo.Name)
continue continue