summaryrefslogtreecommitdiff
path: root/vendor/github.com/minio/minio-go/v7/api-list.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2025-04-07 11:05:51 +0100
committerLibravatar GitHub <noreply@github.com>2025-04-07 11:05:51 +0100
commitbce643286c6a136db47f2cf7bf3c4fa16a9d6a00 (patch)
treefa621fd5af6bb8fd26d28103b9c3f8d57c088f98 /vendor/github.com/minio/minio-go/v7/api-list.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.22.4 to 2.23.0 (#3974) (diff)
downloadgotosocial-bce643286c6a136db47f2cf7bf3c4fa16a9d6a00.tar.xz
[chore]: Bump github.com/minio/minio-go/v7 from 7.0.85 to 7.0.89 (#3977)
Bumps [github.com/minio/minio-go/v7](https://github.com/minio/minio-go) from 7.0.85 to 7.0.89. - [Release notes](https://github.com/minio/minio-go/releases) - [Commits](https://github.com/minio/minio-go/compare/v7.0.85...v7.0.89) --- updated-dependencies: - dependency-name: github.com/minio/minio-go/v7 dependency-version: 7.0.89 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/minio/minio-go/v7/api-list.go')
-rw-r--r--vendor/github.com/minio/minio-go/v7/api-list.go66
1 files changed, 54 insertions, 12 deletions
diff --git a/vendor/github.com/minio/minio-go/v7/api-list.go b/vendor/github.com/minio/minio-go/v7/api-list.go
index 31b6edf2e..26d35c4c2 100644
--- a/vendor/github.com/minio/minio-go/v7/api-list.go
+++ b/vendor/github.com/minio/minio-go/v7/api-list.go
@@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
"net/url"
+ "slices"
"time"
"github.com/minio/minio-go/v7/pkg/s3utils"
@@ -421,20 +422,17 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
var (
keyMarker = ""
versionIDMarker = ""
+ preName = ""
+ preKey = ""
+ perVersions []Version
+ numVersions int
)
-
- for {
- // Get list of objects a maximum of 1000 per request.
- result, err := c.listObjectVersionsQuery(ctx, bucketName, opts, keyMarker, versionIDMarker, delimiter)
- if err != nil {
- sendObjectInfo(ObjectInfo{
- Err: err,
- })
- return
+ send := func(vers []Version) {
+ if opts.WithVersions && opts.ReverseVersions {
+ slices.Reverse(vers)
+ numVersions = len(vers)
}
-
- // If contents are available loop through and send over channel.
- for _, version := range result.Versions {
+ for _, version := range vers {
info := ObjectInfo{
ETag: trimEtag(version.ETag),
Key: version.Key,
@@ -448,6 +446,7 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
UserTags: version.UserTags,
UserMetadata: version.UserMetadata,
Internal: version.Internal,
+ NumVersions: numVersions,
}
select {
// Send object version info.
@@ -457,6 +456,38 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
return
}
}
+ }
+ for {
+ // Get list of objects a maximum of 1000 per request.
+ result, err := c.listObjectVersionsQuery(ctx, bucketName, opts, keyMarker, versionIDMarker, delimiter)
+ if err != nil {
+ sendObjectInfo(ObjectInfo{
+ Err: err,
+ })
+ return
+ }
+ if opts.WithVersions && opts.ReverseVersions {
+ for _, version := range result.Versions {
+ if preName == "" {
+ preName = result.Name
+ preKey = version.Key
+ }
+ if result.Name == preName && preKey == version.Key {
+ // If the current name is same as previous name,
+ // we need to append the version to the previous version.
+ perVersions = append(perVersions, version)
+ continue
+ }
+ // Send the file versions.
+ send(perVersions)
+ perVersions = perVersions[:0]
+ perVersions = append(perVersions, version)
+ preName = result.Name
+ preKey = version.Key
+ }
+ } else {
+ send(result.Versions)
+ }
// Send all common prefixes if any.
// NOTE: prefixes are only present if the request is delimited.
@@ -480,8 +511,17 @@ func (c *Client) listObjectVersions(ctx context.Context, bucketName string, opts
versionIDMarker = result.NextVersionIDMarker
}
+ // If context is canceled, return here.
+ if contextCanceled(ctx) {
+ return
+ }
+
// Listing ends result is not truncated, return right here.
if !result.IsTruncated {
+ // sent the lasted file with versions
+ if opts.ReverseVersions && len(perVersions) > 0 {
+ send(perVersions)
+ }
return
}
}
@@ -683,6 +723,8 @@ func (c *Client) listObjectsQuery(ctx context.Context, bucketName, objectPrefix,
// ListObjectsOptions holds all options of a list object request
type ListObjectsOptions struct {
+ // ReverseVersions - reverse the order of the object versions
+ ReverseVersions bool
// Include objects versions in the listing
WithVersions bool
// Include objects metadata in the listing