mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup: extract bindmount spec parsing
Docker-DCO-1.1-Signed-off-by: Brian Goff <cpuguy83@gmail.com> (github: cpuguy83)
This commit is contained in:
parent
c9ca37dfe9
commit
f34679d0a9
1 changed files with 31 additions and 25 deletions
|
@ -122,6 +122,31 @@ func applyVolumesFrom(container *Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseBindVolumeSpec(spec string) (BindMap, error) {
|
||||||
|
var (
|
||||||
|
arr = strings.Split(spec, ":")
|
||||||
|
err error = nil
|
||||||
|
vol BindMap
|
||||||
|
)
|
||||||
|
|
||||||
|
switch len(arr) {
|
||||||
|
case 1:
|
||||||
|
vol.DstPath = spec
|
||||||
|
vol.Mode = "rw"
|
||||||
|
case 2:
|
||||||
|
vol.SrcPath = arr[0]
|
||||||
|
vol.DstPath = arr[1]
|
||||||
|
vol.Mode = "rw"
|
||||||
|
case 3:
|
||||||
|
vol.SrcPath = arr[0]
|
||||||
|
vol.DstPath = arr[1]
|
||||||
|
vol.Mode = arr[2]
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("Invalid volume specification: %s", spec)
|
||||||
|
}
|
||||||
|
return vol, err
|
||||||
|
}
|
||||||
|
|
||||||
func getBindMap(container *Container) (map[string]BindMap, error) {
|
func getBindMap(container *Container) (map[string]BindMap, error) {
|
||||||
var (
|
var (
|
||||||
// Create the requested bind mounts
|
// Create the requested bind mounts
|
||||||
|
@ -131,37 +156,18 @@ func getBindMap(container *Container) (map[string]BindMap, error) {
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, bind := range container.hostConfig.Binds {
|
for _, bind := range container.hostConfig.Binds {
|
||||||
// FIXME: factorize bind parsing in parseBind
|
vol, err := parseBindVolumeSpec(bind)
|
||||||
var (
|
if err != nil {
|
||||||
src, dst, mode string
|
return binds, err
|
||||||
arr = strings.Split(bind, ":")
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(arr) == 2 {
|
|
||||||
src = arr[0]
|
|
||||||
dst = arr[1]
|
|
||||||
mode = "rw"
|
|
||||||
} else if len(arr) == 3 {
|
|
||||||
src = arr[0]
|
|
||||||
dst = arr[1]
|
|
||||||
mode = arr[2]
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("Invalid bind specification: %s", bind)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bail if trying to mount to an illegal destination
|
// Bail if trying to mount to an illegal destination
|
||||||
for _, illegal := range illegalDsts {
|
for _, illegal := range illegalDsts {
|
||||||
if dst == illegal {
|
if vol.DstPath == illegal {
|
||||||
return nil, fmt.Errorf("Illegal bind destination: %s", dst)
|
return nil, fmt.Errorf("Illegal bind destination: %s", vol.DstPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindMap := BindMap{
|
binds[filepath.Clean(vol.DstPath)] = vol
|
||||||
SrcPath: src,
|
|
||||||
DstPath: dst,
|
|
||||||
Mode: mode,
|
|
||||||
}
|
|
||||||
binds[filepath.Clean(dst)] = bindMap
|
|
||||||
}
|
}
|
||||||
return binds, nil
|
return binds, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue