github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/volume/mounts/parser.go (about)

     1  package mounts // import "github.com/demonoid81/moby/volume/mounts"
     2  
     3  import (
     4  	"errors"
     5  	"runtime"
     6  
     7  	"github.com/demonoid81/moby/api/types/mount"
     8  )
     9  
    10  const (
    11  	// OSLinux is the same as runtime.GOOS on linux
    12  	OSLinux = "linux"
    13  	// OSWindows is the same as runtime.GOOS on windows
    14  	OSWindows = "windows"
    15  )
    16  
    17  // ErrVolumeTargetIsRoot is returned when the target destination is root.
    18  // It's used by both LCOW and Linux parsers.
    19  var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'")
    20  
    21  // Parser represents a platform specific parser for mount expressions
    22  type Parser interface {
    23  	ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)
    24  	ParseMountSpec(cfg mount.Mount) (*MountPoint, error)
    25  	ParseVolumesFrom(spec string) (string, string, error)
    26  	DefaultPropagationMode() mount.Propagation
    27  	ConvertTmpfsOptions(opt *mount.TmpfsOptions, readOnly bool) (string, error)
    28  	DefaultCopyMode() bool
    29  	ValidateVolumeName(name string) error
    30  	ReadWrite(mode string) bool
    31  	IsBackwardCompatible(m *MountPoint) bool
    32  	HasResource(m *MountPoint, absPath string) bool
    33  	ValidateTmpfsMountDestination(dest string) error
    34  	ValidateMountConfig(mt *mount.Mount) error
    35  }
    36  
    37  // NewParser creates a parser for a given container OS, depending on the current host OS (linux on a windows host will resolve to an lcowParser)
    38  func NewParser(containerOS string) Parser {
    39  	switch containerOS {
    40  	case OSWindows:
    41  		return &windowsParser{}
    42  	}
    43  	if runtime.GOOS == OSWindows {
    44  		return &lcowParser{}
    45  	}
    46  	return &linuxParser{}
    47  }