Skip to content

Commit 3342b07

Browse files
committed
feat: relative parent paths on bind mount src
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent b39bbb4 commit 3342b07

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
@@ -382,7 +382,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
382382

383383
if parsed.Type == string(mounttypes.TypeBind) {
384384
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
385-
if strings.HasPrefix(hostPart, "."+string(filepath.Separator)) || hostPart == "." {
385+
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
386386
if absHostPart, err := filepath.Abs(hostPart); err == nil {
387387
hostPart = absHostPart
388388
}

opts/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (m *MountOpt) Set(value string) error {
9393
mount.Type = mounttypes.Type(strings.ToLower(val))
9494
case "source", "src":
9595
mount.Source = val
96-
if strings.HasPrefix(val, "."+string(filepath.Separator)) || val == "." {
96+
if !filepath.IsAbs(val) && strings.HasPrefix(val, ".") {
9797
if abs, err := filepath.Abs(val); err == nil {
9898
mount.Source = abs
9999
}

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)