Bläddra i källkod

Merge pull request #36009 from ripcurld0/small_nitpick

Small nitpick: create ErrVolumeTargetIsRoot in the volume package
Sebastiaan van Stijn 7 år sedan
förälder
incheckning
fb13aeef0f
3 ändrade filer med 7 tillägg och 3 borttagningar
  1. 1 2
      volume/lcow_parser.go
  2. 1 1
      volume/linux_parser.go
  3. 5 0
      volume/parser.go

+ 1 - 2
volume/lcow_parser.go

@@ -2,7 +2,6 @@ package volume
 
 
 import (
 import (
 	"errors"
 	"errors"
-	"fmt"
 	"path"
 	"path"
 
 
 	"github.com/docker/docker/api/types/mount"
 	"github.com/docker/docker/api/types/mount"
@@ -10,7 +9,7 @@ import (
 
 
 var lcowSpecificValidators mountValidator = func(m *mount.Mount) error {
 var lcowSpecificValidators mountValidator = func(m *mount.Mount) error {
 	if path.Clean(m.Target) == "/" {
 	if path.Clean(m.Target) == "/" {
-		return fmt.Errorf("invalid specification: destination can't be '/'")
+		return ErrVolumeTargetIsRoot
 	}
 	}
 	if m.Type == mount.TypeNamedPipe {
 	if m.Type == mount.TypeNamedPipe {
 		return errors.New("Linux containers on Windows do not support named pipe mounts")
 		return errors.New("Linux containers on Windows do not support named pipe mounts")

+ 1 - 1
volume/linux_parser.go

@@ -29,7 +29,7 @@ func linuxSplitRawSpec(raw string) ([]string, error) {
 func linuxValidateNotRoot(p string) error {
 func linuxValidateNotRoot(p string) error {
 	p = path.Clean(strings.Replace(p, `\`, `/`, -1))
 	p = path.Clean(strings.Replace(p, `\`, `/`, -1))
 	if p == "/" {
 	if p == "/" {
-		return fmt.Errorf("invalid specification: destination can't be '/'")
+		return ErrVolumeTargetIsRoot
 	}
 	}
 	return nil
 	return nil
 }
 }

+ 5 - 0
volume/parser.go

@@ -1,6 +1,7 @@
 package volume
 package volume
 
 
 import (
 import (
+	"errors"
 	"runtime"
 	"runtime"
 
 
 	"github.com/docker/docker/api/types/mount"
 	"github.com/docker/docker/api/types/mount"
@@ -13,6 +14,10 @@ const (
 	OSWindows = "windows"
 	OSWindows = "windows"
 )
 )
 
 
+// ErrVolumeTargetIsRoot is returned when the target destination is root.
+// It's used by both LCOW and Linux parsers.
+var ErrVolumeTargetIsRoot = errors.New("invalid specification: destination can't be '/'")
+
 // Parser represents a platform specific parser for mount expressions
 // Parser represents a platform specific parser for mount expressions
 type Parser interface {
 type Parser interface {
 	ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)
 	ParseMountRaw(raw, volumeDriver string) (*MountPoint, error)