volume/mounts: remove windowsValidateRegex() utility

This utility was just a shallow wrapper around executing the regular
expression, and in some cases, we didn't even use the error it returned,
so better to inline the code instead of abstracting it away.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2021-07-27 10:06:31 +02:00
parent 71b0e47bee
commit 384517218a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 9 additions and 10 deletions

View file

@ -2,8 +2,10 @@ package mounts // import "github.com/docker/docker/volume/mounts"
import (
"errors"
"fmt"
"path"
"regexp"
"strings"
"github.com/docker/docker/api/types/mount"
)
@ -37,8 +39,8 @@ var lcowValidators mountValidator = func(m *mount.Mount) error {
if m.Type == mount.TypeNamedPipe {
return errors.New("Linux containers on Windows do not support named pipe mounts")
}
if err := windowsValidateRegex(m.Target, lcowMountDestinationRegex); err != nil {
return err
if !lcowMountDestinationRegex.MatchString(strings.ToLower(m.Target)) {
return fmt.Errorf("invalid mount path: '%s'", m.Target)
}
return nil
}

View file

@ -155,17 +155,14 @@ var windowsValidators mountValidator = func(m *mount.Mount) error {
if err := windowsValidateNotRoot(m.Target); err != nil {
return err
}
return windowsValidateRegex(m.Target, mountDestinationRegexp)
if !mountDestinationRegexp.MatchString(strings.ToLower(m.Target)) {
return fmt.Errorf("invalid mount path: '%s'", m.Target)
}
return nil
}
func windowsValidateRegex(p string, r *regexp.Regexp) error {
if r.MatchString(strings.ToLower(p)) {
return nil
}
return fmt.Errorf("invalid mount path: '%s'", p)
}
func windowsValidateAbsolute(p string) error {
if err := windowsValidateRegex(p, mountDestinationRegexp); err != nil {
if !mountDestinationRegexp.MatchString(strings.ToLower(p)) {
return fmt.Errorf("invalid mount path: '%s' mount path must be absolute", p)
}
return nil