2018-04-17 16:50:28 -04:00
|
|
|
package mounts // import "github.com/docker/docker/volume/mounts"
|
2017-08-01 13:32:44 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-07-27 04:06:31 -04:00
|
|
|
"fmt"
|
2017-08-01 13:32:44 -04:00
|
|
|
"path"
|
2021-07-26 06:38:06 -04:00
|
|
|
"regexp"
|
2021-07-27 04:06:31 -04:00
|
|
|
"strings"
|
2017-08-01 13:32:44 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/mount"
|
|
|
|
)
|
|
|
|
|
2021-07-02 07:41:47 -04:00
|
|
|
// NewLCOWParser creates a parser with Linux Containers on Windows semantics.
|
|
|
|
func NewLCOWParser() Parser {
|
2021-06-29 07:19:02 -04:00
|
|
|
return &lcowParser{
|
|
|
|
windowsParser{
|
|
|
|
fi: defaultFileInfoProvider{},
|
|
|
|
},
|
|
|
|
}
|
2021-07-02 07:41:47 -04:00
|
|
|
}
|
|
|
|
|
2021-07-02 07:25:27 -04:00
|
|
|
// rxLCOWDestination is the regex expression for the mount destination for LCOW
|
|
|
|
//
|
|
|
|
// Destination (aka container path):
|
|
|
|
// - Variation on hostdir but can be a drive followed by colon as well
|
|
|
|
// - If a path, must be absolute. Can include spaces
|
|
|
|
// - Drive cannot be c: (explicitly checked in code, not RegEx)
|
|
|
|
const rxLCOWDestination = `(?P<destination>/(?:[^\\/:*?"<>\r\n]+[/]?)*)`
|
|
|
|
|
2021-07-26 06:38:06 -04:00
|
|
|
var (
|
|
|
|
lcowMountDestinationRegex = regexp.MustCompile(`^` + rxLCOWDestination + `$`)
|
|
|
|
lcowSplitRawSpec = regexp.MustCompile(`^` + rxSource + rxLCOWDestination + rxMode + `$`)
|
|
|
|
)
|
|
|
|
|
2021-07-26 06:59:19 -04:00
|
|
|
var lcowValidators mountValidator = func(m *mount.Mount) error {
|
2017-08-01 13:32:44 -04:00
|
|
|
if path.Clean(m.Target) == "/" {
|
2018-01-14 06:10:49 -05:00
|
|
|
return ErrVolumeTargetIsRoot
|
2017-08-01 13:32:44 -04:00
|
|
|
}
|
|
|
|
if m.Type == mount.TypeNamedPipe {
|
|
|
|
return errors.New("Linux containers on Windows do not support named pipe mounts")
|
|
|
|
}
|
2021-07-27 04:06:31 -04:00
|
|
|
if !lcowMountDestinationRegex.MatchString(strings.ToLower(m.Target)) {
|
|
|
|
return fmt.Errorf("invalid mount path: '%s'", m.Target)
|
2021-07-26 06:59:19 -04:00
|
|
|
}
|
2017-08-01 13:32:44 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type lcowParser struct {
|
|
|
|
windowsParser
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:44:29 -05:00
|
|
|
func (p *lcowParser) ValidateMountConfig(mnt *mount.Mount) error {
|
2021-07-26 06:59:19 -04:00
|
|
|
return p.validateMountConfigReg(mnt, lcowValidators)
|
2017-08-01 13:32:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *lcowParser) ParseMountRaw(raw, volumeDriver string) (*MountPoint, error) {
|
2021-07-26 06:44:12 -04:00
|
|
|
arr, err := p.splitRawSpec(raw, lcowSplitRawSpec)
|
2021-07-26 06:38:06 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-26 06:59:19 -04:00
|
|
|
return p.parseMount(arr, raw, volumeDriver, false, lcowValidators)
|
2017-08-01 13:32:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *lcowParser) ParseMountSpec(cfg mount.Mount) (*MountPoint, error) {
|
2021-07-26 06:59:19 -04:00
|
|
|
return p.parseMountSpec(cfg, false, lcowValidators)
|
2017-08-01 13:32:44 -04:00
|
|
|
}
|