mirror of https://github.com/docker/cli.git
feat: relative parent paths on bind mount src
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
parent
b39bbb4e3b
commit
3342b070b4
|
@ -382,7 +382,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
||||||
|
|
||||||
if parsed.Type == string(mounttypes.TypeBind) {
|
if parsed.Type == string(mounttypes.TypeBind) {
|
||||||
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
|
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
|
||||||
if strings.HasPrefix(hostPart, "."+string(filepath.Separator)) || hostPart == "." {
|
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
|
||||||
if absHostPart, err := filepath.Abs(hostPart); err == nil {
|
if absHostPart, err := filepath.Abs(hostPart); err == nil {
|
||||||
hostPart = absHostPart
|
hostPart = absHostPart
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ func (m *MountOpt) Set(value string) error {
|
||||||
mount.Type = mounttypes.Type(strings.ToLower(val))
|
mount.Type = mounttypes.Type(strings.ToLower(val))
|
||||||
case "source", "src":
|
case "source", "src":
|
||||||
mount.Source = val
|
mount.Source = val
|
||||||
if strings.HasPrefix(val, "."+string(filepath.Separator)) || val == "." {
|
if !filepath.IsAbs(val) && strings.HasPrefix(val, ".") {
|
||||||
if abs, err := filepath.Abs(val); err == nil {
|
if abs, err := filepath.Abs(val); err == nil {
|
||||||
mount.Source = abs
|
mount.Source = abs
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,22 @@ func TestMountRelative(t *testing.T) {
|
||||||
name: "Current path",
|
name: "Current path",
|
||||||
path: ".",
|
path: ".",
|
||||||
bind: "type=bind,source=.,target=/target",
|
bind: "type=bind,source=.,target=/target",
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: "Current path with slash",
|
name: "Current path with slash",
|
||||||
path: "./",
|
path: "./",
|
||||||
bind: "type=bind,source=./,target=/target",
|
bind: "type=bind,source=./,target=/target",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Parent path with slash",
|
||||||
|
path: "../",
|
||||||
|
bind: "type=bind,source=../,target=/target",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Parent path",
|
||||||
|
path: "..",
|
||||||
|
bind: "type=bind,source=..,target=/target",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
|
|
Loading…
Reference in New Issue