fix: listing for directory object when delimiter is present (#11463)

When you have heirarchy of prefixes with directory objects
our current master would list directory objects as prefixes
when delimiter is present, this is inconsistent with AWS S3

```
aws s3api list-objects --endpoint-url http://localhost:9000 \
    --profile minio --bucket testbucket-v --prefix new/ --delimiter /
{
    "CommonPrefixes": [
        {
            "Prefix": "new/"
        },
        {
            "Prefix": "new/new/"
        }
    ]
}
```

Instead this PR fixes this to behave like AWS S3

```
aws s3api list-objects --endpoint-url http://localhost:9000 \
      --profile minio --bucket testbucket-v --prefix new/ --delimiter /
{
    "Contents": [
        {
            "Key": "new/",
            "LastModified": "2021-02-05T06:27:42.660Z",
            "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
            "Size": 0,
            "StorageClass": "STANDARD",
            "Owner": {
                "DisplayName": "",
                "ID": "02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4"
            }
        }
    ],
    "CommonPrefixes": [
        {
            "Prefix": "new/new/"
        }
    ]
}
```
This commit is contained in:
Harshavardhana 2021-02-05 16:24:40 -08:00 committed by GitHub
parent 5fe4bb6b36
commit 1fdafaf72f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -782,7 +782,7 @@ func (z *erasureServerPools) ListObjectVersions(ctx context.Context, bucket, pre
loi.IsTruncated = true
}
for _, obj := range objects {
if obj.IsDir && delimiter != "" {
if obj.IsDir && obj.ModTime.IsZero() && delimiter != "" {
loi.Prefixes = append(loi.Prefixes, obj.Name)
} else {
loi.Objects = append(loi.Objects, obj)
@ -821,7 +821,7 @@ func (z *erasureServerPools) ListObjects(ctx context.Context, bucket, prefix, ma
loi.IsTruncated = true
}
for _, obj := range objects {
if obj.IsDir && delimiter != "" {
if obj.IsDir && obj.ModTime.IsZero() && delimiter != "" {
loi.Prefixes = append(loi.Prefixes, obj.Name)
} else {
loi.Objects = append(loi.Objects, obj)