You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

  1. package filer_pb
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  4. )
  5. func toFileId(fileIdStr string) (*FileId, error) {
  6. t, err := needle.ParseFileIdFromString(fileIdStr)
  7. if err != nil {
  8. return nil, err
  9. }
  10. return &FileId{
  11. VolumeId: uint32(t.VolumeId),
  12. Cookie: uint32(t.Cookie),
  13. FileKey: uint64(t.Key),
  14. }, nil
  15. }
  16. func (fid *FileId) toFileId() string {
  17. return needle.NewFileId(needle.VolumeId(fid.VolumeId), fid.FileKey, fid.Cookie).String()
  18. }
  19. func (fid *FileId) Equals(that *FileId) bool {
  20. return fid.FileKey == that.FileKey && fid.VolumeId == that.VolumeId && fid.Cookie == that.Cookie
  21. }
  22. func BeforeEntrySerialization(chunks []*FileChunk) {
  23. for _, chunk := range chunks {
  24. if chunk.FileId != "" {
  25. if fid, err := toFileId(chunk.FileId); err == nil {
  26. chunk.Fid = fid
  27. chunk.FileId = ""
  28. }
  29. }
  30. if chunk.SourceFileId != "" {
  31. if fid, err := toFileId(chunk.SourceFileId); err == nil {
  32. chunk.SourceFid = fid
  33. chunk.SourceFileId = ""
  34. }
  35. }
  36. }
  37. }
  38. func AfterEntryDeserialization(chunks []*FileChunk) {
  39. for _, chunk := range chunks {
  40. if chunk.Fid != nil && chunk.FileId == "" {
  41. chunk.FileId = chunk.Fid.toFileId()
  42. }
  43. if chunk.SourceFid != nil && chunk.SourceFileId == "" {
  44. chunk.SourceFileId = chunk.SourceFid.toFileId()
  45. }
  46. }
  47. }