diff --git a/volume/local/local.go b/volume/local/local.go index eb78814ab0..fc29794003 100644 --- a/volume/local/local.go +++ b/volume/local/local.go @@ -54,7 +54,6 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) { } r := &Root{ - scope: scope, path: rootDirectory, volumes: make(map[string]*localVolume), rootIdentity: rootIdentity, @@ -107,7 +106,6 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) { // commands to create/remove dirs within its provided scope. type Root struct { m sync.Mutex - scope string path string quotaCtl *quota.Control volumes map[string]*localVolume @@ -224,8 +222,8 @@ func (r *Root) Remove(v volume.Volume) error { realPath = filepath.Dir(lv.path) } - if !r.scopedPath(realPath) { - return errdefs.System(errors.Errorf("Unable to remove a directory outside of the local volume root %s: %s", r.scope, realPath)) + if realPath == r.path || !strings.HasPrefix(realPath, r.path) { + return errdefs.System(errors.Errorf("unable to remove a directory outside of the local volume root %s: %s", r.path, realPath)) } if err := removePath(realPath); err != nil { diff --git a/volume/local/local_unix.go b/volume/local/local_unix.go index 3ef2db40c3..2b5863cb74 100644 --- a/volume/local/local_unix.go +++ b/volume/local/local_unix.go @@ -10,7 +10,6 @@ import ( "fmt" "net" "os" - "path/filepath" "strings" "syscall" "time" @@ -48,15 +47,6 @@ func (o *optsConfig) String() string { return fmt.Sprintf("type='%s' device='%s' o='%s' size='%d'", o.MountType, o.MountDevice, o.MountOpts, o.Quota.Size) } -// scopedPath verifies that the path where the volume is located -// is under Docker's root and the valid local paths. -func (r *Root) scopedPath(realPath string) bool { - if strings.HasPrefix(realPath, filepath.Join(r.scope, volumesPathName)) && realPath != filepath.Join(r.scope, volumesPathName) { - return true - } - return false -} - func setOpts(v *localVolume, opts map[string]string) error { if len(opts) == 0 { return nil diff --git a/volume/local/local_windows.go b/volume/local/local_windows.go index 9fc2092720..13847228a5 100644 --- a/volume/local/local_windows.go +++ b/volume/local/local_windows.go @@ -5,8 +5,6 @@ package local // import "github.com/docker/docker/volume/local" import ( "os" - "path/filepath" - "strings" "syscall" "time" @@ -16,15 +14,6 @@ import ( type optsConfig struct{} -// scopedPath verifies that the path where the volume is located -// is under Docker's root and the valid local paths. -func (r *Root) scopedPath(realPath string) bool { - if strings.HasPrefix(realPath, filepath.Join(r.scope, volumesPathName)) && realPath != filepath.Join(r.scope, volumesPathName) { - return true - } - return false -} - func setOpts(v *localVolume, opts map[string]string) error { if len(opts) > 0 { return errdefs.InvalidParameter(errors.New("options are not supported on this platform"))