From caf9f4b80fde985ef1afccf259be85f0c6655e7e Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Wed, 1 Sep 2021 21:13:46 -0700 Subject: [PATCH 1/4] Have more intelligence on splitting bind paths --- .../app/wwctl/container/exec/child/main.go | 6 ++- internal/pkg/util/util.go | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 1e464fbd..8d797eef 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -7,10 +7,10 @@ import ( "fmt" "os" "path" - "strings" "syscall" "github.com/hpcng/warewulf/internal/pkg/container" + "github.com/hpcng/warewulf/internal/pkg/util" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" ) @@ -38,9 +38,11 @@ func CobraRunE(cmd *cobra.Command, args []string) error { var source string var dest string - bind := strings.Split(b, ":") + bind := util.SplitPaths(b, ":") source = bind[0] + fmt.Println(bind) + if len(bind) == 1 { dest = source } else { diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index c2698ce4..146b86e2 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -315,3 +315,43 @@ func CopyUIDGID(source string, dest string) error { err = os.Chown(dest, UID, GID) return err } + +func SplitEscaped(input, delim, escape string) []string { + var ret []string + str := "" + for i := 1; i < len(input); i++ { + str += string(input[i-1]) + if string(input[i]) == delim && string(input[i-1]) != escape { + i++ + ret = append(ret, str) + str = "" + } + if string(input[i]) == escape { + i++ + } + + } + str += string(input[len(input)-1]) + ret = append(ret, str) + + return (ret) +} + +func SplitPaths(input, delim string) []string { + var ret []string + str := "" + for i := 1; i < len(input); i++ { + str += string(input[i-1]) + //if (string(input[i]) == delim && string(input[i-1]) != "/") && (IsDir(str) || IsFile(str)) { + if string(input[i]) == delim && (IsDir(str) || IsFile(str)) { + i++ + ret = append(ret, str) + str = "" + } + + } + str += string(input[len(input)-1]) + ret = append(ret, str) + + return (ret) +} From 3665e06cb1e011cb8222ec0500861652a3a25091 Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Wed, 1 Sep 2021 21:20:36 -0700 Subject: [PATCH 2/4] Add ability to escape a split path as well --- internal/pkg/util/util.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 146b86e2..8ac6b2c7 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -342,12 +342,14 @@ func SplitPaths(input, delim string) []string { str := "" for i := 1; i < len(input); i++ { str += string(input[i-1]) - //if (string(input[i]) == delim && string(input[i-1]) != "/") && (IsDir(str) || IsFile(str)) { - if string(input[i]) == delim && (IsDir(str) || IsFile(str)) { + if (string(input[i]) == delim && string(input[i-1]) != "\\") && (IsDir(str) || IsFile(str)) { i++ ret = append(ret, str) str = "" } + if string(input[i]) == "\\" { + i++ + } } str += string(input[len(input)-1]) From ed64386b8b108501a33832d3aedc3a62f6bdfeee Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Wed, 1 Sep 2021 21:20:50 -0700 Subject: [PATCH 3/4] remove debug print --- internal/app/wwctl/container/exec/child/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 8d797eef..194e7635 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -41,8 +41,6 @@ func CobraRunE(cmd *cobra.Command, args []string) error { bind := util.SplitPaths(b, ":") source = bind[0] - fmt.Println(bind) - if len(bind) == 1 { dest = source } else { From 4c8edc16fee6d3562546d058f3ec0ceff63d1f7a Mon Sep 17 00:00:00 2001 From: Gregory Kurtzer Date: Thu, 2 Sep 2021 15:34:19 -0700 Subject: [PATCH 4/4] Changed API name to valid path --- internal/app/wwctl/container/exec/child/main.go | 2 +- internal/pkg/util/util.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/app/wwctl/container/exec/child/main.go b/internal/app/wwctl/container/exec/child/main.go index 194e7635..3a418ec1 100644 --- a/internal/app/wwctl/container/exec/child/main.go +++ b/internal/app/wwctl/container/exec/child/main.go @@ -38,7 +38,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error { var source string var dest string - bind := util.SplitPaths(b, ":") + bind := util.SplitValidPaths(b, ":") source = bind[0] if len(bind) == 1 { diff --git a/internal/pkg/util/util.go b/internal/pkg/util/util.go index 8ac6b2c7..73c7b74c 100644 --- a/internal/pkg/util/util.go +++ b/internal/pkg/util/util.go @@ -337,7 +337,7 @@ func SplitEscaped(input, delim, escape string) []string { return (ret) } -func SplitPaths(input, delim string) []string { +func SplitValidPaths(input, delim string) []string { var ret []string str := "" for i := 1; i < len(input); i++ {