github.com/wlan0/docker@v1.5.0/pkg/graphdb/utils.go (about)

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