From 6529dcb3b52fce143539bf7c912ce9c00ed9ec33 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 26 Jul 2020 22:56:05 -0700 Subject: [PATCH] fix: gateway Walk() implementation to list correct contents (#10131) closes #10122 --- cmd/gateway-main.go | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index 8920693df..1f4836ade 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -59,29 +59,32 @@ func (l *GatewayLocker) NewNSLock(ctx context.Context, bucket string, objects .. // Walk - implements common gateway level Walker, to walk on all objects recursively at a prefix func (l *GatewayLocker) Walk(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo, opts ObjectOptions) error { walk := func(ctx context.Context, bucket, prefix string, results chan<- ObjectInfo) error { - var marker string + go func() { + // Make sure the results channel is ready to be read when we're done. + defer close(results) - // Make sure the results channel is ready to be read when we're done. - defer close(results) + var marker string - for { - // set maxKeys to '0' to list maximum possible objects in single call. - loi, err := l.ObjectLayer.ListObjects(ctx, bucket, prefix, marker, "", 0) - if err != nil { - return err - } - marker = loi.NextMarker - for _, obj := range loi.Objects { - select { - case results <- obj: - case <-ctx.Done(): - return nil + for { + // set maxKeys to '0' to list maximum possible objects in single call. + loi, err := l.ObjectLayer.ListObjects(ctx, bucket, prefix, marker, "", 0) + if err != nil { + logger.LogIf(ctx, err) + return + } + marker = loi.NextMarker + for _, obj := range loi.Objects { + select { + case results <- obj: + case <-ctx.Done(): + return + } + } + if !loi.IsTruncated { + break } } - if !loi.IsTruncated { - break - } - } + }() return nil }