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.6 KiB

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