/
linux_parser.go
41 lines (31 loc) · 1.01 KB
/
linux_parser.go
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
39
40
41
package parser
import (
"regexp"
"gitlab.com/gitlab-org/gitlab-runner/helpers/path"
)
const (
linuxDir = `/(?:[^\\/:*?"<>|\r\n ]+/?)*`
linuxVolumeName = `[^\\/:*?"<>|\r\n]+`
linuxSource = `((?P<source>((` + linuxDir + `)|(` + linuxVolumeName + `))):)?`
linuxDestination = `(?P<destination>(?:` + linuxDir + `))`
linuxMode = `(:(?P<mode>(?i)ro|rw|z))?`
linuxBindPropagation = `((:|,)(?P<bindPropagation>(?i)shared|slave|private|rshared|rslave|rprivate))?`
)
type linuxParser struct {
baseParser
}
func NewLinuxParser() Parser {
return &linuxParser{
baseParser: baseParser{
path: path.NewUnixPath(),
},
}
}
func (p *linuxParser) ParseVolume(spec string) (*Volume, error) {
specExp := regexp.MustCompile(`^` + linuxSource + linuxDestination + linuxMode + linuxBindPropagation + `$`)
parts, err := p.matchesToVolumeSpecParts(spec, specExp)
if err != nil {
return nil, err
}
return newVolume(parts["source"], parts["destination"], parts["mode"], parts["bindPropagation"]), nil
}