mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
volume/local: remove redundant Root.scopedPath(), Root.scope
Now that there's no differentiation between Linux and Windows for this check, we can remove the two implementations and move the code inline as it's only used in a single location and moving it inline makes it more transparent on what's being checked. As part of this change, the now unused "scope" field is also removed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0abd7ba229
commit
74be0fed6f
3 changed files with 2 additions and 25 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
|
|
Loading…
Reference in a new issue