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"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"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]+[/]?)*)`
|
|
|
|
|
2017-08-01 13:32:44 -04:00
|
|
|
var lcowSpecificValidators mountValidator = func(m *mount.Mount) error {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type lcowParser struct {
|
|
|
|
windowsParser
|
|
|
|
}
|
|
|
|
|
2017-12-19 05:44:29 -05:00
|
|
|
func (p *lcowParser) ValidateMountConfig(mnt *mount.Mount) error {
|
2017-08-01 13:32:44 -04:00
|
|
|
return p.validateMountConfigReg(mnt, rxLCOWDestination, lcowSpecificValidators)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *lcowParser) ParseMountRaw(raw, volumeDriver string) (*MountPoint, error) {
|
|
|
|
return p.parseMountRaw(raw, volumeDriver, rxLCOWDestination, false, lcowSpecificValidators)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *lcowParser) ParseMountSpec(cfg mount.Mount) (*MountPoint, error) {
|
|
|
|
return p.parseMountSpec(cfg, rxLCOWDestination, false, lcowSpecificValidators)
|
|
|
|
}
|