2019-05-17 09:03:23 +00:00
|
|
|
package filer_pb
|
|
|
|
|
|
|
|
import (
|
2019-09-02 10:28:40 +00:00
|
|
|
"github.com/joeslay/seaweedfs/weed/storage/needle"
|
2019-05-17 09:03:23 +00:00
|
|
|
)
|
|
|
|
|
2019-06-22 19:30:08 +00:00
|
|
|
func toFileIdObject(fileIdStr string) (*FileId, error) {
|
2019-05-17 09:03:23 +00:00
|
|
|
t, err := needle.ParseFileIdFromString(fileIdStr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &FileId{
|
|
|
|
VolumeId: uint32(t.VolumeId),
|
|
|
|
Cookie: uint32(t.Cookie),
|
|
|
|
FileKey: uint64(t.Key),
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:30:08 +00:00
|
|
|
func (fid *FileId) toFileIdString() string {
|
2019-05-17 09:03:23 +00:00
|
|
|
return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String()
|
|
|
|
}
|
|
|
|
|
2019-06-22 19:30:08 +00:00
|
|
|
func (c *FileChunk) GetFileIdString() string {
|
|
|
|
if c.FileId != "" {
|
|
|
|
return c.FileId
|
|
|
|
}
|
|
|
|
if c.Fid != nil {
|
|
|
|
c.FileId = c.Fid.toFileIdString()
|
|
|
|
return c.FileId
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2019-05-17 09:03:23 +00:00
|
|
|
func BeforeEntrySerialization(chunks []*FileChunk) {
|
|
|
|
|
|
|
|
for _, chunk := range chunks {
|
|
|
|
|
|
|
|
if chunk.FileId != "" {
|
2019-06-22 19:30:08 +00:00
|
|
|
if fid, err := toFileIdObject(chunk.FileId); err == nil {
|
2019-05-17 09:03:23 +00:00
|
|
|
chunk.Fid = fid
|
|
|
|
chunk.FileId = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if chunk.SourceFileId != "" {
|
2019-06-22 19:30:08 +00:00
|
|
|
if fid, err := toFileIdObject(chunk.SourceFileId); err == nil {
|
2019-05-17 09:03:23 +00:00
|
|
|
chunk.SourceFid = fid
|
|
|
|
chunk.SourceFileId = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func AfterEntryDeserialization(chunks []*FileChunk) {
|
|
|
|
|
|
|
|
for _, chunk := range chunks {
|
|
|
|
|
|
|
|
if chunk.Fid != nil && chunk.FileId == "" {
|
2019-06-22 19:30:08 +00:00
|
|
|
chunk.FileId = chunk.Fid.toFileIdString()
|
2019-05-17 09:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if chunk.SourceFid != nil && chunk.SourceFileId == "" {
|
2019-06-22 19:30:08 +00:00
|
|
|
chunk.SourceFileId = chunk.SourceFid.toFileIdString()
|
2019-05-17 09:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|