fix: gateway Walk() implementation to list correct contents (#10131)

closes #10122
This commit is contained in:
Harshavardhana 2020-07-26 22:56:05 -07:00 committed by GitHub
parent 4b22b288a6
commit 6529dcb3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 // 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 { 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 { 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. // Make sure the results channel is ready to be read when we're done.
defer close(results) defer close(results)
var marker string
for { for {
// set maxKeys to '0' to list maximum possible objects in single call. // set maxKeys to '0' to list maximum possible objects in single call.
loi, err := l.ObjectLayer.ListObjects(ctx, bucket, prefix, marker, "", 0) loi, err := l.ObjectLayer.ListObjects(ctx, bucket, prefix, marker, "", 0)
if err != nil { if err != nil {
return err logger.LogIf(ctx, err)
return
} }
marker = loi.NextMarker marker = loi.NextMarker
for _, obj := range loi.Objects { for _, obj := range loi.Objects {
select { select {
case results <- obj: case results <- obj:
case <-ctx.Done(): case <-ctx.Done():
return nil return
} }
} }
if !loi.IsTruncated { if !loi.IsTruncated {
break break
} }
} }
}()
return nil return nil
} }