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.

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