Skip to content

Commit 761285b

Browse files
committed
feat: relative parent paths on bind mount src
Signed-off-by: Alano Terblanche <[email protected]>
1 parent f23ec25 commit 761285b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

cli/command/container/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
375375

376376
if parsed.Type == string(mounttypes.TypeBind) {
377377
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
378-
if strings.HasPrefix(hostPart, "."+string(filepath.Separator)) || hostPart == "." {
378+
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
379379
if absHostPart, err := filepath.Abs(hostPart); err == nil {
380380
hostPart = absHostPart
381381
}

opts/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (m *MountOpt) Set(value string) error {
100100
mount.Type = mounttypes.Type(strings.ToLower(val))
101101
case "source", "src":
102102
mount.Source = val
103-
if strings.HasPrefix(val, "."+string(filepath.Separator)) || val == "." {
103+
if !filepath.IsAbs(val) && strings.HasPrefix(val, ".") {
104104
if abs, err := filepath.Abs(val); err == nil {
105105
mount.Source = abs
106106
}

opts/mount_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,22 @@ func TestMountRelative(t *testing.T) {
3939
name: "Current path",
4040
path: ".",
4141
bind: "type=bind,source=.,target=/target",
42-
}, {
42+
},
43+
{
4344
name: "Current path with slash",
4445
path: "./",
4546
bind: "type=bind,source=./,target=/target",
4647
},
48+
{
49+
name: "Parent path with slash",
50+
path: "../",
51+
bind: "type=bind,source=../,target=/target",
52+
},
53+
{
54+
name: "Parent path",
55+
path: "..",
56+
bind: "type=bind,source=..,target=/target",
57+
},
4758
} {
4859
t.Run(testcase.name, func(t *testing.T) {
4960
var mount MountOpt

0 commit comments

Comments
 (0)