From 64931c77f4fac563ac7ec10713395812b9a5fddd Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 7 Jun 2022 09:49:50 +0300 Subject: [PATCH] [#503] Handle leading slash in names Signed-off-by: Denis Kirillov --- internal/neofs/tree.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/neofs/tree.go b/internal/neofs/tree.go index ac212bd82..f4310624f 100644 --- a/internal/neofs/tree.go +++ b/internal/neofs/tree.go @@ -74,7 +74,7 @@ const ( settingsFileName = "bucket-settings" notifConfFileName = "bucket-notifications" corsFilename = "bucket-cors" - emptyFileName = "" // to handle trailing slash in name + emptyFileName = "" // to handle trailing and leading slash in name bucketTaggingFilename = "bucket-tagging" // versionTree -- ID of a tree with object versions. @@ -527,9 +527,12 @@ func (c *TreeClient) GetLatestVersion(ctx context.Context, cnrID *cid.ID, object return c.getLatestVersion(ctx, cnrID, versionTree, path, meta) } -// pathFromName splits name by '/' and add an empty marker if name has trailing slash. +// pathFromName splits name by '/' and add an empty marker if name has trailing or leading slash. func pathFromName(objectName string) []string { path := strings.Split(objectName, separator) + if path[0] == "" { + path[0] = emptyFileName + } if path[len(path)-1] == "" { path[len(path)-1] = emptyFileName } @@ -560,6 +563,9 @@ func (c *TreeClient) GetLatestVersionsByPrefix(ctx context.Context, cnrID *cid.I func (c *TreeClient) determinePrefixNode(ctx context.Context, cnrID *cid.ID, treeID, prefix string) (uint64, string, error) { var rootID uint64 path := strings.Split(prefix, separator) + if path[0] == "" { + path[0] = emptyFileName + } tailPrefix := path[len(path)-1] if len(path) > 1 {