xl: Dedup common prefixes entries (#11426)

Since the support of empty directory __XLDIR__, the walk code in listing
can return two duplicated entries, one as a real diretory, the second as
the empty object with a trailing slash.

The fix deduplicates entries in CommonPrefixes when that happens.
This commit is contained in:
Anis Elleuch 2021-02-03 17:54:37 +01:00 committed by GitHub
parent fed3bda697
commit 7f3f3ee1ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1319,11 +1319,15 @@ func (z *erasureServerSets) listObjectVersions(ctx context.Context, bucket, pref
loi.NextMarker = entries.FilesVersions[len(entries.FilesVersions)-1].Name
}
var prevPrefix string
for _, entry := range entries.FilesVersions {
for _, version := range entry.Versions {
objInfo := version.ToObjectInfo(bucket, entry.Name)
if HasSuffix(objInfo.Name, SlashSeparator) && !recursive {
loi.Prefixes = append(loi.Prefixes, objInfo.Name)
if objInfo.Name != prevPrefix {
loi.Prefixes = append(loi.Prefixes, objInfo.Name)
prevPrefix = objInfo.Name
}
continue
}
loi.Objects = append(loi.Objects, objInfo)