github.com/nilium/gitlab-runner@v12.5.0+incompatible/helpers/path/unix_path.go (about)

     1  package path
     2  
     3  import golang_path "path"
     4  
     5  type unixPath struct{}
     6  
     7  func (p *unixPath) Join(elem ...string) string {
     8  	return golang_path.Join(elem...)
     9  }
    10  
    11  func (p *unixPath) IsAbs(path string) bool {
    12  	path = golang_path.Clean(path)
    13  	return golang_path.IsAbs(path)
    14  }
    15  
    16  func (p *unixPath) IsRoot(path string) bool {
    17  	path = golang_path.Clean(path)
    18  	return golang_path.IsAbs(path) && golang_path.Dir(path) == path
    19  }
    20  
    21  func (p *unixPath) Contains(basePath, targetPath string) bool {
    22  	basePath = golang_path.Clean(basePath)
    23  	targetPath = golang_path.Clean(targetPath)
    24  
    25  	for {
    26  		if targetPath == basePath {
    27  			return true
    28  		}
    29  		if p.IsRoot(targetPath) || targetPath == "." {
    30  			return false
    31  		}
    32  		targetPath = golang_path.Dir(targetPath)
    33  	}
    34  }
    35  
    36  func NewUnixPath() Path {
    37  	return &unixPath{}
    38  }