From 97f81d32700f0101ca198a4300d29aeecc6d337d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 24 Jun 2022 15:39:30 +0300 Subject: [PATCH] [#611] Process delimiters on the object info cache hit Signed-off-by: Alex Vanin --- api/layer/object.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/api/layer/object.go b/api/layer/object.go index 22f79a8a7..04bb97cf1 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -672,7 +672,25 @@ func triageExtendedObjects(allObjects []*data.ExtendedObjectInfo) (prefixes []st func (n *layer) objectInfoFromObjectsCacheOrNeoFS(ctx context.Context, bktInfo *data.BucketInfo, obj oid.ID, prefix, delimiter string) *data.ObjectInfo { if objInfo := n.objCache.GetObject(newAddress(bktInfo.CID, obj)); objInfo != nil { - return objInfo + // that's the simplest solution + // consider doing something else + if !strings.HasPrefix(objInfo.Name, prefix) { + return nil + } + if len(delimiter) == 0 { + return objInfo + } + copiedObjInfo := *objInfo + tail := strings.TrimPrefix(copiedObjInfo.Name, prefix) + index := strings.Index(tail, delimiter) + if index >= 0 { + copiedObjInfo.IsDir = true + copiedObjInfo.Size = 0 + copiedObjInfo.Headers = nil + copiedObjInfo.ContentType = "" + copiedObjInfo.Name = prefix + tail[:index+1] + } + return &copiedObjInfo } meta, err := n.objectHead(ctx, bktInfo, obj)