Both lcow_parser.go and linux_parser.go are duplicating the error:
"invalid specification: destination can't be '/'"
This commit creates a new error called "ErrVolumeTargetIsRoot"
that is used by both linux_parser and lcow_parser and remove
the duplication in the code.
Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
| ... | ... |
@@ -2,7 +2,6 @@ package volume |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"path" |
| 7 | 6 |
|
| 8 | 7 |
"github.com/docker/docker/api/types/mount" |
| ... | ... |
@@ -10,7 +9,7 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
var lcowSpecificValidators mountValidator = func(m *mount.Mount) error {
|
| 12 | 12 |
if path.Clean(m.Target) == "/" {
|
| 13 |
- return fmt.Errorf("invalid specification: destination can't be '/'")
|
|
| 13 |
+ return ErrVolumeTargetIsRoot |
|
| 14 | 14 |
} |
| 15 | 15 |
if m.Type == mount.TypeNamedPipe {
|
| 16 | 16 |
return errors.New("Linux containers on Windows do not support named pipe mounts")
|
| ... | ... |
@@ -29,7 +29,7 @@ func linuxSplitRawSpec(raw string) ([]string, error) {
|
| 29 | 29 |
func linuxValidateNotRoot(p string) error {
|
| 30 | 30 |
p = path.Clean(strings.Replace(p, `\`, `/`, -1)) |
| 31 | 31 |
if p == "/" {
|
| 32 |
- return fmt.Errorf("invalid specification: destination can't be '/'")
|
|
| 32 |
+ return ErrVolumeTargetIsRoot |
|
| 33 | 33 |
} |
| 34 | 34 |
return nil |
| 35 | 35 |
} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package volume |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"runtime" |
| 5 | 6 |
|
| 6 | 7 |
"github.com/docker/docker/api/types/mount" |
| ... | ... |
@@ -13,6 +14,10 @@ const ( |
| 13 | 13 |
OSWindows = "windows" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
+// ErrVolumeTargetIsRoot is returned when the target destination is root. |
|
| 17 |
+// It's used by both LCOW and Linux parsers. |
|
| 18 |
+var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'")
|
|
| 19 |
+ |
|
| 16 | 20 |
// Parser represents a platform specific parser for mount expressions |
| 17 | 21 |
type Parser interface {
|
| 18 | 22 |
ParseMountRaw(raw, volumeDriver string) (*MountPoint, error) |