aboutsummaryrefslogtreecommitdiff
path: root/weed/storage/needle/file_id.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/storage/needle/file_id.go')
-rw-r--r--weed/storage/needle/file_id.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/weed/storage/needle/file_id.go b/weed/storage/needle/file_id.go
index 906877b8c..5dabb0f25 100644
--- a/weed/storage/needle/file_id.go
+++ b/weed/storage/needle/file_id.go
@@ -2,6 +2,8 @@ package needle
import (
"encoding/hex"
+ "fmt"
+ "strings"
. "github.com/chrislusf/seaweedfs/weed/storage/types"
)
@@ -20,6 +22,41 @@ func NewFileId(VolumeId VolumeId, key uint64, cookie uint32) *FileId {
return &FileId{VolumeId: VolumeId, Key: Uint64ToNeedleId(key), Cookie: Uint32ToCookie(cookie)}
}
+// Deserialize the file id
+func ParseFileIdFromString(fid string) (*FileId, error) {
+ vid, needleKeyCookie, err := splitVolumeId(fid)
+ if err != nil {
+ return nil, err
+ }
+ volumeId, err := NewVolumeId(vid)
+ if err != nil {
+ return nil, err
+ }
+
+ nid, cookie, err := ParseNeedleIdCookie(needleKeyCookie)
+ if err != nil {
+ return nil, err
+ }
+ fileId := &FileId{VolumeId: volumeId, Key: nid, Cookie: cookie}
+ return fileId, nil
+}
+
+func (n *FileId) GetVolumeId() VolumeId {
+ return n.VolumeId
+}
+
+func (n *FileId) GetNeedleId() NeedleId {
+ return n.Key
+}
+
+func (n *FileId) GetCookie() Cookie {
+ return n.Cookie
+}
+
+func (n *FileId) GetNeedleIdCookie() string {
+ return formatNeedleIdCookie(n.Key, n.Cookie)
+}
+
func (n *FileId) String() string {
return n.VolumeId.String() + "," + formatNeedleIdCookie(n.Key, n.Cookie)
}
@@ -33,3 +70,12 @@ func formatNeedleIdCookie(key NeedleId, cookie Cookie) string {
}
return hex.EncodeToString(bytes[nonzero_index:])
}
+
+// copied from operation/delete_content.go, to cut off cycle dependency
+func splitVolumeId(fid string) (vid string, key_cookie string, err error) {
+ commaIndex := strings.Index(fid, ",")
+ if commaIndex <= 0 {
+ return "", "", fmt.Errorf("wrong fid format")
+ }
+ return fid[:commaIndex], fid[commaIndex+1:], nil
+}