Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: relative parent paths on bind mount src #4966

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/container/opts.go
Expand Up @@ -382,7 +382,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con

if parsed.Type == string(mounttypes.TypeBind) {
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 {
hostPart = absHostPart
}
Expand Down
2 changes: 1 addition & 1 deletion opts/mount.go
Expand Up @@ -93,7 +93,7 @@ func (m *MountOpt) Set(value string) error {
mount.Type = mounttypes.Type(strings.ToLower(val))
case "source", "src":
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 {
mount.Source = abs
}
Expand Down
13 changes: 12 additions & 1 deletion opts/mount_test.go
Expand Up @@ -39,11 +39,22 @@ func TestMountRelative(t *testing.T) {
name: "Current path",
path: ".",
bind: "type=bind,source=.,target=/target",
}, {
},
{
name: "Current path with slash",
path: "./",
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) {
var mount MountOpt
Expand Down