From ec6039c53b9681dabeb3c513ec574c4beb77f639 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 26 Jul 2022 18:36:05 +0300 Subject: [PATCH] [#627] Correct listing object same as directory Signed-off-by: Denis Kirillov --- internal/neofs/tree.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/neofs/tree.go b/internal/neofs/tree.go index 592ca07d6..6de807566 100644 --- a/internal/neofs/tree.go +++ b/internal/neofs/tree.go @@ -655,10 +655,17 @@ func (c *TreeClient) getSubTreeByPrefix(ctx context.Context, cnrID cid.ID, treeI nodes := nodesMap[fileName] - if !latestOnly { - nodes = append(nodes, node) - } else if len(nodes) == 0 || node.GetTimestamp() > nodes[0].GetTimestamp() { + // Add all nodes if flag latestOnly is false. + // Add all intermediate nodes (actually should be exactly one intermediate node with the same name) + // and only latest leaf (object) nodes. To do this store and replace last leaf (object) node in nodes[0] + if len(nodes) == 0 { nodes = []*tree.GetSubTreeResponse_Body{node} + } else if !latestOnly || isIntermediate(node) { + nodes = append(nodes, node) + } else if isIntermediate(nodes[0]) { + nodes = append([]*tree.GetSubTreeResponse_Body{node}, nodes...) + } else if node.GetTimestamp() > nodes[0].GetTimestamp() { + nodes[0] = node } nodesMap[fileName] = nodes @@ -682,7 +689,7 @@ func getFilename(node *tree.GetSubTreeResponse_Body) string { return "" } -func isIntermediate(node *tree.GetNodeByPathResponse_Info) bool { +func isIntermediate(node NodeResponse) bool { if len(node.GetMeta()) != 1 { return false }