File: unix_path.go

package info (click to toggle)
gitlab-ci-multi-runner 14.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 31,248 kB
  • sloc: sh: 1,694; makefile: 384; asm: 79; ruby: 68
file content (38 lines) | stat: -rw-r--r-- 752 bytes parent folder | download
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{}
}