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.

75 lines
1.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  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. func (fp FullPath) Name() (string) {
  21. _, name := filepath.Split(string(fp))
  22. return name
  23. }
  24. type Attr struct {
  25. Mtime time.Time // time of last modification
  26. Crtime time.Time // time of creation (OS X only)
  27. Mode os.FileMode // file mode
  28. Uid uint32 // owner uid
  29. Gid uint32 // group gid
  30. }
  31. func (attr Attr) IsDirectory() (bool) {
  32. return attr.Mode & os.ModeDir > 0
  33. }
  34. type Entry struct {
  35. FullPath
  36. Attr
  37. // the following is for files
  38. Chunks []FileChunk `json:"chunks,omitempty"`
  39. }
  40. type FileChunk struct {
  41. Fid FileId `json:"fid,omitempty"`
  42. Offset int64 `json:"offset,omitempty"`
  43. Size uint64 `json:"size,omitempty"` // size in bytes
  44. }
  45. type AbstractFiler interface {
  46. CreateEntry(*Entry) (error)
  47. AppendFileChunk(FullPath, FileChunk) (err error)
  48. FindEntry(FullPath) (found bool, fileEntry *Entry, err error)
  49. DeleteEntry(FullPath) (fileEntry *Entry, err error)
  50. ListDirectoryEntries(dirPath FullPath) ([]*Entry, error)
  51. UpdateEntry(*Entry) (error)
  52. }
  53. var ErrNotFound = errors.New("filer: no entry is found in filer store")
  54. type FilerStore interface {
  55. InsertEntry(*Entry) (error)
  56. AppendFileChunk(FullPath, FileChunk) (err error)
  57. FindEntry(FullPath) (found bool, entry *Entry, err error)
  58. DeleteEntry(FullPath) (fileEntry *Entry, err error)
  59. ListDirectoryEntries(dirPath FullPath, startFileName string, inclusive bool, limit int) ([]*Entry, error)
  60. }