Cleanup: extract bindmount spec parsing
| ... | ... |
@@ -122,6 +122,31 @@ func applyVolumesFrom(container *Container) error {
|
| 122 | 122 |
return nil |
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 |
+func parseBindVolumeSpec(spec string) (BindMap, error) {
|
|
| 126 |
+ var ( |
|
| 127 |
+ arr = strings.Split(spec, ":") |
|
| 128 |
+ err error = nil |
|
| 129 |
+ vol BindMap |
|
| 130 |
+ ) |
|
| 131 |
+ |
|
| 132 |
+ switch len(arr) {
|
|
| 133 |
+ case 1: |
|
| 134 |
+ vol.DstPath = spec |
|
| 135 |
+ vol.Mode = "rw" |
|
| 136 |
+ case 2: |
|
| 137 |
+ vol.SrcPath = arr[0] |
|
| 138 |
+ vol.DstPath = arr[1] |
|
| 139 |
+ vol.Mode = "rw" |
|
| 140 |
+ case 3: |
|
| 141 |
+ vol.SrcPath = arr[0] |
|
| 142 |
+ vol.DstPath = arr[1] |
|
| 143 |
+ vol.Mode = arr[2] |
|
| 144 |
+ default: |
|
| 145 |
+ err = fmt.Errorf("Invalid volume specification: %s", spec)
|
|
| 146 |
+ } |
|
| 147 |
+ return vol, err |
|
| 148 |
+} |
|
| 149 |
+ |
|
| 125 | 150 |
func getBindMap(container *Container) (map[string]BindMap, error) {
|
| 126 | 151 |
var ( |
| 127 | 152 |
// Create the requested bind mounts |
| ... | ... |
@@ -131,37 +156,18 @@ func getBindMap(container *Container) (map[string]BindMap, error) {
|
| 131 | 131 |
) |
| 132 | 132 |
|
| 133 | 133 |
for _, bind := range container.hostConfig.Binds {
|
| 134 |
- // FIXME: factorize bind parsing in parseBind |
|
| 135 |
- var ( |
|
| 136 |
- src, dst, mode string |
|
| 137 |
- arr = strings.Split(bind, ":") |
|
| 138 |
- ) |
|
| 139 |
- |
|
| 140 |
- if len(arr) == 2 {
|
|
| 141 |
- src = arr[0] |
|
| 142 |
- dst = arr[1] |
|
| 143 |
- mode = "rw" |
|
| 144 |
- } else if len(arr) == 3 {
|
|
| 145 |
- src = arr[0] |
|
| 146 |
- dst = arr[1] |
|
| 147 |
- mode = arr[2] |
|
| 148 |
- } else {
|
|
| 149 |
- return nil, fmt.Errorf("Invalid bind specification: %s", bind)
|
|
| 134 |
+ vol, err := parseBindVolumeSpec(bind) |
|
| 135 |
+ if err != nil {
|
|
| 136 |
+ return binds, err |
|
| 150 | 137 |
} |
| 151 |
- |
|
| 152 | 138 |
// Bail if trying to mount to an illegal destination |
| 153 | 139 |
for _, illegal := range illegalDsts {
|
| 154 |
- if dst == illegal {
|
|
| 155 |
- return nil, fmt.Errorf("Illegal bind destination: %s", dst)
|
|
| 140 |
+ if vol.DstPath == illegal {
|
|
| 141 |
+ return nil, fmt.Errorf("Illegal bind destination: %s", vol.DstPath)
|
|
| 156 | 142 |
} |
| 157 | 143 |
} |
| 158 | 144 |
|
| 159 |
- bindMap := BindMap{
|
|
| 160 |
- SrcPath: src, |
|
| 161 |
- DstPath: dst, |
|
| 162 |
- Mode: mode, |
|
| 163 |
- } |
|
| 164 |
- binds[filepath.Clean(dst)] = bindMap |
|
| 145 |
+ binds[filepath.Clean(vol.DstPath)] = vol |
|
| 165 | 146 |
} |
| 166 | 147 |
return binds, nil |
| 167 | 148 |
} |