Skip to content

Commit

Permalink
return context error if the context was canceled mid-way
Browse files Browse the repository at this point in the history
fixes #1850
  • Loading branch information
harshavardhana committed Jul 10, 2023
1 parent 8be8154 commit c0cb084
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions api-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (c *Client) listObjectsV2(ctx context.Context, bucketName string, opts List
// If contents are available loop through and send over channel.
for _, object := range result.Contents {
object.ETag = trimEtag(object.ETag)
object.Err = ctx.Err()
select {
// Send object content.
case objectStatCh <- object:
Expand All @@ -128,7 +129,7 @@ func (c *Client) listObjectsV2(ctx context.Context, bucketName string, opts List
for _, obj := range result.CommonPrefixes {
select {
// Send object prefixes.
case objectStatCh <- ObjectInfo{Key: obj.Prefix}:
case objectStatCh <- ObjectInfo{Key: obj.Prefix, Err: ctx.Err()}:
// If receives done from the caller, return here.
case <-ctx.Done():
return
Expand Down Expand Up @@ -321,6 +322,8 @@ func (c *Client) listObjects(ctx context.Context, bucketName string, opts ListOb
for _, object := range result.Contents {
// Save the marker.
marker = object.Key
object.ETag = trimEtag(object.ETag)
object.Err = ctx.Err()
select {
// Send object content.
case objectStatCh <- object:
Expand All @@ -335,7 +338,7 @@ func (c *Client) listObjects(ctx context.Context, bucketName string, opts ListOb
for _, obj := range result.CommonPrefixes {
select {
// Send object prefixes.
case objectStatCh <- ObjectInfo{Key: obj.Prefix}:
case objectStatCh <- ObjectInfo{Key: obj.Prefix, Err: ctx.Err()}:
// If receives done from the caller, return here.
case <-ctx.Done():
return
Expand Down Expand Up @@ -424,6 +427,7 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
IsDeleteMarker: version.isDeleteMarker,
UserTags: version.UserTags,
UserMetadata: version.UserMetadata,
Err: ctx.Err(),
}
select {
// Send object version info.
Expand All @@ -439,7 +443,7 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
for _, obj := range result.CommonPrefixes {
select {
// Send object prefixes.
case resultCh <- ObjectInfo{Key: obj.Prefix}:
case resultCh <- ObjectInfo{Key: obj.Prefix, Err: ctx.Err()}:
// If receives done from the caller, return here.
case <-ctx.Done():
return
Expand Down Expand Up @@ -783,6 +787,7 @@ func (c *Client) listIncompleteUploads(ctx context.Context, bucketName, objectPr

// Send all multipart uploads.
for _, obj := range result.Uploads {
obj.Err = ctx.Err()
// Calculate total size of the uploaded parts if 'aggregateSize' is enabled.
select {
// Send individual uploads here.
Expand All @@ -797,7 +802,7 @@ func (c *Client) listIncompleteUploads(ctx context.Context, bucketName, objectPr
for _, obj := range result.CommonPrefixes {
select {
// Send delimited prefixes here.
case objectMultipartStatCh <- ObjectMultipartInfo{Key: obj.Prefix, Size: 0}:
case objectMultipartStatCh <- ObjectMultipartInfo{Key: obj.Prefix, Size: 0, Err: ctx.Err()}:
// If context is canceled.
case <-ctx.Done():
return
Expand Down

0 comments on commit c0cb084

Please sign in to comment.