fullpath.go 763 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package filer2
  2. import (
  3. "path/filepath"
  4. "strings"
  5. "github.com/chrislusf/seaweedfs/weed/util"
  6. )
  7. type FullPath string
  8. func NewFullPath(dir, name string) FullPath {
  9. return FullPath(dir).Child(name)
  10. }
  11. func (fp FullPath) DirAndName() (string, string) {
  12. dir, name := filepath.Split(string(fp))
  13. if dir == "/" {
  14. return dir, name
  15. }
  16. if len(dir) < 1 {
  17. return "/", ""
  18. }
  19. return dir[:len(dir)-1], name
  20. }
  21. func (fp FullPath) Name() string {
  22. _, name := filepath.Split(string(fp))
  23. return name
  24. }
  25. func (fp FullPath) Child(name string) FullPath {
  26. dir := string(fp)
  27. if strings.HasSuffix(dir, "/") {
  28. return FullPath(dir + name)
  29. }
  30. return FullPath(dir + "/" + name)
  31. }
  32. func (fp FullPath) AsInode() uint64 {
  33. return uint64(util.HashStringToLong(string(fp)))
  34. }