[#657] Don't use <empty> to handle trailing slash

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
support/v0.25
Denis Kirillov 2022-09-07 11:16:42 +03:00 committed by Kirillov Denis
parent 9cd4ef1ac4
commit 5184ed66c6
1 changed files with 3 additions and 18 deletions

View File

@ -75,7 +75,6 @@ const (
settingsFileName = "bucket-settings"
notifConfFileName = "bucket-notifications"
corsFilename = "bucket-cors"
emptyFileName = "<empty>" // to handle trailing and leading slash in name
bucketTaggingFilename = "bucket-tagging"
// versionTree -- ID of a tree with object versions.
@ -150,10 +149,6 @@ func (n *TreeNode) Get(key string) (string, bool) {
func (n *TreeNode) FileName() (string, bool) {
value, ok := n.Meta[fileNameKV]
if ok && value == emptyFileName {
value = ""
}
return value, ok
}
@ -216,7 +211,7 @@ func newMultipartInfo(node NodeResponse) (*data.MultipartInfo, error) {
case uploadIDKV:
multipartInfo.UploadID = string(kv.GetValue())
case fileNameKV:
multipartInfo.Key = strings.TrimSuffix(string(kv.GetValue()), emptyFileName)
multipartInfo.Key = string(kv.GetValue())
case createdKV:
if utcMilli, err := strconv.ParseInt(string(kv.GetValue()), 10, 64); err == nil {
multipartInfo.Created = time.UnixMilli(utcMilli)
@ -564,16 +559,9 @@ func (c *TreeClient) GetLatestVersion(ctx context.Context, cnrID cid.ID, objectN
return newNodeVersion(objectName, nodes[0])
}
// pathFromName splits name by '/' and add an empty marker if name has trailing or leading slash.
// pathFromName splits name by '/'.
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
}
return path
return strings.Split(objectName, separator)
}
func (c *TreeClient) GetLatestVersionsByPrefix(ctx context.Context, cnrID cid.ID, prefix string) ([]*data.NodeVersion, error) {
@ -583,9 +571,6 @@ func (c *TreeClient) GetLatestVersionsByPrefix(ctx context.Context, cnrID cid.ID
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 len(path) > 1 && path[0] == "" {
path[0] = emptyFileName
}
tailPrefix := path[len(path)-1]
if len(path) > 1 {