github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/volume/mounts/lcow_parser.go (about) 1 package mounts // import "github.com/docker/docker/volume/mounts" 2 3 import ( 4 "errors" 5 "fmt" 6 "path" 7 "regexp" 8 "strings" 9 10 "github.com/docker/docker/api/types/mount" 11 ) 12 13 // NewLCOWParser creates a parser with Linux Containers on Windows semantics. 14 func NewLCOWParser() Parser { 15 return &lcowParser{ 16 windowsParser{ 17 fi: defaultFileInfoProvider{}, 18 }, 19 } 20 } 21 22 // rxLCOWDestination is the regex expression for the mount destination for LCOW 23 // 24 // Destination (aka container path): 25 // - Variation on hostdir but can be a drive followed by colon as well 26 // - If a path, must be absolute. Can include spaces 27 // - Drive cannot be c: (explicitly checked in code, not RegEx) 28 const rxLCOWDestination = `(?P<destination>/(?:[^\\/:*?"<>\r\n]+[/]?)*)` 29 30 var ( 31 lcowMountDestinationRegex = regexp.MustCompile(`^` + rxLCOWDestination + `$`) 32 lcowSplitRawSpec = regexp.MustCompile(`^` + rxSource + rxLCOWDestination + rxMode + `$`) 33 ) 34 35 var lcowValidators mountValidator = func(m *mount.Mount) error { 36 if path.Clean(m.Target) == "/" { 37 return ErrVolumeTargetIsRoot 38 } 39 if m.Type == mount.TypeNamedPipe { 40 return errors.New("Linux containers on Windows do not support named pipe mounts") 41 } 42 if !lcowMountDestinationRegex.MatchString(strings.ToLower(m.Target)) { 43 return fmt.Errorf("invalid mount path: '%s'", m.Target) 44 } 45 return nil 46 } 47 48 type lcowParser struct { 49 windowsParser 50 } 51 52 func (p *lcowParser) ValidateMountConfig(mnt *mount.Mount) error { 53 return p.validateMountConfigReg(mnt, lcowValidators) 54 } 55 56 func (p *lcowParser) ParseMountRaw(raw, volumeDriver string) (*MountPoint, error) { 57 arr, err := p.splitRawSpec(raw, lcowSplitRawSpec) 58 if err != nil { 59 return nil, err 60 } 61 return p.parseMount(arr, raw, volumeDriver, false, lcowValidators) 62 } 63 64 func (p *lcowParser) ParseMountSpec(cfg mount.Mount) (*MountPoint, error) { 65 return p.parseMountSpec(cfg, false, lcowValidators) 66 }