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