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