parser.go 1.4 KB

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