From 6d52f460123356f716fcac40da333952c5749cc1 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Sun, 21 Jan 2024 00:39:03 +0300 Subject: [PATCH] [#165] Fix v1 listing bookmark Signed-off-by: Denis Kirillov --- api/layer/listing.go | 58 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/api/layer/listing.go b/api/layer/listing.go index 6f0b305d..e7039107 100644 --- a/api/layer/listing.go +++ b/api/layer/listing.go @@ -74,12 +74,13 @@ type ( } allObjectListingParams struct { - BktInfo *data.BucketInfo - Delimiter string - Prefix string - MaxKeys int - Marker string - Bookmark string + BktInfo *data.BucketInfo + Delimiter string + Prefix string + MaxKeys int + Marker string + Bookmark string + VersionAPi string } ) @@ -88,12 +89,13 @@ func (n *layer) ListObjectsV1(ctx context.Context, p *ListObjectsParamsV1) (*Lis var result ListObjectsInfoV1 prm := allObjectListingParams{ - BktInfo: p.BktInfo, - Delimiter: p.Delimiter, - Prefix: p.Prefix, - MaxKeys: p.MaxKeys, - Marker: p.Marker, - Bookmark: p.Marker, + BktInfo: p.BktInfo, + Delimiter: p.Delimiter, + Prefix: p.Prefix, + MaxKeys: p.MaxKeys, + Marker: p.Marker, + Bookmark: p.Marker, + VersionAPi: "v1", } objects, next, err := n.getLatestObjectsVersions(ctx, prm) @@ -116,12 +118,13 @@ func (n *layer) ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*Lis var result ListObjectsInfoV2 prm := allObjectListingParams{ - BktInfo: p.BktInfo, - Delimiter: p.Delimiter, - Prefix: p.Prefix, - MaxKeys: p.MaxKeys, - Marker: p.StartAfter, - Bookmark: p.ContinuationToken, + BktInfo: p.BktInfo, + Delimiter: p.Delimiter, + Prefix: p.Prefix, + MaxKeys: p.MaxKeys, + Marker: p.StartAfter, + Bookmark: p.ContinuationToken, + VersionAPi: "v2", } objects, next, err := n.getLatestObjectsVersions(ctx, prm) @@ -141,12 +144,13 @@ func (n *layer) ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*Lis func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsParams) (*ListObjectVersionsInfo, error) { prm := allObjectListingParams{ - BktInfo: p.BktInfo, - Delimiter: p.Delimiter, - Prefix: p.Prefix, - MaxKeys: p.MaxKeys, - Marker: p.KeyMarker, - Bookmark: p.VersionIDMarker, + BktInfo: p.BktInfo, + Delimiter: p.Delimiter, + Prefix: p.Prefix, + MaxKeys: p.MaxKeys, + Marker: p.KeyMarker, + Bookmark: p.VersionIDMarker, + VersionAPi: "vs", } objects, isTruncated, err := n.getAllObjectsVersions(ctx, prm) @@ -223,7 +227,11 @@ func (n *layer) getLatestObjectsVersions(ctx context.Context, p allObjectListing if next != nil { session.Next = []*data.NodeVersion{next} - n.cache.PutListSession(owner, cache.CreateListSessionCacheKey(p.BktInfo.CID, p.Prefix, next.OID.EncodeToString()), session) + if p.VersionAPi == "v1" { + n.cache.PutListSession(owner, cache.CreateListSessionCacheKey(p.BktInfo.CID, p.Prefix, objects[len(objects)-1].FilePath), session) + } else { + n.cache.PutListSession(owner, cache.CreateListSessionCacheKey(p.BktInfo.CID, p.Prefix, next.OID.EncodeToString()), session) + } } return