github.com/nilium/gitlab-runner@v12.5.0+incompatible/helpers/path/windows_path.go (about) 1 // +build windows 2 3 // This implementation only works when compiled for Windows 4 // as this uses the `path/filepath` which is platform dependent 5 6 package path 7 8 import ( 9 "path/filepath" 10 "strings" 11 ) 12 13 type windowsPath struct{} 14 15 func (p *windowsPath) Join(elem ...string) string { 16 return filepath.Join(elem...) 17 } 18 19 func (p *windowsPath) IsAbs(path string) bool { 20 path = filepath.Clean(path) 21 return filepath.IsAbs(path) 22 } 23 24 func (p *windowsPath) IsRoot(path string) bool { 25 path = filepath.Clean(path) 26 return filepath.IsAbs(path) && filepath.Dir(path) == path 27 } 28 29 func (p *windowsPath) Contains(basePath, targetPath string) bool { 30 // we use `filepath.Rel` as this perform OS-specific comparison 31 // and this set of functions is compiled using OS-specific golang filepath 32 relativePath, err := filepath.Rel(basePath, targetPath) 33 if err != nil { 34 return false 35 } 36 37 // if it starts with `..` it tries to escape the path 38 if strings.HasPrefix(relativePath, "..") { 39 return false 40 } 41 42 return true 43 } 44 45 func NewWindowsPath() Path { 46 return &windowsPath{} 47 }