From 43cae9ee048ff62c1c746619dd11d39fc3e52b03 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 21 Dec 2023 10:53:50 +0300 Subject: [PATCH] [#248] Correct object versions response markers Signed-off-by: Denis Kirillov --- api/handler/object_list_test.go | 4 ++++ api/layer/versioning.go | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/handler/object_list_test.go b/api/handler/object_list_test.go index e8e1caed..6e962d62 100644 --- a/api/handler/object_list_test.go +++ b/api/handler/object_list_test.go @@ -232,12 +232,16 @@ func TestMintVersioningListObjectVersionsVersionIDContinuation(t *testing.T) { checkVersionsNames(t, page1, objects) require.Equal(t, page1.Version[maxKeys-1].VersionID, page1.NextVersionIDMarker) require.True(t, page1.IsTruncated) + require.Empty(t, page1.KeyMarker) + require.Empty(t, page1.VersionIDMarker) page2 := listObjectsVersions(hc, bktName, "", "", page1.NextKeyMarker, page1.NextVersionIDMarker, maxKeys) require.Len(t, page2.Version, maxKeys) checkVersionsNames(t, page1, objects) require.Empty(t, page2.NextVersionIDMarker) require.False(t, page2.IsTruncated) + require.Equal(t, page1.NextKeyMarker, page2.KeyMarker) + require.Equal(t, page1.NextVersionIDMarker, page2.VersionIDMarker) } func checkVersionsNames(t *testing.T, versions *ListObjectsVersionsResponse, names []string) { diff --git a/api/layer/versioning.go b/api/layer/versioning.go index 2bf9b2bc..7e0c4a67 100644 --- a/api/layer/versioning.go +++ b/api/layer/versioning.go @@ -9,11 +9,6 @@ import ( ) func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) { - var ( - allObjects = make([]*data.ExtendedObjectInfo, 0, p.MaxKeys) - res = &ListObjectVersionsInfo{} - ) - versions, err := n.getAllObjectsVersions(ctx, p.BktInfo, p.Prefix, p.Delimiter) if err != nil { return nil, err @@ -25,6 +20,8 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar } sort.Strings(sortedNames) + allObjects := make([]*data.ExtendedObjectInfo, 0, p.MaxKeys) + for _, name := range sortedNames { sortedVersions := versions[name] sort.Slice(sortedVersions, func(i, j int) bool { @@ -41,6 +38,11 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar return nil, err } + res := &ListObjectVersionsInfo{ + KeyMarker: p.KeyMarker, + VersionIDMarker: p.VersionIDMarker, + } + res.CommonPrefixes, allObjects = triageExtendedObjects(allObjects) if len(allObjects) > p.MaxKeys { @@ -49,8 +51,6 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar res.NextVersionIDMarker = allObjects[p.MaxKeys-1].ObjectInfo.VersionID() allObjects = allObjects[:p.MaxKeys] - res.KeyMarker = p.KeyMarker - res.VersionIDMarker = p.VersionIDMarker } res.Version, res.DeleteMarker = triageVersions(allObjects)