2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-10-25 17:38:53 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package kvmetainfo
|
|
|
|
|
2018-11-06 11:40:06 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-25 17:38:53 +01:00
|
|
|
|
2018-11-06 11:40:06 +00:00
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
2018-10-25 17:38:53 +01:00
|
|
|
|
|
|
|
// TODO: known issue:
|
|
|
|
// this is incorrect since there's no good way to get such a path
|
|
|
|
// since the exact previous key is
|
|
|
|
// append(previousPrefix(cursor), infinite(0xFF)...)
|
|
|
|
func keyBefore(cursor string) string {
|
|
|
|
if cursor == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
before := []byte(cursor)
|
|
|
|
if before[len(before)-1] == 0 {
|
|
|
|
return string(before[:len(before)-1])
|
|
|
|
}
|
|
|
|
before[len(before)-1]--
|
|
|
|
|
2018-11-12 13:23:19 +00:00
|
|
|
before = append(before, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f)
|
2018-10-25 17:38:53 +01:00
|
|
|
return string(before)
|
|
|
|
}
|
|
|
|
|
|
|
|
func keyAfter(cursor string) string {
|
|
|
|
return cursor + "\x00"
|
|
|
|
}
|
2018-11-06 11:40:06 +00:00
|
|
|
|
|
|
|
// getSegmentPath returns the unique path for a particular segment
|
|
|
|
func getSegmentPath(encryptedPath storj.Path, segNum int64) storj.Path {
|
|
|
|
return storj.JoinPaths(fmt.Sprintf("s%d", segNum), encryptedPath)
|
|
|
|
}
|