Bucket List Operations.
(ctx context.Context, bucketName string, opts ListObjectsOptions)
| 118 | |
| 119 | // Bucket List Operations. |
| 120 | func (c *Client) listObjectsV2(ctx context.Context, bucketName string, opts ListObjectsOptions) iter.Seq[ObjectInfo] { |
| 121 | // Default listing is delimited at "/" |
| 122 | delimiter := "/" |
| 123 | if opts.Recursive { |
| 124 | // If recursive we do not delimit. |
| 125 | delimiter = "" |
| 126 | } |
| 127 | |
| 128 | // Return object owner information by default |
| 129 | fetchOwner := true |
| 130 | |
| 131 | return func(yield func(ObjectInfo) bool) { |
| 132 | if contextCanceled(ctx) { |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | // Validate bucket name. |
| 137 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 138 | yield(ObjectInfo{Err: err}) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | // Validate incoming object prefix. |
| 143 | if err := s3utils.CheckValidObjectNamePrefix(opts.Prefix); err != nil { |
| 144 | yield(ObjectInfo{Err: err}) |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | // Save continuationToken for next request. |
| 149 | var continuationToken string |
| 150 | for { |
| 151 | if contextCanceled(ctx) { |
| 152 | return |
| 153 | } |
| 154 | |
| 155 | // Get list of objects a maximum of 1000 per request. |
| 156 | result, err := c.listObjectsV2Query(ctx, bucketName, opts.Prefix, continuationToken, |
| 157 | fetchOwner, opts.WithMetadata, delimiter, opts.StartAfter, opts.MaxKeys, opts.headers) |
| 158 | if err != nil { |
| 159 | yield(ObjectInfo{Err: err}) |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | // If contents are available loop through and send over channel. |
| 164 | for _, object := range result.Contents { |
| 165 | object.ETag = trimEtag(object.ETag) |
| 166 | if !yield(object) { |
| 167 | return |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Send all common prefixes if any. |
| 172 | // NOTE: prefixes are only present if the request is delimited. |
| 173 | for _, obj := range result.CommonPrefixes { |
| 174 | if !yield(ObjectInfo{Key: obj.Prefix}) { |
| 175 | return |
| 176 | } |
| 177 | } |
no test coverage detected