Skip to content

Commit 5016a22

Browse files
authored
Merge pull request #206 from mat007/fix-volume-trailing-slash
2 parents 83c54ca + 77073f1 commit 5016a22

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

loader/full-example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ services:
268268
- .:/code
269269
- ./static:/var/www/html
270270
# User-relative path
271-
- ~/configs:/etc/configs/:ro
271+
- ~/configs:/etc/configs:ro
272272
# Named volume
273273
- datavolume:/var/lib/mysql
274274
- type: bind

loader/full-struct_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
399399
{Source: "/opt/data", Target: "/var/lib/mysql", Type: "bind", Bind: &types.ServiceVolumeBind{CreateHostPath: true}},
400400
{Source: workingDir, Target: "/code", Type: "bind", Bind: &types.ServiceVolumeBind{CreateHostPath: true}},
401401
{Source: filepath.Join(workingDir, "static"), Target: "/var/www/html", Type: "bind", Bind: &types.ServiceVolumeBind{CreateHostPath: true}},
402-
{Source: filepath.Join(homeDir, "/configs"), Target: "/etc/configs/", Type: "bind", ReadOnly: true, Bind: &types.ServiceVolumeBind{CreateHostPath: true}},
402+
{Source: filepath.Join(homeDir, "/configs"), Target: "/etc/configs", Type: "bind", ReadOnly: true, Bind: &types.ServiceVolumeBind{CreateHostPath: true}},
403403
{Source: "datavolume", Target: "/var/lib/mysql", Type: "volume", Volume: &types.ServiceVolumeVolume{}},
404404
{Source: filepath.Join(workingDir, "opt"), Target: "/opt", Consistency: "cached", Type: "bind"},
405405
{Target: "/opt", Type: "tmpfs", Tmpfs: &types.ServiceVolumeTmpfs{
@@ -851,7 +851,7 @@ func fullExampleYAML(workingDir, homeDir string) string {
851851
create_host_path: true
852852
- type: bind
853853
source: %s
854-
target: /etc/configs/
854+
target: /etc/configs
855855
read_only: true
856856
bind:
857857
create_host_path: true
@@ -1481,7 +1481,7 @@ func fullExampleJSON(workingDir, homeDir string) string {
14811481
{
14821482
"type": "bind",
14831483
"source": "%s",
1484-
"target": "/etc/configs/",
1484+
"target": "/etc/configs",
14851485
"read_only": true,
14861486
"bind": {
14871487
"create_host_path": true

loader/volume.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package loader
1818

1919
import (
20+
"path"
2021
"strings"
2122
"unicode"
2223
"unicode/utf8"
@@ -36,11 +37,11 @@ func ParseVolume(spec string) (types.ServiceVolumeConfig, error) {
3637
return volume, errors.New("invalid empty volume spec")
3738
case 1, 2:
3839
volume.Target = spec
39-
volume.Type = string(types.VolumeTypeVolume)
40+
volume.Type = types.VolumeTypeVolume
4041
return volume, nil
4142
}
4243

43-
buffer := []rune{}
44+
var buffer []rune
4445
for _, char := range spec + string(endOfSpec) {
4546
switch {
4647
case isWindowsDrive(buffer, char):
@@ -50,12 +51,13 @@ func ParseVolume(spec string) (types.ServiceVolumeConfig, error) {
5051
populateType(&volume)
5152
return volume, errors.Wrapf(err, "invalid spec: %s", spec)
5253
}
53-
buffer = []rune{}
54+
buffer = nil
5455
default:
5556
buffer = append(buffer, char)
5657
}
5758
}
5859

60+
volume.Target = path.Clean(volume.Target)
5961
populateType(&volume)
6062
return volume, nil
6163
}

loader/volume_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ func TestParseVolumeAnonymousVolume(t *testing.T) {
3434
}
3535
}
3636

37+
func TestParseVolumeCleanTarget(t *testing.T) {
38+
volume, err := ParseVolume("/path/")
39+
expected := types.ServiceVolumeConfig{Type: "volume", Target: "/path", Volume: &types.ServiceVolumeVolume{}}
40+
assert.NilError(t, err)
41+
assert.Check(t, is.DeepEqual(expected, volume))
42+
}
43+
3744
func TestParseVolumeAnonymousVolumeWindows(t *testing.T) {
3845
for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
3946
volume, err := ParseVolume(path)

0 commit comments

Comments
 (0)