mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
Merge pull request #7257 from bbckr/avoid-resolving-dot-in-named-pipe
Avoid resolving dotted segments when host path for volume is named pipe
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/cli/cli/config/configfile"
|
||||
@@ -206,6 +208,16 @@ func validateCgroupPermission(s string) bool {
|
||||
// expandPath returns the absolute path of dir, relative to base if dir is relative path.
|
||||
// base is expected to be an absolute path
|
||||
func expandPath(base, dir string) string {
|
||||
if runtime.GOOS == "windows" {
|
||||
pipeExp := regexp.MustCompile(`^` + rxPipe + `$`)
|
||||
match := pipeExp.FindStringSubmatch(strings.ToLower(dir))
|
||||
|
||||
if len(match) == 1 {
|
||||
// avoid resolving dot-segment in named pipe
|
||||
return dir
|
||||
}
|
||||
}
|
||||
|
||||
if filepath.IsAbs(dir) {
|
||||
return filepath.Clean(dir)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ func TestExpandPath(t *testing.T) {
|
||||
|
||||
{"/tmp/alloc/task", "c:/home/user", "c:/home/user"},
|
||||
{"/tmp/alloc/task", "c:/home/user/..", "c:/home"},
|
||||
|
||||
{"/tmp/alloc/task", `//./pipe/named_pipe`, `//./pipe/named_pipe`},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
@@ -55,6 +57,13 @@ func TestParseVolumeSpec_Windows(t *testing.T) {
|
||||
`e:\containerpath`,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"named pipe",
|
||||
`//./pipe/named_pipe://./pipe/named_pipe`,
|
||||
`\\.\pipe\named_pipe`,
|
||||
`//./pipe/named_pipe`,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range validCases {
|
||||
|
||||
Reference in New Issue
Block a user