aboutsummaryrefslogtreecommitdiff
path: root/volume
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2022-05-09 19:26:05 +0800
committerEng Zer Jun <engzerjun@gmail.com>2022-05-09 19:45:40 +0800
commit7873c27cfbd812dca60d90367d375bbae5a27014 (patch)
tree2f5d18783ac58536681d39b6e9baa0fd349cdba1 /volume
parentbb88ff4ab44c0e030bcd02ee364c66cdb5cef5a4 (diff)
all: replace strings.Replace with strings.ReplaceAll
strings.ReplaceAll(s, old, new) is a wrapper function for strings.Replace(s, old, new, -1). But strings.ReplaceAll is more readable and removes the hardcoded -1. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Diffstat (limited to 'volume')
-rw-r--r--volume/mounts/linux_parser.go4
-rw-r--r--volume/mounts/windows_parser.go14
-rw-r--r--volume/service/store_test.go2
3 files changed, 10 insertions, 10 deletions
diff --git a/volume/mounts/linux_parser.go b/volume/mounts/linux_parser.go
index e9d7a9c5de..bcabe45720 100644
--- a/volume/mounts/linux_parser.go
+++ b/volume/mounts/linux_parser.go
@@ -36,14 +36,14 @@ func linuxSplitRawSpec(raw string) ([]string, error) {
}
func linuxValidateNotRoot(p string) error {
- p = path.Clean(strings.Replace(p, `\`, `/`, -1))
+ p = path.Clean(strings.ReplaceAll(p, `\`, `/`))
if p == "/" {
return ErrVolumeTargetIsRoot
}
return nil
}
func linuxValidateAbsolute(p string) error {
- p = strings.Replace(p, `\`, `/`, -1)
+ p = strings.ReplaceAll(p, `\`, `/`)
if path.IsAbs(p) {
return nil
}
diff --git a/volume/mounts/windows_parser.go b/volume/mounts/windows_parser.go
index 99db17dc88..2e587bcc83 100644
--- a/volume/mounts/windows_parser.go
+++ b/volume/mounts/windows_parser.go
@@ -144,7 +144,7 @@ func windowsValidMountMode(mode string) bool {
}
func windowsValidateNotRoot(p string) error {
- p = strings.ToLower(strings.Replace(p, `/`, `\`, -1))
+ p = strings.ToLower(strings.ReplaceAll(p, `/`, `\`))
if p == "c:" || p == `c:\` {
return fmt.Errorf("destination path cannot be `c:` or `c:\\`: %v", p)
}
@@ -316,18 +316,18 @@ func (p *windowsParser) parseMount(arr []string, raw, volumeDriver string, conve
return nil, errInvalidSpec(raw)
}
// Host Source Path or Name + Destination
- spec.Source = strings.Replace(arr[0], `/`, `\`, -1)
+ spec.Source = strings.ReplaceAll(arr[0], `/`, `\`)
spec.Target = arr[1]
case 3:
// HostSourcePath+DestinationPath+Mode
- spec.Source = strings.Replace(arr[0], `/`, `\`, -1)
+ spec.Source = strings.ReplaceAll(arr[0], `/`, `\`)
spec.Target = arr[1]
mode = arr[2]
default:
return nil, errInvalidSpec(raw)
}
if convertTargetToBackslash {
- spec.Target = strings.Replace(spec.Target, `/`, `\`, -1)
+ spec.Target = strings.ReplaceAll(spec.Target, `/`, `\`)
}
if !windowsValidMountMode(mode) {
@@ -376,7 +376,7 @@ func (p *windowsParser) parseMountSpec(cfg mount.Mount, convertTargetToBackslash
Spec: cfg,
}
if convertTargetToBackslash {
- mp.Destination = strings.Replace(cfg.Target, `/`, `\`, -1)
+ mp.Destination = strings.ReplaceAll(cfg.Target, `/`, `\`)
}
switch cfg.Type {
@@ -397,9 +397,9 @@ func (p *windowsParser) parseMountSpec(cfg mount.Mount, convertTargetToBackslash
}
}
case mount.TypeBind:
- mp.Source = strings.Replace(cfg.Source, `/`, `\`, -1)
+ mp.Source = strings.ReplaceAll(cfg.Source, `/`, `\`)
case mount.TypeNamedPipe:
- mp.Source = strings.Replace(cfg.Source, `/`, `\`, -1)
+ mp.Source = strings.ReplaceAll(cfg.Source, `/`, `\`)
}
// cleanup trailing `\` except for paths like `c:\`
if len(mp.Source) > 3 && mp.Source[len(mp.Source)-1] == '\\' {
diff --git a/volume/service/store_test.go b/volume/service/store_test.go
index 97c521717d..0266bb0945 100644
--- a/volume/service/store_test.go
+++ b/volume/service/store_test.go
@@ -367,7 +367,7 @@ var cmpVolume = cmp.AllowUnexported(volumetestutils.FakeVolume{}, volumeWrapper{
func setupTest(t *testing.T) (*VolumeStore, func()) {
t.Helper()
- dirName := strings.Replace(t.Name(), string(os.PathSeparator), "_", -1)
+ dirName := strings.ReplaceAll(t.Name(), string(os.PathSeparator), "_")
dir, err := os.MkdirTemp("", dirName)
assert.NilError(t, err)