filer_structure.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package filer2
  2. import (
  3. "errors"
  4. "os"
  5. "time"
  6. "path/filepath"
  7. )
  8. type FileId string //file id in SeaweedFS
  9. type FullPath string
  10. func (fp FullPath) DirAndName() (string, string) {
  11. dir, name := filepath.Split(string(fp))
  12. if dir == "/" {
  13. return dir, name
  14. }
  15. if len(dir) < 1 {
  16. return "/", ""
  17. }
  18. return dir[:len(dir)-1], name
  19. }
  20. type Attr struct {
  21. Mtime time.Time // time of last modification
  22. Crtime time.Time // time of creation (OS X only)
  23. Mode os.FileMode // file mode
  24. Uid uint32 // owner uid
  25. Gid uint32 // group gid
  26. }
  27. type Entry struct {
  28. FullPath
  29. Attr
  30. // the following is for files
  31. Chunks []FileChunk `json:"chunks,omitempty"`
  32. }
  33. type FileChunk struct {
  34. Fid FileId `json:"fid,omitempty"`
  35. Offset int64 `json:"offset,omitempty"`
  36. Size uint64 `json:"size,omitempty"` // size in bytes
  37. }
  38. type AbstractFiler interface {
  39. CreateEntry(*Entry) (error)
  40. AppendFileChunk(FullPath, FileChunk) (err error)
  41. FindEntry(FullPath) (found bool, fileEntry *Entry, err error)
  42. DeleteEntry(FullPath) (fileEntry *Entry, err error)
  43. ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
  44. UpdateEntry(*Entry) (error)
  45. }
  46. var ErrNotFound = errors.New("filer: no entry is found in filer store")
  47. type FilerStore interface {
  48. InsertEntry(*Entry) (error)
  49. AppendFileChunk(FullPath, FileChunk) (err error)
  50. FindEntry(FullPath) (found bool, entry *Entry, err error)
  51. DeleteEntry(FullPath) (fileEntry *Entry, err error)
  52. ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
  53. }