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.

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