gitlab.com/jfprevost/gitlab-runner-notlscheck@v11.11.4+incompatible/executors/docker/internal/volumes/parser/linux_parser.go (about)

     1  package parser
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"gitlab.com/gitlab-org/gitlab-runner/helpers/path"
     7  )
     8  
     9  const (
    10  	linuxDir        = `/(?:[^\\/:*?"<>|\r\n ]+/?)*`
    11  	linuxVolumeName = `[^\\/:*?"<>|\r\n]+`
    12  
    13  	linuxSource = `((?P<source>((` + linuxDir + `)|(` + linuxVolumeName + `))):)?`
    14  
    15  	linuxDestination = `(?P<destination>(?:` + linuxDir + `))`
    16  	linuxMode        = `(:(?P<mode>(?i)ro|rw|z))?`
    17  )
    18  
    19  type linuxParser struct {
    20  	baseParser
    21  }
    22  
    23  func NewLinuxParser() Parser {
    24  	return &linuxParser{
    25  		baseParser: baseParser{
    26  			path: path.NewUnixPath(),
    27  		},
    28  	}
    29  }
    30  
    31  func (p *linuxParser) ParseVolume(spec string) (*Volume, error) {
    32  	specExp := regexp.MustCompile(`^` + linuxSource + linuxDestination + linuxMode + `$`)
    33  
    34  	parts, err := p.matchesToVolumeSpecParts(spec, specExp)
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	return newVolume(parts["source"], parts["destination"], parts["mode"]), nil
    40  }