utils_linux.go 511 B

1234567891011121314151617181920212223242526272829303132
  1. package graphdb
  2. import (
  3. "path"
  4. "strings"
  5. )
  6. // Split p on /
  7. func split(p string) []string {
  8. return strings.Split(p, "/")
  9. }
  10. // PathDepth returns the depth or number of / in a given path
  11. func PathDepth(p string) int {
  12. parts := split(p)
  13. if len(parts) == 2 && parts[1] == "" {
  14. return 1
  15. }
  16. return len(parts)
  17. }
  18. func splitPath(p string) (parent, name string) {
  19. if p[0] != '/' {
  20. p = "/" + p
  21. }
  22. parent, name = path.Split(p)
  23. l := len(parent)
  24. if parent[l-1] == '/' {
  25. parent = parent[:l-1]
  26. }
  27. return
  28. }