From 1fdafaf72f3e4185f3ff6dcacc3a017e9483ac8a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 5 Feb 2021 16:24:40 -0800 Subject: [PATCH] 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/" } ] } ``` --- cmd/erasure-server-pool.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/erasure-server-pool.go b/cmd/erasure-server-pool.go index 32f919afa..c7fd60e53 100644 --- a/cmd/erasure-server-pool.go +++ b/cmd/erasure-server-pool.go @@ -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)